ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hi,
I have been strugling with the same issue and took me few days to figure it out. I commited my WIP code so u can see an exampled. https://github.com/DeborggraeveR/ros2-mecanum-bot
This is a simular approuch as my ROS1 robot which is using the RobotHW interface and communicates with arduiono: https://github.com/DeborggraeveR/ampru
I don't have a tutorial yet, but here is a quick summary of what i done so far
Visualize the robot Create the mecanumbot_description package with urdf model Create the mecanumbot_bringup package with launch file for robot_state_publisher & join_state_publisher to be able to visualize the robot model in rviz2
Add the hardware interface Create the mecanumbot_hardware package and implement a "hardware_interface::SystemInterface" class. Most important line in this class is:
hardware_interface::CommandInterface(
info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &velocity_commands_[i]
)
If the joint name = wheel_joint, we map /joint_state/wheel_joint/velocity to "velocity_command_" So if the velocity changes, the value will be stored in the "velocity_command_" which u can read during the "write" call. Important on making this package work:
Next you need to define the joints used by the hardware in the URDF file (see bottom of my URDF => ros2_control node) I also added the controller config file to the description package
Use the hardware class Next i removed the "joint_state_publisher" from the bringup package launch files and added ros2_control When u launch this, it wont work. U can call "ros2 control list_hardware_interfaces" to see your hardware and notice all joint are unclaimed U can call "ros2 control list_controllers" to see there are no active controllers
Next is to get your joint state published, this seems to do the same as the "joint_state_publisher" which is now commented out in my launch files
ros2 control load_start_controller joint_state_controller
Still the hardware is unclaimed. I tried with running "ros2 control load_start_controller diffbot_base_controller" to launch the DiffDriveController. I found example of this in PR or ros2_control_demos repo: https://github.com/BorgesJVT/ros2_control_demos/tree/demo_diff_drive_controller
Custom controller As i'm working on a mecanum bot, i also created a mecanumbot_controller package, which contains the controller. Important part of the controller is that it subscribes to "/cmd_vel". Run "ros2 run teleop_twist_keyboard teleop_twist_keyboard" to publish those messages The controller added the joints used by the hardware in the "command_interface_configuration" method. This causes running this controller to claim the joins (ros2 control list_hardware_interfaces)
During the update of the controller i set the velocity as value of the "hardware_interface::LoanedCommandInterface" This causes the variable mapped in the hardware to be updated.
Auto launch controllers I have a open question here on the board on how to spawn the controllers trough launch files. As workaround i added the mecanumbot_control packages, where the main method is the same as the ros2_control controller_manager main and where i add, configure & start my controllers
Final When i run the teleopt_twist_keyboard and "move" the robot around, the "hardware::write" method will log the velocity of the wheel has change :)
Kind regards,