Kria Autonomous Robotic Platform (Karp) uses Odrive board for controlling the RBE-102024-003 24V 6.5-inch wheel hub motor with an encoder. In this tutorial, we will see how to install Odrive on our Petalinux image, how to calibrate the motor and encoders, and how to move the motor using ROS 2.
1. RBE-102024-003 motorsThe motors used in Karp are wheel hub electric motors.
Construction form items for this motor are:
- Number of phases: 3-phases
- Core slot number: 27
- Number of magnet poles: 30
- Hall Angle: 40º
- Encoder: AEDR-8300 (Incremental Encoder, 3200CPR)
Standard operating conditions:
- Rated voltage: 24V
- Rated load: 5N.m
- Rotation direction: CW&CCW
- Motor position: Any position available
- Voltage range for use: 20-36V
- Operating conditions: -20ºC to 60ºC
- Storage conditions: -25ºC to 80ºC
Electrical Pinout:
These motors have one optical incremental encoder, which needs the Red(+), Black(-), White(A), and Grey(B) cables, and also a Hall sensor which needs the Red(+), Black(-) and HALL A, B and C cables.
For Karp we don't use the Hall sensor, we use the AEDR-8300 encoder for obtaining the motor position.
These different cables are grouped in 3 different connectors whose Male/Femal part numbers are PARP-06V -> PALR-06V,PARP-05V -> PALR-05V, and VHR-3N -> B3P-VH and B3P-VH-B. You can buy them in any online store like Digikey and create your own cables for connecting them to the Odrive board.
2. Odrive boardOdrive board is a high-performance motor control for robotics. These boards can control two motors and 24V and 48V versions are available. It is open-source Hardware and Software with a forum in which they solve any doubt.
This board has a voltage connector on the left side. Two A, B, C connectors in which the motors are connected, a connector in the middle for the brake resistance, some GPIO pins, Encoder A, B, Z connectors, CAN interface and more.
An image of the board,
We will use this board for driving two RB·102024-003 motors.
3. Wiring the RBE-102024-003 motor in the Odrive boardAs you can see in the image this is how the wiring is done.
We connect the motor phase U, V, and W to the A, B, and C connectors. And the Red(+), Black(-), White(A), and Grey(B) encoder cables to the 5V, GND, A, and B Odrive pins. Then you only need to feed the board with 24V and connect it using a Serial cable to the board.
In the image, you can also see an usb isolator module adum3160.
This is placed to solve the ground loop problem as specified in the documentation.
4. Install Odrive on the Kria board.For installing Odrive we only need to install the python package they provide. This can be done like,
sudo pip3 install --upgrade odrive
To check that everything is working as expected we can launch odrivetool, this is a command-line tool from which we can configure different motor parameters in the Odrive board. If you launch it in Kria board you will see,
xilinx-k26-starterkit-2021_2:~$ odrivetool
ODrive control utility v0.5.4
Website: https://odriverobotics.com/
Docs: https://docs.odriverobotics.com/
Forums: https://discourse.odriverobotics.com/
Discord: https://discord.gg/k3ZZ3mS
Github: https://github.com/odriverobotics/ODrive/
Please connect your ODrive.
5. Configuring Odrive motor board parameters.As specified in section 4 you can use odrivetool for configuring motor parameters on Odrive board. This is helpful at first when you don't know how Odrive works. This is very time expensive and tedious work, to ease this work a python script has been created.
You can see how odrive_config.py is in the code section. This script configures the two drive axis motors, encoders, and PID gains. When everything is calibrated it moves the motors from 0 to 360 degrees in increments of 30 degrees.
6. Controlling the motors using ROS 2.In the past, we have written a project about how to install ROS 2 in Kria with Petalinux 2021.2. You can go there before following this section.
For running motors using ROS 2, we will use the odrive_ros2_control package.
This package contains the next packages inside:
- odrive_ros2_control -> Metapackage for
odrive_ros2_control
packages - odrive_bringup -> Launch files and configurations for ODrive
- odrive_description -> ODrive ros2_control description
- odrive_hardware_interface -> ODrive hardware interface
This package is prepared to work with ROS 2 Foxy (you can't use ROS 2 Galactic for the moment because there is an API change in ros_control) and you can see that the repository has three branches, devel, and fw-v.0.5.3 which are the same, and fw-v0.5.1 which is the one I am going to use since my Odrive board is flashed with this version. I try to flash the board with a newer version but I couldn't make it work properly with another version that was not 0.5.1.
In this case for compiling the package we haven't used any pre-built meta-ros recipes and we have compiled the package directly inside the Kria board. This is not a good practice and the compilation is preferable to do it outside the board but due to lack of time, this was done like this.
Before doing this compilation on the board we have installed the next packages in the Petalinux image:
ROS_DEV_PACKAGES = " \
ament-lint-auto-dev \
ament-cmake-auto-dev \
ament-cmake-core-dev \
ament-cmake-cppcheck-dev \
ament-cmake-cpplint-dev \
ament-cmake-export-definitions-dev \
ament-cmake-export-dependencies-dev \
ament-cmake-export-include-directories-dev \
ament-cmake-export-interfaces-dev \
ament-cmake-export-libraries-dev \
ament-cmake-export-link-flags-dev \
ament-cmake-export-targets-dev \
ament-cmake-gmock-dev \
ament-cmake-gtest-dev \
ament-cmake-include-directories-dev \
ament-cmake-libraries-dev \
ament-cmake-dev \
ament-cmake-pytest-dev \
ament-cmake-python-dev \
ament-cmake-ros-dev \
ament-cmake-target-dependencies-dev \
ament-cmake-test-dev \
ament-cmake-version-dev \
ament-cmake-uncrustify-dev \
ament-cmake-flake8-dev \
ament-cmake-pep257-dev \
ament-copyright-dev \
ament-cpplint-dev \
ament-flake8-dev \
ament-index-python-dev \
ament-index-cpp-dev \
ament-lint-cmake-dev \
ament-mypy-dev \
ament-package-dev \
ament-pclint-dev \
ament-pep257-dev \
ament-pycodestyle-dev \
ament-pyflakes-dev \
ament-uncrustify-dev \
ament-xmllint-dev \
pluginlib-dev \
class-loader-dev \
console-bridge-dev \
rcpputils-dev \
rcutils-dev \
tinyxml-vendor-dev \
tinyxml2-vendor-dev \
libtinyxml2-dev \
rclcpp-dev \
rcl-dev \
rmw-dev \
rcl-yaml-param-parser-dev \
rosidl-runtime-c-dev \
rosidl-runtime-cpp-dev \
rosidl-typesupport-interface-dev \
builtin-interfaces-dev \
tracetools \
rcl-interfaces-dev \
libstatistics-collector-dev \
statistics-msgs-dev \
hardware-interface-dev \
libstdc++ \
libstdc++-staticdev \
"
These are all the dev packages needed to compile odrive_ros2_control inside the board.
We need also to install the necessary colcon extension package for compiling and ros_control packages.
python3-colcon-common-extensions \
ros2-control \
ros2-controllers \
Once we have all these dependencies installed on the Petalinux image we can compile the package with the next commands.
mkdir -p ros_ws/src
cd ros_ws/src/
git clone https://github.com/jlamperez/odrive_ros2_control -b fw-v0.5.1
cd ..
colcon build
7. Launching Odrive on KriaFor launching the motor you can launch odrive.launch.py
source install/local_setup.bash
ros2 launch odrive_bringup odrive.launch.py
ros2 launch odrive_bringup odrive.launch.py # if we want to see both motor joints.
After launching the nodes you should be able to see the next topic lists
$ ros2 topic list
/clicked_point
/dynamic_joint_states
/goal_pose
/initialpose
/joint0_velocity_controller/commands
/joint_states
/parameter_events
/robot_description
/rosout
/tf
/tf_static
And send commands to the joint0_velocity_controller with
ros2 topic pub -1 /joint0_velocity_controller/commands std_msgs/Float64MultiArray "data: [1]"
And monitor the status of axis0, including position, speed, torque, temperature, error code with:
ros2 topic echo /dynamic_joint_states
As pointed out in the documentation you can also visualize tf in rviz2.
Karp is based on DiffBot or ''Differential Mobile Robot'' from ros2_control_demos, this is, a simple mobile base with a differential drive. The robot is basically a box moving according to differential drive kinematics. You can find more about ros2_control in the documentation.
The list of hardware interfaces from Karp are the next ones
ros2 control list_hardware_interfaces
command interfaces
left_wheel_joint/velocity [claimed]
right_wheel_joint/velocity [claimed]
state interfaces
left_wheel_joint/position
left_wheel_joint/velocity
right_wheel_joint/position
right_wheel_joint/velocity
and the list of controllers
$ ros2 control list_controllers
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
karp_base_controller[diff_drive_controller/DiffDriveController] active
You can check the implementation of these controllers in Kria Autonomous Robotic Platform (karp) ROS 2 packages.
9. meta-karpYou can find Petalinux files inside https://github.com/jlamperez/meta-karp repository which is the Petalinux meta-user layer for Kria Autonomous Robotic Platform (KARP).
Comments
Please log in or sign up to comment.