Based on Micro-ROS, the open-source omnidirectional mobile robot T-Robot (Xuri x3 pie + ESP32)

Repo:https://github.com/z2010012286/T-Robot

0 Open source motivation

  • Learned ROS and micro-ROS on and off for about 1 year and always wanted to do something
  • Rising Sun x3 PI +ROS2 has a lot of interesting things that need a platform to achieve
  • ** There seems to be no open source mobile robot project using Micro-ROS at the bottom in China (if there is, please ignore…) **

1 Robot hardware part

** are Taobao procurement, in order to avoid advertising suspicion, do not put links ~**

  • ** Robot chassis layout **
  • ** Main control ** : esp32 (ESP-WROOM-32)+** Rising Sun x3 Pie **(2GB)
  • ** LiDAR ** : LD14
  • IMU : MPU9250
  • ** Motor ** : WGA12-N20 DC motor (12V, 1:50 reduction ratio)
  • ** Motor drive chip ** : 4 RZ7889
  • ** Encoder ** : AB dual phase incremental magnetic Hall encoder
  • ** Power Supply: 12V lithium battery; -12V drive motor; External 12V to 5V module provides DC-5V output (maximum current 4A);
  • ** Wheels ** : 4 wheat wheels, diameter 48mm
  • ** Structural parts ** : Cut acrylic sheet, 3D printing

2 Underlying firmware part (core)

2.1 lib/config

Contains most macro definitions, pin definitions, etc.

2.2 lib/encoder

Encapsulation of c + + library is suitable for esp32 encoder, the original author warehouse address: [ESP32encoder] (https://github.com/madhephaestus/ESP32Encoder.git)

  • This project has made necessary modifications to it, adding the ‘getRPM()’ function to directly obtain the speed information.

```c++ float ESP32Encoder::getRPM(int counts_per_rev) //counts_per_rev: Count of encoders per revolution { counts_per_rev_ = counts_per_rev; int64_t encoder_ticks = getCount(); // this function calculates the motor’s RPM based on encoder ticks and delta time unsigned long current_time = micros(); unsigned long dt = current_time - prev_update_time_; // convert the time from milliseconds to minutes double dtm = (double)dt / 60000000; double delta_ticks = encoder_ticks - prev_encoder_ticks_; // calculate wheel’s speed (RPM) prev_update_time_ = current_time; prev_encoder_ticks_ = encoder_ticks; return ((delta_ticks / counts_per_rev_) / dtm); } `

  • Configurable for different encoder counting modes:

```c++ //file: ESP32encoder.h void attachSingleEdge(int aPintNumber, int bPinNumber); // 1x void attachHalfQuad(int aPintNumber, int bPinNumber); // 2x void attachFullQuad(int aPintNumber, int bPinNumber); //4 times `

2.3 lib/imu

  • imu_interface.h
  • Defines the ‘ros2 imu message’ format of imu, which can be sent directly to ROS/ROS2 for use;
  • ‘IMUInterface()’ constructor initializes’ imu_msg.header 'related information, different versions of the writing slightly different;
  • Abstract 4 virtual functions, easy to adapt to different types of IMUs;

```c++ //file: imu_interface.h virtual geometry_msgs__msg__Vector3 readAccelerometer() = 0; virtual geometry_msgs__msg__Vector3 readGyroscope() = 0; virtual bool startSensor() = 0; virtual void calibrateGyro()=0; `

  • default_imu.h
  • rely on MPU9250 library (https://github.com/hideakitai/MPU9250.git), the library can be platformio. Ini file for automatic installation, also can be downloaded manually add;
  • Implementation of 4 virtual functions in ‘imu_interface.h’;

2.4 lib/kinematics

c++ package for solving the car chassis forward and inverse kinematics library. Suitable for two-round difference, Ackermann, wheat wheel, etc. The library of the original address: [kinematics] (https://github.com/linorobot/linorobot2_hardware/tree/galactic/firmware/lib/kinematics) Car wheel base, wheel diameter, speed and other information are defined in ‘lib/config’;

  • Core function 1: Calculate the wheel speed of the car from the linear speed and angular speed

```c++ rpm getRPM(float linear_x, float linear_y, float angular_z); `

  • Core function 2: linear speed and angular speed are calculated from the wheel speed of the trolley

```c++ velocities getVelocities(int rpm1, int rpm2, int rpm3, int rpm4); `

2.5 lib/motor

‘motor_interface.h’ abstracts the various functions of the motor, such as forward rotation, reverse, stop, etc. ‘motor.h’ inherits’ motor_interface ‘and implements its various functions, and adds’ pwm_offset’; ‘pwm_offset’ is to solve the problem that some motors do not rotate under low duty ratio pwm drive;

2.6 lib/odemetry

The odometer ‘nav_msgs/msg/odometry’ is defined to publish the ‘odometry message’;

  • Core function 1: Gets the current odometry message data

```c++ nav_msgs__msg__Odometry Odometry::getData() { return odom_msg_; } `

  • Core function 2: passes the speed information and updates the odometry message data

```c++ void update(float vel_dt, float linear_vel_x, float linear_vel_y, float angular_vel_z); `

2.7 lib/pid

As the name suggests, the PID control of the motor, not much to explain, look at the code ~ 2.8 lib/micro_ros_arduino Based on the official micro_ros_arduino#v2.0.5foxy, necessary modifications are made to it, and rebuild is carried out:

2.9 src/main.cpp

  • Initialize encoders, pid controls, motors, etc
  • Create 2 publishers: odom and imu
  • Create one subscriber: cmd_vel
  • Create 3 software timers: 2 for publisher release; 1 for controlling the movement of the robot;

3 ROS2 feature pack

  • robot_description: indicates the robot description file
  • robot_bringup: starts the launch file, including lidar and micro_ros_agent
  • robot_cartographer: indicates that cartographer creates maps

4 Follow-up

  • Add camera to try more gameplay; There are a lot of interesting algorithms in the TROS of the x3 faction of the Rising Sun;
  • Will update from time to time