Get current position in Manual Mode

Hi everyone

I’m developing a new external device for the xArm6 that will help me to program a repetitive task in an easier way. It has three buttons:
Button A: Start/Stop recording
Button B: Log the current pose when pressed
Button C: Play the recorded trajectory

I’m not an experienced Python user, in fact I’ve never used it so far. That’s why I’m trying to get started with Blocky first.

Some considerations.
-Manual mode has to be enabled to allow free movement of the arm and define each point of the trajectory
-The trajectory will be in linear motion.
-The speed and acceleration of the TCP will be fixed.

I need some help to start this project, any advice is appreciated

Thanks!


UFACTORY Website
Official Store
uArm User Facebook Group

Feedback:
English
中文通道

Here is a example with Python, the process is:

  • Press A, start recording, robot in manual mode.
  • Press B one time, record current position, like point1. Move the robot to another place and then press B one time, and it will record the position, like point 2.
  • Release A, stop recording and robot in position mode.
  • Press C, play the trajectory, robot will move from the point 1 to point 2 with linear motion.
from xarm.wrapper import XArmAPI
import time

# Connect to the xArm controller
arm = XArmAPI('192.168.1.80')  # Replace with your robot's IP address
time.sleep(0.5)

# Initialize the robot arm and set to position mode
arm.set_mode(0)  # Start in position mode
arm.set_state(0)

# Define the controller's CO pins for buttons
BUTTON_A_PIN = 0  # Corresponds to CO0
BUTTON_B_PIN = 1  # Corresponds to CO1
BUTTON_C_PIN = 2  # Corresponds to CO2

recording = False
trajectory = []

try:
    while True:
        # Get the status of the controller CO pins
        _, controller_co = arm.get_cgpio_digital()

        # Button A (CO0): Start recording and switch to manual mode, stop recording and switch back to position mode
        if controller_co[BUTTON_A_PIN] == 0:  # Low signal triggers
            if not recording:
                # Start recording and switch to manual mode
                recording = True
                arm.set_mode(2)  # Switch to manual mode
                arm.set_state(0)
                print("Recording started. Switched to manual mode.")
            time.sleep(0.1)  # Debounce delay
        elif recording and controller_co[BUTTON_A_PIN] == 1:
            # Stop recording and switch back to position mode
            recording = False
            arm.set_mode(0)  # Switch back to position mode
            arm.set_state(0)
            print("Recording stopped. Switched to position mode.")
            time.sleep(0.5)  # Debounce delay

        # Button B (CO1): Record the current position (Low signal triggers)
        if recording and controller_co[BUTTON_B_PIN] == 0:
            code, position = arm.get_position()
            if code == 0:
                trajectory.append(position)
                print(f"Position recorded: {position}")
            time.sleep(0.5)

        # Button C (CO2): Play the recorded trajectory (Low signal triggers)
        if controller_co[BUTTON_C_PIN] == 0 and trajectory:
            print("Playing back trajectory...")
            for pos in trajectory:
                arm.set_mode(0)
                arm.set_state(0)
                arm.set_position(*pos, wait=True)
            print("Trajectory playback complete.")
            time.sleep(0.5)

except KeyboardInterrupt:
    print("Program interrupted")

finally:
    # Disconnect from the robot arm
    arm.disconnect()

Thanks Daniel, I am learning the commands and replicating your code.