02-22-2023, 05:50 PM
(This post was last modified: 02-22-2023, 05:52 PM bydunderMethods.)
Thanks for the reply! I've updated my code and here's where I am at now:
The tool instantly rotates to the selected image when I call set_picture(pic_idx) from python (jupyter), great!
Any time I use set_picture to rotate the tool 180deg in one move (moving from picture 1 -> 4 for example) the robot goes crazy and tries to twist itself into a pretzel. I can make incremental moves (1 -> 3 -> 5) that when summed exceed 180 just fine; or if I go 1 -> 6 it turns the opposite direction with no issues. I even tried adding some logic to add or subtract 1deg if the new angles is abs(180) resulting in -179deg or 179deg and this still causes the robot to go crazy. What am I doing wrong here?
Here is the updated code:
The tool instantly rotates to the selected image when I call set_picture(pic_idx) from python (jupyter), great!
Any time I use set_picture to rotate the tool 180deg in one move (moving from picture 1 -> 4 for example) the robot goes crazy and tries to twist itself into a pretzel. I can make incremental moves (1 -> 3 -> 5) that when summed exceed 180 just fine; or if I go 1 -> 6 it turns the opposite direction with no issues. I even tried adding some logic to add or subtract 1deg if the new angles is abs(180) resulting in -179deg or 179deg and this still causes the robot to go crazy. What am I doing wrong here?
Here is the updated code:
Code:
self.deg_per_idx = 360/6 # Divide 360deg by the 6 sides of the hexagon
self.d2r = 0.017453292519943295 # Myltiply by this value to convert degrees to radians
def set_picture(self, new_pic_idx):
""" Rotate the tool so that the given new_pic_idx is the picture that will be shown to the camera """
# The next line calculates how many degrees to rotate from the current pic_idx to the new_pic_idx
new_pic_angle = ((self.current_pic_idx - 1) * -self.deg_per_idx) - ((new_pic_idx - 1) * -self.deg_per_idx)
curr_pose = self.robot.Pose() # Get the robot's current pose
new_pose = robomath.rotz(new_pic_angle * self.d2r) # Calculate the new pose (d2r converts deg to radians)
result = self.robot.MoveJ(curr_pose * new_pose) # Move the robot to the new pose
self.current_pic_idx = new_pic_idx # Update the current picture index
self.robot.WaitMove(timeout=5000)