RoArm-M3 Control Robotic Arm with Commands
| ||
6. Control Robotic Arm with Commands
In this chapter, you will learn how to use command-based control of a robotic arm by invoking ROS2 services.
Keep the terminal window of the roarm_river robotic arm drive node running, open a new terminal and enter the container, run the Launch file for command control. This demo relies on Moveit2 for motion planning:
cd /home/ws/roarm_ws/ ros2 launch roarm_moveit_cmd command_control.launch.py
Note: After executing this command, the robotic arm will rotate (the upper arm extends straight ahead, parallel to the horizontal plane), please do not place fragile items around the robotic arm and keep away from children.
To display the robotic arm in Rviz2, you can refer to the operation steps in section 4.2 Run Moveit2 Drag-and-drop Interaction Demo.
6.1 Get Current Point Position
Open the third terminal to enter the container, then enter the workspace of the robotic arm ROS2, and call the service used to obtain the current location:
cd /home/ws/roarm_ws/ ros2 service call /get_pose_cmd roarm_msgs/srv/GetPoseCmd
6.2 Control End Movement of Robotic Arm to Specified Position
After opening a new terminal into the container, enter the workspace of the robotic arm ROS2 and call the service used to control the endpoint position of the robotic arm:
cd /home/ws/roarm_ws/ ros2 service call /move_joint_cmd roarm_msgs/srv/MoveJointCmd "{x: 0.3, y: 0, z: 0.1, roll: 0.2, pitch: 0.2, yaw: 0}"
xyz are the coordinates of the target position of the robotic arm in m. Roll, Pitch, and Yaw are the angles of rotation of the end effector in radians. You can control the robotic arm to move to a target position by calling this service.
6.3 Control End Movement of Robotic Arm to Specified Position along Line Trajectory (roll and pitch remain unchanged)
After opening a new terminal into the container, enter the workspace of the robotic arm ROS2 and call the service to move the robotic arm to the specified posture at the line trajectory::
cd /home/ws/roarm_ws/ ros2 service call /move_line_cmd roarm_msgs/srv/MoveLineCmd "{x: 0.2, y: 0.2, z: 0.1}"
x, y, and z are the coordinates of the target point, measured in meters.
6.4 Control Robotic Arm Gripper to Specified Arc Position
After opening a new terminal into the container, enter the workspace of the robotic arm ROS2, publish the data to the topic, and control the arc position of the gripper joint:
cd /home/ws/roarm_ws/ ros2 topic pub /gripper_cmd std_msgs/msg/Float32 "{data: 0.5}" -1
data: is the coordinate of the target point of the gripper joint, in radians, and the range of gripping is 0.0~1.5.
By calling this service, you can control the robotic arm gripper to move to the given target position.
6.5 Draw a Circle at Fixed Height
In Rviz2, click Add to add RobotModel.
In the RobotModel tab, find the Description Topic, select /robot_description, and the Links option will appear.
In the Links option, find hand_tcp, expand it and check Show Trail to view the motion trajectory of the end joint.
Call this service to move the robotic arm to the specified position along the arc trajectory:
cd /home/ws/roarm_ws/ ros2 service call /move_circle_cmd roarm_msgs/srv/MoveCircleCmd "{x0: 0.2, y0: 0.1, z0: 0.2, x1: 0.2, y1: 0.2, z1: 0.2 }"
x0, y0, and z0 are the coordinates of the center point, while x1, y1, and z1 are the coordinates of the target point in meters. By calling this service, the robotic arm can be controlled to move to the specified position along the arc trajectory, and the circle drawn by the robotic arm in the Rviz2 interface can also be seen.