Commit 88348f5a authored by Dominique Piche's avatar Dominique Piche

add sequence about arbitrary axis + doc update

parent 6099043a
......@@ -204,7 +204,7 @@ class MecaRobot:
pose = np.array(pose[beg:end].split(','), dtype=float)
return pose
def linear_sequence(self, axis: str, total_distance: float, step: float, delay: float=0, do_clear_buffer : bool=True):
def linear_sequence(self, direction_vector: np.ndarray, total_distance: float, step: float, delay: float=0, do_clear_buffer : bool=True):
"""
Moves the tool reference frame linearly along an axis by steps. In its default position,
the robot is in a singularity, which means it has to move elsewhere using the MovePose or
......@@ -218,50 +218,44 @@ class MecaRobot:
if do_clear_buffer and self.is_tracking:
self.clear_buffer()
if axis not in ['x', 'y', 'z']:
print("Unrecognized axis. Options are x, y or z.")
else:
for i in range(abs(int(total_distance/step))):
if axis == 'x':
self.run('MoveLinRelWRF', [step, 0, 0, 0, 0, 0])
elif axis == 'y':
self.run('MoveLinRelWRF', [0, step, 0, 0, 0, 0])
else:
self.run('MoveLinRelWRF', [0, 0, step, 0, 0, 0])
direction_vector = direction_vector / np.linalg.norm(direction_vector)
if delay != 0:
self.run('Delay', delay)
for i in range(abs(int(total_distance/step))):
# Writing the movement in the form [x, y, z, alpha, beta, gamma] used by the robot.
lin_pose = list(step * direction_vector) + [0, 0, 0]
if self.is_tracking:
self.wait_for('3004', 'Did not receive EOM')
self._track_data()
self.run('MoveLinRelWRF', lin_pose)
if delay != 0:
self.run('Delay', delay)
def square_sequence(self, axis_1: str, total_distance_along_axis_1: float, step_1: float,
axis_2: str, total_distance_along_axis_2: float, step_2: float,
if self.is_tracking:
self.wait_for('3004', 'Did not receive EOM')
self._track_data()
def square_sequence(self, direction_vec_1: np.ndarray, total_distance_along_direction_vec_1: float, step_1: float,
direction_vec_2: np.ndarray, total_distance_along_direction_vec_2: float, step_2: float,
delay: float=0, do_clear_buffer: bool=True):
"""
Moves the tool reference frame by steps to cover a square (multiple linear
sequences).
Moves the tool reference frame by steps to cover a square (multiple linear sequences). The two
axes must be orthogonal.
"""
if axis_1 not in ['x', 'y', 'z'] or axis_2 not in ['x', 'y', 'z']:
print('Unrecognized axis. Options are x, y or z.')
if np.dot(direction_vec_1, direction_vec_2) != 0:
print("The two direction vectors are not orthogonal, cannot form a square.")
else:
for i in range(abs(int(total_distance_along_axis_1/step_1))):
for i in range(abs(int(total_distance_along_direction_vec_1/step_1))):
if i == 0:
# Clearing the buffer on the first sequence
self.linear_sequence(axis_2, total_distance_along_axis_2, step_2, delay, do_clear_buffer)
self.linear_sequence(direction_vec_2, total_distance_along_direction_vec_2, step_2, delay, do_clear_buffer)
else:
self.linear_sequence(axis_2, total_distance_along_axis_2, step_2, delay, False)
self.linear_sequence(direction_vec_2, total_distance_along_direction_vec_2, step_2, delay, False)
step_2 = -step_2
if axis_1 == 'x':
self.run('MoveLinRelWRF', [step_1, 0, 0, 0, 0, 0])
elif axis_1 == 'y':
self.run('MoveLinRelWRF', [0, step_1, 0, 0, 0, 0])
else:
self.run('MoveLinRelWRF', [0, 0, step_1, 0, 0, 0])
lin_pose = list(step_1 * direction_vec_1) + [0, 0, 0]
self.run('MoveLinRelWRF', lin_pose)
if delay != 0:
self.run('Delay', delay)
......@@ -270,34 +264,41 @@ class MecaRobot:
self.wait_for('3004', 'Did not receive EOM')
self._track_data()
def cube_sequence(self, total_distance_x: float, step_x: float,
total_distance_y: float, step_y: float,
total_distance_z: float, step_z: float,
def cube_sequence(self, direction_vec_1: np.ndarray, total_distance_along_direction_vec_1: float, step_1: float,
direction_vec_2: np.ndarray, total_distance_along_direction_vec_2: float, step_2: float,
direction_vec_3: np.ndarray, total_distance_along_direction_vec_3: float, step_3: float,
delay: float=0, do_clear_buffer: bool=True):
"""
Moves the tool reference frame by steps to map 3D space by covering a cube (multiple square sequences).
"""
for i in range(abs(int(total_distance_z/step_z))):
if i == 0:
# Clearing the buffer on the first sequence
self.square_sequence('x', total_distance_x, step_x, 'y', total_distance_y, step_y, delay, do_clear_buffer)
else:
self.square_sequence('x', total_distance_x, step_x, 'y', total_distance_y, step_y, delay, False)
if np.dot(direction_vec_1, direction_vec_2) != 0 or np.dot(direction_vec_2, direction_vec_3) != 0 or np.dot(direction_vec_3, direction_vec_1) != 0:
print('The three direction vectors are not orthogonal, cannot form a cube.')
else:
for i in range(abs(int(total_distance_along_direction_vec_3/step_3))):
if i == 0:
# Clearing the buffer on the first sequence
self.square_sequence(direction_vec_1, total_distance_along_direction_vec_1, step_1,
direction_vec_2, total_distance_along_direction_vec_2, step_2, delay, do_clear_buffer)
else:
self.square_sequence(direction_vec_1, total_distance_along_direction_vec_1, step_1,
direction_vec_2, total_distance_along_direction_vec_2, step_2, delay, False)
step_x = -step_x
step_1 = -step_1
if total_distance_x/step_x % 2 != 0:
step_y = -step_y
self.run('MoveLinRelWRF', [0, 0, step_z, 0, 0, 0])
if total_distance_along_direction_vec_1/step_1 % 2 != 0:
step_2 = -step_2
if delay != 0:
self.run('Delay', delay)
lin_pose = list(step_3 * direction_vec_3) + [0, 0, 0]
if self.is_tracking:
self.wait_for('3004', 'Did not receive EOM')
self._track_data()
self.run('MoveLinRelWRF', lin_pose)
if delay != 0:
self.run('Delay', delay)
if self.is_tracking:
self.wait_for('3004', 'Did not receive EOM')
self._track_data()
@staticmethod
def answer_not_found(error_message):
......
......@@ -275,7 +275,6 @@ class MecaRobotForDosimetry(MecaRobot):
self.source_offset = np.array([x_max, y_max, z_max])
self.source_position = self.source_position + self.source_offset
def move_position_relative_to_source(self, position: np.ndarray):
"""
......
......@@ -91,17 +91,17 @@ Returns:
Numpy array of the robot pose, in the from [x,y,z,α,β,γ].
**MecaRobot.linear_sequence**(*axis, total_distance, step, delay=0, do_clear_buffer=True*)
**MecaRobot.linear_sequence**(*direction_vector, total_distance, step, delay=0, do_clear_buffer=True*)
Moves the tool reference frame linearly along an axis by steps. For instance, using linear_sequence('x', 50, 1) will move the robot along the x-axis for 50 mm with 1 mm steps. If the user is tracking, there will be 50 new entries in the *tracking_data.txt* file (after every step). In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
Moves the tool reference frame linearly along an axis by steps. For instance, using linear_sequence(np.array([1,0,0]), 50, 1) will move the robot along the x-axis for 50 mm with 1 mm steps. If the user is tracking, there will be 50 new entries in the *tracking_data.txt* file (after every step). In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
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 skipped to save about 2 seconds by setting do_clear_buffer to False if the user is certain the buffer is empty.
Parameters:
- **axis : *str***
- **direction_vector : *np.ndarray***
Movement direction. Can be x, y or z.
Movement direction in the form [x, y, z].
- **total_distance : *float***
Distance to cover in mm.
......@@ -115,30 +115,30 @@ Parameters:
Clears the socket buffer if the robot is in tracking mode and do_clear_buffer is True.
**MecaRobot.square_sequence**(*axis_1, total_distance_along_axis_1, step_1, axis_2, total_distance_along_axis_2, step_2, delay=0, do_clear_buffer=True*)
**MecaRobot.square_sequence**(*direction_vec_1, total_distance_along_direction_vec_1, step_1, direction_vec_2, total_distance_along_direction_vec_2, step_2, delay=0, do_clear_buffer=True*)
Moves the tool reference frame by steps to cover a square (multiple linear sequences). In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
Moves the tool reference frame by steps to cover a square (multiple linear sequences). Thus, the two direction vectors have to be orthogonal. In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
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 skipped to save 2 seconds by setting do_clear_buffer to False if the user is certain the buffer is empty.
Parameters:
- **axis_1 : *str***
- **direction_vec_1 : *np.ndarray***
First movement direction. Can be x, y or z.
- **total_distance_along_axis_1 : *float***
First movement direction in the form [x, y, z].
- **total_distance_along_direction_vec_1 : *float***
Distance to cover along axis_1 in mm.
- **step_1 : *str***
- **step_1 : *float***
Step size along axis_1 in mm.
- **axis_2 : *str***
- **direction_vec_2 : *np.ndarray***
Second movement direction. Can be x, y or z.
- **total_distance_along_axis_2 : *float***
Second movement direction in the form [x, y, z].
- **total_distance_along_direction_vec_2 : *float***
Distance to cover along axis_2 in mm.
- **step_2 : *str***
- **step_2 : *float***
Step size along axis_2 in mm.
- **delay : *float***
......@@ -148,35 +148,54 @@ Parameters:
Clears the socket buffer if the robot is in tracking mode and do_clear_buffer is True.
**MecaRobot.cube_sequence**(*total_distance_x, step_x, total_distance_y, step_y, total_distance_z, step_z, delay=0, do_clear_buffer=True*)
**MecaRobot.cube_sequence**(*direction_vec_1, total_distance_along_direction_vec_1, step_1, direction_vec_2, total_distance_along_direction_vec_2, step_2, direction_vec_3, total_distance_along_direction_vec_3, step_3, delay, do_clear_buffer*):
Moves the tool reference frame by steps to map 3D space by covering a cube (multiple square sequences). In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
Moves the tool reference frame by steps to map 3D space by covering a cube (multiple square sequences). The three directions vectors have to be orthogonal. In its default position, the robot is in a singularity, which means it has to move elsewhere using the MovePose or MoveJoints command prior to a linear sequence.
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 skipped to save 2 seconds by setting do_clear_buffer to False if the user is certain the buffer is empty.
Parameters:
- **total_distance_x: *float***
- **direction_vec_1 : *np.ndarray***
First movement direction in the form [x, y, z].
- **total_distance_along_direc_vec_1 : *float***
Distance to cover along the first axis in mm.
- **step_1 : *str***
Step size along the first axis.
- **direction_vec_2 : *np.ndarray***
Second movement direction in the form [x, y, z].
- **total_distance_along_direc_vec_2 : *float***
Distance to cover along x-axis in mm.
- **step_x : *str***
Distance to cover along the second axis in mm.
- **step_2 : *str***
Step size along x-axis.
- **total_distance_y: *float***
Step size along the second axis.
- **direction_vec_3 : *np.ndarray***
Distance to cover along y-axis in mm.
- **step_y : *str***
Third movement direction in the form [x, y, z].
Step size along y-axis.
- **total_distance_z: *float***
- **total_distance_along_direc_vec_3 : *float***
Distance to cover along z-axis in mm.
- **step_z : *str***
Distance to cover along third axis in mm.
- **step_3 : *str***
Step size along z-axis.
Step size along the third axis.
- **delay : *float***
If specified, the robot will wait this number of seconds after every step.
- **do_clear_buffer : *bool***
Clears the socket buffer if the robot is in tracking mode and do_clear_buffer is True.
......@@ -205,7 +224,7 @@ Parameters:
Array of each scintillator's z-position (in mm) relative to the end of the robot (flange reference frame), starting with the closest. For instance, for the 3 point PSD depicted [here](https://drive.google.com/file/d/1_yfqkUp4w1Qwi7k_yBzmAPf0obf2jAUw/view?usp=sharing), this parameter would be np.array([230, 240, 250]).
- **source_position : *np.ndarray***
Position (x, y, z) of the source (in mm) in relation to the base of the robot (world reference frame).
- **measure_with_nidaq : *bool***
......@@ -255,7 +274,7 @@ Returns an array of the position of each scintillator in relation to the source
Returns:
- **scintillators_positions_relative_to_source : *np.ndarray***
Array of the scintillators' position relative to source.
**MecaRobotForDosimetry.set_source_position**(*source_position_relative_to_TRF*)
......
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