Open afr2903 opened 6 months ago
This feature is possible using the xArm SDK
methods. First, the arm is set to manual mode, until Enter
is pressed. Alternatively, linear positions can be used to achieve the desired state.
def record_state(self, state):
"""Record a new state for the arm and gripper"""
print(f"Recording state: {state}")
self.arm.set_mode(2) # Joint teaching mode
self.arm.set_state(0)
print("The arm is now in MANUAL mode, press enter to record the position...")
input()
Then, the user is guided by the terminal to save the desired state in joint
or lineal
movements:
print("Do you want to record a joint or lineal position? (J/L)")
movement_type = input()
if movement_type.upper() == "J": # Joint position
joint_position = self.arm.get_servo_angle()
print("Joint position recorded, paste the following line in the ARM_STATES dictionary:")
print(f"\"{state}\": [\"Y\", \"J\", {joint_position[1][0]}, {joint_position[1][1]}, {joint_position[1][2]}, {joint_position[1][3]}, {joint_position[1][4]}, {joint_position[1][5]}, 10],")
elif movement_type.upper() == "L": # Lineal position
print("Which is the desired TCP, board or wire gripper? (B/W)")
desired_tcp = input()
if desired_tcp.upper() == "B":
self.arm.set_tcp_offset(BOARD_TCP)
elif desired_tcp.upper() == "W":
self.arm.set_tcp_offset(WIRE_TCP)
else:
self.arm.set_tcp_offset([0,0,0,0,0,0])
lineal_position = self.arm.get_position()
print("Lineal position recorded, paste the following line in the ARM_STATES dictionary:")
print(f"\"{state}\": [\"Y\", \"L\", {lineal_position[1][0]}, {lineal_position[1][1]}, {lineal_position[1][2]}, {lineal_position[1][3]}, {lineal_position[1][4]}, {lineal_position[1][5]}, 10, \"{desired_tcp.upper()}\"],")
An element to add to the dictionary is displayed in the terminal to be copied and pasted.
Refactorization of the main code implementation for easier use by mechatronic engineering students.
Goals: