Factor-Robotics / odrive_ros2_control

ODrive driver for ros2_control
Apache License 2.0
270 stars 83 forks source link

Publish to topic cmd_val #5

Open MoonWalkerAZ opened 2 years ago

MoonWalkerAZ commented 2 years ago

Is there a good example how to control two motors for differential drive robot ? I would like to publish Twist message to cmd_val topic to control velocity of two motors.

borongyuan commented 2 years ago

Hi, there's a good example provied by @kallaspriit. Please refer to issue #1.

kallaspriit commented 2 years ago

Yeah my robot uses this library for physical and simulated differential drive robot, works nicely :)

https://github.com/kallaspriit/rosbot https://www.youtube.com/watch?v=t-1GAfGHRLs

MoonWalkerAZ commented 2 years ago

@kallaspriit I have checked your library, but I don't understand which part do I need to create a node that creates cmd_vel topic and sends the correct data to odrive. I'm new at this. Can you help me ? I have seen that you use joystick to send a Twist message, but I dont know where is that twist message being read and then converted to values that odrive driver understands.

kallaspriit commented 2 years ago

For manual testing /cmd_vel is published by teleop_twist_joy package (which uses joy package to get joystick input).

See this for reference https://github.com/kallaspriit/rosbot/blob/main/ros/src/teleop_twist_joy/launch/teleop.launch.py

To run in, you can run . launch_teleop.bash in ros or

. install/local_setup.bash
ros2 launch teleop_twist_joy teleop.launch.py

Which does the same thing.

MoonWalkerAZ commented 2 years ago

Ok, but who is subscribing to /cmd_vel topic ? And how is the Twist message being converted to input so that odrive can understand it ? Thats the part that I don't understand.

borongyuan commented 2 years ago

Before using this package, you need to be familiar with ros2_control framework. http://control.ros.org/ros2_controllers/diff_drive_controller/doc/userdoc.html

MoonWalkerAZ commented 2 years ago

Ok. Some example of how to use an implement diff_drive_controller with odrive package would be nice. @kallaspriit could you help me with this ?

kallaspriit commented 2 years ago

Well the rosbot repo IS an example of how to implement diff drive controller with odrive, not sure what else you need. Familiarize yourself with ROS2, ros2_control, URDF's and read the repo. It's all configuration, no actual code is needed but it takes time to understand what does what, no way around it.

Main configuration is in robot URDF (Universal Robot Descriptor File), take a look at https://github.com/kallaspriit/rosbot/blob/main/ros/src/rosbot_description/urdf/rosbot.urdf.xacro https://github.com/kallaspriit/rosbot/blob/main/ros/src/rosbot_description/ros2_control/rosbot_system.ros2_control.xacro https://github.com/kallaspriit/rosbot/blob/main/ros/src/rosbot_description/urdf/rosbot_links.urdf.xacro https://github.com/kallaspriit/rosbot/blob/main/ros/src/rosbot_description/config/diff_drive_controller.yaml

MoonWalkerAZ commented 2 years ago

Ok, thank you @kallaspriit and @borongyuan four your help.