ROS 2 driver of the AR4 robot arm from Annin Robotics. Tested with ROS 2 Jazzy on Ubuntu 24.04. Supports:
- AR4 MK1 (Original version), MK2, MK3, MK4
- AR4 servo gripper
Features:
- MoveIt control
- Gazebo simulation
The following projects showcases additional features and capabilities built on top of this driver:
- Hand-Eye calibration
- Teleoperation using Xbox controller
- Multi-arm control
- Voice controlled pick and place
- annin_ar4_description
- Hardware description of arm & servo gripper urdf.
- annin_ar4_driver
- ROS interfaces for the arm and servo gripper drivers, built on the ros2_control framework.
- Manages joint offsets, limits and conversion between joint and actuator messages.
- Handles communication with the microcontrollers.
- annin_ar4_firmware
- Firmware for the Teensy and Arduino Nano microcontrollers.
- annin_ar4_moveit_config
- MoveIt module for motion planning.
- Controlling the arm and servo gripper through Rviz.
- annin_ar4_gazebo
- Simulation on Gazebo.
There are two modules that you will always need to run:
-
Arm module - this can be for either a real-world or simulated arm
- For controlling the real-world arm, you will need to run the
annin_ar4_drivermodule - For the simulated arm, you will need to run the
annin_ar4_gazebomodule - Either of the modules will load the necessary hardware descriptions for MoveIt
- For controlling the real-world arm, you will need to run the
-
MoveIt module - the
annin_ar4_moveit_configmodule provides the MoveIt interface and RViz GUI.
The various use cases of the modules and instructions to run them are described below:
If you are unfamiliar with MoveIt, it is recommended to start with this to explore planning with MoveIt in RViz. This contains neither a real-world nor a simulated arm but just a model loaded within RViz for visualisation.
The robot description, moveit interface and RViz will all be loaded in the single demo launch file
ros2 launch annin_ar4_moveit_config demo.launch.py ar_model:=mk4Start the annin_ar4_driver module, which will load configs and the robot description:
ros2 launch annin_ar4_driver driver.launch.py ar_model:=mk4 calibrate:=True include_gripper:=TrueAvailable Launch Arguments:
ar_model: The model of the AR4. Options aremk1,mk2,mk3ormk4. Defaults tomk4.calibrate: Whether to calibrate the robot arm (determine the absolute position of each joint).include_gripper: Whether to include the servo gripper. Defaults to:include_gripper:=True.serial_port: Serial port of the Teensy board. Defaults to:serial_port:=/dev/ttyACM0.arduino_serial_port: Serial port of the Arduino Nano board. Defaults toarduino_serial_port:=/dev/ttyUSB0.
calibrate:=False.
Start MoveIt and RViz:
ros2 launch annin_ar4_moveit_config moveit.launch.pyYou can now plan in RViz and control the real-world arm. Joint commands and joint states will be updated through the hardware interface.
NOTE: At any point you may interrupt the robot movement by pressing the E-Stop button on the robot. This would abruptly stop the robot motion! To reset the E-Stop state of the robot use the following command
ros2 run annin_ar4_driver reset_estop.sh <AR_MODEL>where <AR_MODEL> is the model of the AR4, one of mk1, mk2, or mk3
Start the annin_ar4_gazebo module, which will start the Gazebo simulator and load the robot description.
ros2 launch annin_ar4_gazebo gazebo.launch.pyStart Moveit and RViz:
ros2 launch annin_ar4_moveit_config moveit.launch.py use_sim_time:=true include_gripper:=TrueYou can now plan in RViz and control the simulated arm.
The following ROS 2 commands are useful during setup, testing, and manual calibration.
All commands assume your ROS workspace has been sourced.
ros2 action send_goal /gripper_controller/gripper_cmd \
control_msgs/action/GripperCommand \
"{command: {position: 0.012, max_effort: 0.0}}"
ros2 action send_goal /gripper_controller/gripper_cmd \
control_msgs/action/GripperCommand \
"{command: {position: 0.000, max_effort: 0.0}}"
This is the recommended pose when powering off the robot.
ros2 service call /park std_srvs/srv/Trigger "{}"
ros2 service call /calibrate_mask annin_ar4_driver/srv/CalibrateMask "{mask: '000011'}"
The calibration mask is a 6-character string, one character per joint, ordered as:
[J1][J2][J3][J4][J5][J6]
Each character may be:
1β Calibrate this joint0β Skip this joint
Examples:
000011β Calibrate J5 and J6 only111111β Calibrate all joints100000β Calibrate J1 only001100β Calibrate J3 and J4 only
This allows selective recalibration when only certain joints have been mechanically adjusted.
If your robot joints appear slightly misaligned after calibration (for example, a joint that is not perfectly vertical or horizontal when commanded to zero), joint offsets should be adjusted directly in the Teensy firmware, not in ROS configuration files.
Near the top of the Teensy sketch file, locate the following array:
float CAL_OFFSET_DEG[NUM_JOINTS] = { 1.2, -0.8, 0, 0, 0, 0 };
This array defines a per-joint angular offset in degrees that is applied after calibration to compensate for small mechanical and assembly tolerances.
Joint index mapping:
- Index 0 β J1
- Index 1 β J2
- Index 2 β J3
- Index 3 β J4
- Index 4 β J5
- Index 5 β J6
- Perform a normal calibration sequence.
- Command the robot to the vertical rest / park position.
- Using a digital level or angle gauge, measure each joint.
- If a joint is not aligned as expected:
- Add a positive value if the joint must rotate further in the positive direction.
- Add a negative value if the joint must rotate back in the negative direction.
- Update the corresponding value in
CAL_OFFSET_DEG. - Reflash the Teensy firmware and re-run calibration.
If Joint 1 requires a +1.2Β° correction and Joint 2 requires a β0.8Β° correction:
float CAL_OFFSET_DEG[NUM_JOINTS] = { 1.2, -0.8, 0, 0, 0, 0 };
Notes:
- Any change to
CAL_OFFSET_DEGrequires reflashing the Teensy - These offsets are intended for fine-tuning only
- Large errors usually indicate a mechanical alignment issue
By default this repo uses velocity-based joint trajectory control. It allows the arm to move a lot faster and the arm movement is also a lot smoother. If for any
reason you'd like to use the simpler classic position-only control mode, you can
set velocity_control_enabled: false in driver.yaml. Note that you'll need to reduce velocity and acceleration scaling in order for larger motions to succeed.
See the Gripper Overcurrent Protection page.
This example demonstrates a minimal C++ ROS 2 node using MoveItβs MoveGroupInterface to perform a simple pick-style motion sequence:
- open the gripper
- move the arm to a safe joint pose
- move to a pick pose
- close the gripper
- return to the safe pose
This example is intended as a starting point for writing custom ROS 2 nodes that command the AR4 through MoveIt.
cd ~/ros2_ws/src
ros2 pkg create ar4_moveit_cpp_demo --build-type ament_cmake \
--dependencies rclcpp moveit_ros_planning_interfaceCopy the example source file:
- simple_pick_place_mgi.cpp
into:
- ar4_moveit_cpp_demo/src/
Replace the generated CMakeLists.txt in:
- ar4_moveit_cpp_demo/
with the CMakeLists.txt provided in the example folder.
cd ~/ros2_ws
colcon build
source install/setup.bashros2 launch annin_ar4_driver driver.launch.py \
ar_model:=mk4 calibrate:=True include_gripper:=Trueros2 launch annin_ar4_moveit_config moveit.launch.pyros2 run ar4_moveit_cpp_demo simple_pick_place_mgi- MoveIt must already be running before launching the demo node.
- The demo uses joint-space targets for the arm and named states for the gripper (
open/closed) as defined in the SRDF. - The code is intentionally minimal and designed to be easily extended for more advanced behaviors such as pose targets, collision objects, or service-based command interfaces.
