This contains a ROS2 node for communication with mjbots moteus controllers.
License: Apache 2.0
- Clone this repository into the
src
folder of your ROS2 workspace.
cd src
git clone https://github.com/mjbots/moteus_ros2
- Navigate to the top level of the ROS2 workspace folder and run:
colcon build
- Source the workspace:
source ./install/setup.bash
- Run the example launch file:
ros2 launch moteus_control example_launch.yaml
The following commands assume you are using the parameters from the default launch file. You can change the namespace or the IDs configured according to your application. The following are examples of commands that can be sent.
- Show the current status of servo ID 1.
ros2 topic echo /moteus/id_1/state
- Request the motor stop, in order to clear any faults.
ros2 topic pub /moteus/id_1/cmd_stop std_msgs/msg/Empty "{}"
- Send a position mode command.
The following requests a move to position 0.5, repeating the command at 50Hz. Each field which should be sent, should be a single element list with the desired value present.
ros2 topic pub -r 50 /moteus/id_1/cmd_position moteus_msgs/msg/PositionCommand "{position: [0.5], accel_limit: [5]}"
Note that the ROS2 node only sends commands to moteus when it receives them from ROS. Thus you need to either:
a. Send ROS commands faster than the configured watchdog timeout period (0.1s by default)
b. Change servo.default_timeout_s
to nan
if you want it disabled
c. Temporarily override the watchdog timeout on a per-command basis like the following:
ros2 topic pub /moteus/id_1/cmd_position moteus_msgs/msg/PositionCommand "{position: [0.5], accel_limit: [5], watchdog_timeout:[.NAN]}"
- Send a command that requires no arguments. The possible options are:
/moteus/id_1/cmd_stop
/moteus/id_1/cmd_brake
/moteus/id_1/cmd_recapture_position_velocity
These can all be sent with the following:
ros2 topic pub -1 /moteus/id_1/cmd_brake std_msgs/msg/Empty "{}"
- Send a command that requires a single floating point argument. The possible options are:
/moteus/id_1/cmd_set_output_exact
/moteus/id_1/cmd_set_output_nearest
These can be sent with something of the form:
ros2 topic pub -1 /moteus/id_1/cmd_set_output_exact std_msgs/msg/Float32 "{data: 0.5}"
For usage with the pi3hat, the easiest method is to run the entirety
of the ROS2 session as root. That can be accomplished by running
sudo bash
before sourcing the ROS2 setup profiles. An example is
below:
sudo bash
source /opt/ros/iron/setup.sh
source ./install/local.bash
Currently the resolution of the command and query results cannot be changed.
The maximum achievable performance of a system in terms of update rate using this node will be much lower than a dedicated process. The dedicated process is able to combine commands and queries for all servos into a single cycle, and control the resolution of all commands and responses. If you need a fast update rate (>100Hz), consider not using ROS2 and instead directly using either the moteus python or C++ library.
The semantics of all commands are identical to that found in the primary moteus reference documentation: https://github.com/mjbots/moteus/blob/main/docs/reference.md