RoArm-M2-S 5. Control the Robotic Arm with Gamepad or Keyboard
| ||
5. Control the Robotic Arm with Gamepad or Keyboard
This chapter introduces how to use keyboard keys or a gamepad to control the robotic arm. The product RoArm-M2-S does not come with a gamepad, but you can purchase an Xbox Bluetooth controller separately and connect it to your computer for control.
If you have been following the previous tutorials, you need to close the Moveit2 drag-and-drop interaction example from the previous chapter before starting the robotic arm control-related nodes. In the terminal window where you ran the Moveit2 drag-and-drop interaction example, press Ctrl+C to close this process. The terminal running the robotic arm driver node should not be closed; otherwise, you won't be able to control the physical robotic arm.
If you have also terminated the robotic arm driver node's terminal process, you need to restart it according to the instructions in 3.3_Drive_Nodes_of_Robotic_Arm. Keep the robotic arm driver node running, then run the robotic arm control-related nodes.
- To start the robotic arm control-related nodes in the terminal where you closed the Moveit2 drag-and-drop interaction example, enter the following command, which will open a new Rviz2 robotic arm model interface:
ros2 launch moveit_servo demo.launch.py
- Alternatively, you can run this in a new terminal window. If running in a new terminal, make sure to enter the robotic arm ROS2 workspace first, then start the robotic arm control-related nodes as follows:
cd roarm_ws_em0 ros2 launch moveit_servo demo.launch.py
5.1 Keyboard Control for the Robotic Arm
Press Ctrl+Alt+T to open a new terminal window, enter the robotic arm ROS2 workspace, and run the following command to obtain control instructions from the keyboard:
cd ~/roarm_ws_em0/ ros2 run roarm_moveit_cmd setgrippercmd
Press Ctrl+Alt+T to open a new terminal window, enter the robotic arm ROS2 workspace, and run the following commands to get the control commands from the keyboard:
cd ~/roarm_ws_em0/ ros2 run roarm_moveit_cmd keyboardcontrol
Keep this terminal window active (i.e., ensure the operation keys are focused on this terminal window) and use the following keys to control the robotic arm:
- Coordinate Control
- Arrow Key ↑: Move in the positive X-axis direction
- Arrow Key ↓: Move in the negative X-axis direction
- Arrow Key ←: Move in the positive Y-axis direction
- Arrow Key →: Move in the negative Y-axis direction
- ; Key: Move in the positive Z-axis direction
- . Key: Move in the negative Z-axis direction
- Joint Control
- Number 1 Key: Base joint movement
- Number 2 Key: Shoulder joint movement
- Number 3 Key: Elbow joint movement
- Number 4 Key: Gripper joint movement
- Letter R Key: Toggle the direction of the above joint controls
Finally, just press the letter Q to exit the operation.
5.2 Gamepad Control for the Robotic Arm
Plug the controller receiver into the computer, click "Devices" → "USB" → the device name with "Xbox" on it at the top of Oracle VM VirtualBox. A check mark (√) in front of the device name indicates that the controller is connected to the virtual machine. You can control the robotic arm using the following game controller buttons:
- Left-side Joint Control:
- Left and Right Buttons: Base joint movement
- Up and Down Buttons: Shoulder joint movement
- Right-side Joint Control:
- X, B Buttons: Elbow joint movement
- Y, A Buttons: Gripper joint movement
- XY Axis Coordinate Control:
- Left Stick: X-axis movement
- Right Stick: Y-axis movement
RoArm-M2-S ROS2 Humble + Moveit2 Tutorial
- RoArm-M2-S 1. How to Install ROS2
- RoArm-M2-S 2. ROS2 Workspace Description
- RoArm-M2-S 3. Drive Nodes to Control Real-world Robotic Arm
- RoArm-M2-S 4. Drag-and-drop Interactions in Moveit2
- RoArm-M2-S 5. Control the Robotic Arm with Gamepad or Keyboard
- RoArm-M2-S 6. Using Foxglove for Web-Based Control
- RoArm-M2-S 7. Web Application Based on ROS2Web app
- RoArm-M2-S 8. Control Robotic Arm with Commands
- RoArm-M2-S 9. Combined Use
- RoArm-M2-S 10. Ubuntu 22.04 Install ROS2 Humble Tutorial