Commit 427e5585 authored by Daniella Tola's avatar Daniella Tola
Browse files

added assertions to load_program to ensure it loads the correct program

parent 13754e72
from urinterface.robot_connection import RobotConnection
import numpy as np
from pathlib import Path
import time
q0 = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) # configuration no. 1
q1 = np.array([1.3, 0.0, 0.0, 0.0, 0.0, 0.0]) # configuration no. 2
v0 = 2.0
a0 = 8.0
vm_ip = "192.168.80.128"
vm_ip = "192.168.142.128"
ur5e = RobotConnection(vm_ip) # Establish dashboard connection (port 29999) and controller connection (port 30002)
# Now, move to joint angular position q = q0 with joint angular velocity v = v0 and joint angular acceleration a = a0
ur5e.movej(q=q0, v=v0, a=a0)
# Create filename
f_name = "test_motion1.csv"
filename = Path("robot_sim_tests") / Path("test_results") / Path(f_name)
filename = Path("setup_with_ursim") / Path("test_results") / Path(f_name)
# Specify config file path
config_file = Path("robot_sim_tests") / Path("resources") / Path("record_configuration.xml")
config_file = Path("setup_with_ursim") / Path("resources") / Path("record_configuration.xml")
ur5e.start_recording(filename=filename, overwrite=True, config_file=config_file) # start recording and place the recorded data in test_motion.csv
ur5e.movej(q=q1, v=v0, a=a0) # move to joint angular position q = q1
resp = ur5e.load_program("movement1.urp")
ur5e.play_program()
time.sleep(5)
ur5e.stop_program()
# ur5e.movej(q=q1, v=v0, a=a0) # move to joint angular position q = q1
ur5e.stop_recording()
\ No newline at end of file
......@@ -102,6 +102,7 @@ class RobotConnection:
program = "movel("+q_string+opts_string+")\n"
self._send_ctrl_cmd(program)
def movep(self, p=np.zeros(6),v=None, a=None, r=None):
q_string, opts_string = self._move(q=p,v=v,a=a,r=r)
program = "movep("+q_string+opts_string+")\n"
......@@ -135,7 +136,18 @@ class RobotConnection:
def load_program(self, program_name):
self._send_ascii_bytes(f"load {program_name}\n", self.dashboard_socket)
return self.dashboard_socket.recv(1024).decode().startswith("Loading program: ")
loaded_program_response = self.dashboard_socket.recv(1024).decode()
assert "File not found" not in loaded_program_response, f"The program file {program_name} was not found, received: {loaded_program_response}"
assert "Error loading program" not in loaded_program_response, f"An error occurred while attempting to load the program {program_name}, received: {loaded_program_response}"
loaded_program = self.get_loaded_program()
assert program_name in loaded_program, f"The loaded program is incorrect. Expected {program_name}, but got {loaded_program}"
return loaded_program_response.startswith("Loading program: ")
def get_loaded_program(self):
self._send_ascii_bytes(f"get loaded program\n", self.dashboard_socket)
loaded_program = self.dashboard_socket.recv(1024).decode()
return loaded_program
def play_program(self):
self._send_ascii_bytes("play\n", self.dashboard_socket)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment