odrive_config.py : Odrive for BLDC motor Automatic configuration.
odrive_twist_driver.py : Odrive subscrive /cmd_vel, then calculate /odom and /odom_path
OS : Ubuntu 22.04
ROS : humble
flowchart TD
A[Start] --> B[Initialize ROS Node: odrive_motor_control]
B --> C[Create OdriveMotorControl Object]
C --> D[Connect to Odrive]
D --> E[Setup Parameters and Variables]
E --> F[Setup ROS Subscribers and Publishers]
F --> G[Setup Transform Broadcasters]
G --> H[Enter Main Control Loop]
H --> I[Check if ROS is Shutdown]
I -->|No| J[Calculate Relative Velocity]
J --> K[Get Current Position and Calculate Odometry]
K --> L[Publish Odometry and Transform]
L --> M[Publish Odometry Path]
M --> N[Set Motor Velocity]
N --> O[Sleep for Fixed Duration]
O --> H
I -->|Yes| P[End]
subgraph OdriveMotorControl
Q[Constructor: Initialize and Connect to Odrive]
R[odrive_setup: Configure Odrive]
S[calc_relative_vel: Calculate Relative Velocities for Wheels]
T[callback_vel: Update Target Velocities from ROS Message]
U[calcodom: Calculate and Update Odometry]
V[odrive_control: Main Control Loop for Motor Velocity]
end
Q --> R
R --> V
V --> S
S --> U
U --> L
T --> S
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install python3 python3-pip
$ sudo pip3 install --upgrade odrive
$ echo "PATH=$PATH:~/.local/bin/" >> ~/.bashrc
$ sudo apt-get install ros-<ros_distro>-tf-transformations
cd ~/ros2_ws/src/odrive_ros2_control/python_programs
sudo python3 odrive_config.py
lsusb
Bus 001 Device 009: ID 1209:0d32 Generic ODrive Robotics ODrive v3
ls -al /dev/bus//usb//001/009
crw-rw-r-- 1 root root 189, 8 5月 29 14:49 /dev/bus//usb//001/009
sudo chmod 666 /dev/bus/usb/001/009
cd ~/ros2_ws
source ~/ros2_ws/install/setup.bash
ros2 launch odrive_ros2_control odrive_keyboard_control.py
If all goes well, the following message will appear on the terminal
Connect to Odrive...
Connect to Odrive Success!!!