Commit 7593fb42 authored by Dominique Piche's avatar Dominique Piche

change tool design + better demo

parent 0466b6ba
......@@ -3,4 +3,5 @@ __pycache__/
tracking_data.txt
log.txt
trajectory_graph.py
Data/
\ No newline at end of file
Data/
example.py
\ No newline at end of file
......@@ -10,8 +10,8 @@ class MecaRobot:
"""Robot class for programming Meca500 robots"""
def __init__(self,
ip: str,
port: int,
ip: str = "192.168.0.100",
port: int = 10000,
simulation_mode: bool = False,
enable_log: bool = False):
"""
......@@ -20,9 +20,6 @@ class MecaRobot:
:param simulation_mode: enables simulation mode, in which the robot does not move but we
can monitor it on the web interace.
:param enable_log : writes in the log.txt file every communication with the robot.
See https://mecademic.com/Documentation/Meca500-R3-Programming-Manual.pdf for more details
about the reference frames definition.
"""
self.simulation_mode = simulation_mode
......@@ -59,8 +56,8 @@ class MecaRobot:
self.wait_for("2000", "Failed to activate the robot")
self.run('Home')
self.wait_for("2002", "Failed to home the robot")
self.run('SetEOB', 0)
self.wait_for("2055", "Failed to disable EOB")
self.run('SetEOB', 1)
self.wait_for("2054", "Failed to enable EOB")
self.run('SetEOM', 1)
self.wait_for("2052", "Failed to enable EOM")
......@@ -71,7 +68,7 @@ class MecaRobot:
self.zero_joints()
self.clear_buffer()
def send_str(self, msg: str):
def _send_str(self, msg: str):
# Sendind string to the robot over TCP/IP
self.sock.send(bytes(msg + '\0', 'ascii'))
......@@ -79,7 +76,7 @@ class MecaRobot:
with open('log.txt', 'a+') as log:
log.write('Sent: ' + msg + '\n')
def receive_str(self) -> str:
def _receive_str(self) -> str:
# Receiving string from the robot
byte_data = b''
try:
......@@ -107,7 +104,7 @@ class MecaRobot:
str_send = cmd + '(' + str(values) + ')'
# Send command to robot
self.send_str(str_send)
self._send_str(str_send)
print('Running: ' + str_send)
sys.stdout.flush()
......@@ -116,7 +113,7 @@ class MecaRobot:
# Get the robot response.
robot_answer = ""
while robot_answer == "":
robot_answer = self.receive_str()
robot_answer = self._receive_str()
print('Received: %s' % robot_answer)
sys.stdout.flush()
......@@ -127,9 +124,9 @@ class MecaRobot:
with open('log.txt', 'a+') as log:
log.write('Clearing buffer\n')
string_received = self.receive_str()
string_received = self._receive_str()
while string_received != '':
string_received = self.receive_str()
string_received = self._receive_str()
def wait_for(self, answer: str, error_message: str, timeout: float=10) -> str:
# Waits for a specific answer from the robot before continuing the program. Returns the command.
......@@ -145,7 +142,7 @@ class MecaRobot:
robot_output = ''
answer_timer.start()
while answer_not_found and answer_timer.is_alive():
robot_output = self.receive_str()
robot_output = self._receive_str()
if robot_output.find(answer) != -1:
answer_not_found = False
......@@ -214,10 +211,10 @@ class MecaRobot:
The program waits for an end of movement response from the robot before tracking the data.
The buffer is cleared to ensure the EOM responses are not from earlier movements. This step
can be skiped to save 2 seconds by setting do_clear_buffer to False.
can be skipped to save 2 seconds by setting do_clear_buffer to False.
"""
if do_clear_buffer:
if do_clear_buffer and self.is_tracking:
self.clear_buffer()
if axis not in ['x', 'y', 'z']:
......
......@@ -13,7 +13,7 @@ class MecaRobotForDosimetry(MecaRobot):
simulation_mode: bool = False,
enable_log: bool = False,
scintillators_positions: np.ndarray = np.array([0]),
source_position: np.ndarray = np.array([0, 0, 0]),
source_position: np.ndarray = np.array([0,0,0]),
measure_with_nidaq: bool = False,
daq_path_number: int = None,
analog_input_channels: tuple = None,
......@@ -69,25 +69,25 @@ class MecaRobotForDosimetry(MecaRobot):
current_path = os.getcwd()
# Creating time file
self.time_file = open(os.path.join(current_path, 'Data/Time.txt'), 'w+')
self.time_file = open(os.path.join(current_path, 'Data/time.txt'), 'w+')
# Creating scintillators' position files
self.scintillators_positions_files = []
for i in range(self.number_of_scintillators):
file_name = 'Data/Scintillator {} position relative to source.txt'.format(i+1)
file_name = 'Data/scintillator_{}_position_relative_to_source.txt'.format(i+1)
file_path = os.path.join(current_path, file_name)
self.scintillators_positions_files.append(open(file_path, 'w+'))
# Creating scintillators' distance to source files
self.scintillators_distance_to_source_files = []
for i in range(self.number_of_scintillators):
file_name = 'Data/Scintillator {} distance to source.txt'.format(i+1)
file_name = 'Data/scintillator_{}_distance_to_source.txt'.format(i+1)
file_path = os.path.join(current_path, file_name)
self.scintillators_distance_to_source_files.append(open(file_path, 'w+'))
# Creating scintillators' signal file
if self.measure_with_nidaq:
self.scintillators_signal_file = open(os.path.join(current_path, 'Data/Scintillators signal.txt'), 'w+')
self.scintillators_signal_file = open(os.path.join(current_path, 'Data/scintillators_signal.txt'), 'w+')
self.start_time = time.time()
......@@ -197,14 +197,14 @@ class MecaRobotForDosimetry(MecaRobot):
pose = list(abs_position)+[0,0,0]
self.run('MovePose', pose)
def turn_around_source(self, angle_to_cover: float, angular_step: float, delay: float=0, do_clear_buffer = False):
def turn_around_source(self, angle_to_cover: float, angular_step: float, delay: float = 0, do_clear_buffer = True):
"""
Turns the scintillators around the source in the x-y plane. A positive angular_step correspond to a
counter-clockwise rotation. The code waits for the robot to send an end of movement response (EOM)
before tracking the data. The buffer is cleared to ensure the EOM responses are not from earlier
commands. This step can be skipped by setting do_clear_buffer to false to save about 2 seconds.
"""
if do_clear_buffer:
if do_clear_buffer and self.is_tracking:
self.clear_buffer()
robot_pose = self.get_TRF_pose()
......
No preview for this file type
......@@ -4,9 +4,6 @@ import time
from MecaRobot.meca_robot_for_dosimetry import MecaRobotForDosimetry
# Moves the robot in straight lines of 150 mm towards the source in a water tank.
robot_ip = "192.168.0.100"
robot_port = 10000
simulation_mode = False
......@@ -15,7 +12,7 @@ scintillators_positions = np.array([224, 241, 250]) #In mm, relative to robot en
# When the robot is manually jogged to the position depicted in Tools/calibration_setup.stl, the
# source is positionned at (10.00,0.02,-347.00) mm relative to the end of the robot.
source_position = np.array([212.943,108.693,136.658])+np.array([10,0.02,-347])
source_position = np.array([201.700,110.595,139.742])+np.array([10,0.02,-347])
robot = MecaRobotForDosimetry(ip = robot_ip,
......@@ -66,8 +63,8 @@ robot.move_position_relative_to_source(np.array([0,-40,30]))
robot.wait_for('3004', 'Did not receive EOM.')
robot.turn_around_source(90,-5)
robot.turn_around_source(180,5)
robot.turn_around_source(90,-5)
robot.turn_around_source(180,5, do_clear_buffer=False)
robot.turn_around_source(90,-5, do_clear_buffer=False)
# Approaching the source with an angle about x-axis
robot.move_position_relative_to_source(np.array([0,-185,0]))
......
......@@ -8,13 +8,13 @@ from MecaRobot.meca_robot_for_dosimetry import MecaRobotForDosimetry
robot_ip = "192.168.0.100"
robot_port = 10000
simulation_mode = False
simulation_mode = True
enable_log = True
scintillators_positions = np.array([224, 241, 250]) #In mm, relative to robot end (FRF)
# When the robot is manually jogged to the position depicted in Tools/calibration_setup.stl, the
# source is positionned at (10.00,0.02,-347.00) mm relative to the end of the robot.
source_position = np.array([212.769,168.578,136.620])+np.array([10,0.02,-347])
source_position = np.array([211.388,94.964,139.858])+np.array([10,0.02,-347])
measure_with_nidaq = True #Enable tracking with NI daqmx board
daq_path_number = 2 #Path of the NI daqmx device, i.e. Dev1
analog_input_channels = (8, 9, 10, 11)
......@@ -33,19 +33,18 @@ robot = MecaRobotForDosimetry(ip = robot_ip,
analog_output_channels = analog_output_channels)
# Movements
number_of_straight_lines = 2
number_of_straight_lines = 1
robot.start_tracking()
for i in range(number_of_straight_lines):
robot.move_position_relative_to_source(np.array([0,-185,0+i]))
robot.move_position_relative_to_source(np.array([0,-160,0+i]))
robot.linear_sequence('y', 50, 5)
robot.linear_sequence('y', 50, 2, do_clear_buffer=False)
robot.linear_sequence('y', 25, 1, do_clear_buffer=False)
robot.linear_sequence('y', 15, 0.5, do_clear_buffer=False)
robot.linear_sequence('y', 10, 0.1, do_clear_buffer=False)
robot.stop_tracking()
robot.run('Delay', 1)
robot.run('MoveLinRelTRF', [0,-75,0,0,0,0])
......
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