Skip to content

Joint Control Tool (mc_example.py)

mc_example.py is an interactive joint position control tool that lets you control the robot's joint positions in real time via the keyboard, and supports playing back pre-recorded motion sequences.

Features

  • Interactive keyboard control of joint positions
  • Supports control of all 22 joints
  • Playback of pre-recorded motion sequences
  • Real-time viewing of joint status
  • Supports switching between multiple motion files

Installation Requirements

Before using this tool, please ensure:

  1. The GDK Python package is installed
  2. The robot connection is configured (hybrid deployment or on-device deployment)
  3. The motion sequence file (JSON format) is prepared

Usage

1. Prepare the Motion Sequence File

The tool reads motion sequence files in JSON format from the saved_commands/ directory. Make sure this directory exists and contains motion files:

cd ~/.cache/agibot/app/gdk/examples/python
mkdir -p saved_commands

Example motion sequence file format:

{
  "recorded_commands": [
    {
      "joint_names": ["idx21_arm_l_joint1", "idx22_arm_l_joint2"],
      "joint_positions": [0.5, -0.3]
    },
    {
      "joint_names": ["idx21_arm_l_joint1", "idx22_arm_l_joint2"],
      "joint_positions": [0.8, -0.5]
    }
  ]
}

2. Run the Tool

cd ~/.cache/agibot/app/gdk/examples/python
source ~/.cache/agibot/app/env.sh
python3 mc_example.py

3. Keyboard Control

After the tool starts, use the following keys to control it:

Key Function
w / W Move current joint in the positive direction (+0.1 rad)
s / S Move current joint in the negative direction (-0.1 rad)
a / A Switch to the previous joint
d / D Switch to the next joint
p / P Play the next frame of the current motion sequence
m / M Switch to the next motion file
q / Q Quit the program

4. Supported Joint List

The tool supports control of the following 22 joints:

Waist joints (5): - idx01_body_joint1 - Waist joint 1 - idx02_body_joint2 - Waist joint 2 - idx03_body_joint3 - Waist joint 3 - idx04_body_joint4 - Waist joint 4 - idx05_body_joint5 - Waist joint 5

Head joints (3): - idx11_head_joint1 - Head joint 1 - idx12_head_joint2 - Head joint 2 - idx13_head_joint3 - Head joint 3

Left arm joints (7): - idx21_arm_l_joint1 - Left arm joint 1 - idx22_arm_l_joint2 - Left arm joint 2 - idx23_arm_l_joint3 - Left arm joint 3 - idx24_arm_l_joint4 - Left arm joint 4 - idx25_arm_l_joint5 - Left arm joint 5 - idx26_arm_l_joint6 - Left arm joint 6 - idx27_arm_l_joint7 - Left arm joint 7

Right arm joints (7): - idx61_arm_r_joint1 - Right arm joint 1 - idx62_arm_r_joint2 - Right arm joint 2 - idx63_arm_r_joint3 - Right arm joint 3 - idx64_arm_r_joint4 - Right arm joint 4 - idx65_arm_r_joint5 - Right arm joint 5 - idx66_arm_r_joint6 - Right arm joint 6 - idx67_arm_r_joint7 - Right arm joint 7

Configuration Parameters

The following parameters can be modified in the code:

  • _step: The step size moved per key press (default: 0.1 rad)
  • _speed: Joint movement speed (default: 0.3)

Usage Examples

Example 1: Controlling a Single Joint

  1. Run the program
  2. Use the a/d keys to select the joint to control (e.g.: idx21_arm_l_joint1)
  3. Use the w/s keys to adjust the joint position
  4. Observe the robot's joint movement

Example 2: Playing a Motion Sequence

  1. Prepare the motion sequence file and place it in the saved_commands/ directory
  2. Run the program
  3. Use the m key to switch to the motion file you want to play
  4. Press the p key to play the motion sequence frame by frame
  5. Press the p key repeatedly to play the full motion

Notes

Safety Tips:

  • Ensure there is sufficient space around the robot before use
  • Pay attention to the joint's range of motion to avoid exceeding the limits
  • It is recommended to test with small movements first
  • In an emergency, press the q key to quit the program

Usage Restrictions:

  • The tool needs to read JSON files from the saved_commands/ directory; if the directory is empty or the file format is incorrect, the program will report an error
  • The motion sequence file must be valid JSON
  • Ensure the robot is properly connected and initialized