yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MicroROS V2 Robot Car📖
01.Introduction
  • 0.Unboxing Video
  • 1. Readme Learning Route
  • 2. Must Read Before Use
  • 3. Introduction to MicroROS V2 Control Board
  • 4. Introduction to LiDAR
  • 5. Introduction to ESP32 Camera Module
  • 6. FAQ
  • 7. About Charging
02.Assembly course
  • Assembly Video
03.Preparation
  • 1. Quickly Start
  • 2. Write Firmware
  • 3. Install VM and Start System
  • 4. Configure VM and Connect Robot
  • 5. Connect to MicroROS Agent
04.Quick start control course
  • 1. VM Keyboard Remote Control
  • 2. VM Handle Remote Control
  • 3. USB Handle Control
05.Robot control course
  • 1. Robot Information Release
  • 2. Robot Keyboard Control
  • 3. Robot Handle Control
  • 4. Robot State Estimation
  • 5. Linear Speed Calibration
  • 6. Angular Velocity Calibration
  • 7. Robot URDF Model
06.Lidar course
  • 1. Precautions for LiDAR Mapping and Navigation
  • 2. Lidar Avoid
  • 3. Lidar Following
  • 4. Lidar Guard
  • 5. Lidar Patrol
  • 6. Gmapping Mapping
  • 7. Cartographer Mapping
  • 8. Cartographer Quickly Repositioning Navigation
  • 9. Slam Toolx Mapping
  • 10. Navigation2 Single Point Navigation
  • 11. Navigation2 Multi Point Navigation
  • 12. Ros Robot App Mapping And Navigation
07.Road network planning
  • 1. Introduction to Road Network Planning and Quick Start
  • 2. Build a Pose Map
  • 3. Road Network Annotation
  • 4. Planning and Navigation Between Road Networks
  • 5. Road Network Navigation in Any Pose
  • 6. Path Replanning
08.Vision basic course
OpenCV Image Processing
  • 1. Introduction to OpenCV Source CV
  • 2. Open Source CV Geometric Transformation
  • 3. Open Source CV Image Processing and Drawing Text Line Segments
  • 4. Open Source CV Image Beautification
09.Visual General Course (For Standard&Superior version)
4. Yolov11&26 Visual Recognition
  • 1. YOLO Environment Setup
  • 2. CLI Usage
  • 3. Object Detection
  • 4. Instance Segmentation
  • 5. Pose Estimation
  • 6. Image Classification
  • 7. Oriented Bounding Boxes Object Detection
  • 8. Model Prediction
1. ESP32 Visual Recognition Module Configuration
  • 1. Serial Port Configuration WiFi Instructions
  • 2. Use ESP32 Camera Module in Robot Car
  • 3. Servo PTZ Calibration
2. OpenCV Visual Recognition
  • 1. Human Pose Estimation
  • 2. Object Detection
  • 3. AR Vision
  • 4. QR Code
  • 5. Color Recognition
  • 6. Facial Recognition
  • 7. AprilTag Machine Code Recognition
3. Mediapipe Visual Recognition
  • 1. Hand Detection
  • 2. Pose Detection
  • 3. Holistic Detection
  • 4. Facial Detection
  • 5. Facial Recognition
  • 6. Facial Special Effects
  • 7. 3D Object Recognition
  • 8. Brush
  • 9. Gesture Recognition
  • 10. Palm Target Localization
  • 11. Fingertip Trajectory Recognition
10.Visual Advanced Course (Just for Standard version)
1. Visual Control
  • 1. QR Code Recognition Control Action
  • 2. AprilTag Control Car Action Group
  • 3. Gesture Control Car Action Group
  • 4. Visual Line Tracking
2. Visual Tracking
  • 1. Color Tracking
  • 2. Facial Tracking
  • 3. QR Code Tracking
  • 4. Object Recognition And Tracking
  • 5. Mediapipe Palm Tracking
  • 6. Mediapipe Gesture Tracking
  • 7. Mediapipe Human Pose Tracking
  • 8. KCF Object Tracking
  • 9. AprilTag Machine Code Tracking
3. Visual Following
  • 1. Color Follow
  • 2. Face Follow
  • 3. QR Code Follow
  • 4. Mediapipe Palm Follow
  • 5. Mediapipe Gesture Follow
  • 6. Mediapipe Human Posture Follow
  • 7. AprilTag Machine Code Follow
  • 8. Object Follow
11.Visual Advanced Course (Just for Superior version)
1. Visual Control
  • 1. QR Code Recognition Control Action
  • 2. AprilTag Control Car Action Group
  • 3. Gesture Control Car Action Group
  • 4. Visual Line Tracking
2. Visual Tracking
  • 1. Color Tracking
  • 2. Facial Tracking
  • 3. QR Code Tracking
  • 4. YOLO Object Recognition and Tracking
  • 5. Mediapipe Palm Tracking
  • 6. Mediapipe Gesture Tracking
  • 7. Mediapipe Human Pose Tracking
  • 8. KCF Object Tracking
  • 9. AprilTag Machine Code Tracking
3. Visual Follow
  • 1. Color Follow
  • 2. Face Follow
  • 3. QR Code Follow
  • 4. Mediapipe Palm Follow
  • 5. Mediapipe Gesture Follow
  • 6. Mediapipe Human Pose Follow
  • 7. AprilTag Machine Code Follow
  • 8. Object Follow
12.AI Large Model Basic and Applications Course
1. AI Large Model Preparation
  • 1.AI Large Model Preparation
2. AI Large Model Basic Course
  • 1. AI Large Model Types and Principles
  • 2. RAG Retrieval Augmented and Training Samples
  • 3. Embodied Intelligent System Architecture
  • 4. Embodied Intelligence Core Source Code
3. AI Large Model Development
  • 1. Register Model Service Account
  • 2. Configure API KEY
  • 3. Dify Introduction
  • 4. Dify Basic Features
  • 5. RAG Knowledge Base Deployment
  • 6. AI Application Development Chatbot
  • 7. RAG Knowledge Base and Chatbot
  • 8. AI Agent Workflow
4. AI Large Model (Text Version)
  • 1. Semantic Understanding and Instruction Following
  • 2. Multimodal Visual Understanding
  • 3. Multimodal Visual Understanding + Basic Control
  • 4. Multimodal Visual Understanding + Object Following
  • 5. Multimodal Visual Understanding + Visual Line Following
  • 6. Multimodal Visual Understanding + SLAM Navigation
  • 7. Multimodal Visual Understanding + SLAM Navigation + Visual Line Following
  • 8. Multimodal Visual Understanding + SLAM Navigation + Object Following
  • 9. Intent Inference + Multimodal Visual Understanding + SLAM Navigation
13.Openclaw Basics Course
  • 1. Openclaw Introduction
  • 2. Openclaw Core Concepts
  • 3. Openclaw Api-Key Configuration
  • 4. Openclaw Switching Models
  • 5. Openclaw System Prompt
  • 6. Openclaw Common CLI Command
14. Openclaw Interaction Course
  • 1. Openclaw Webchat Interaction
  • 2. Openclaw Tui Interaction
  • 3. Openclaw Whatsapp Interaction
15.Openclaw Development Course
  • 1. Openclaw Robot Mcp Service Integration
  • 2. Robot CLI Command Tools
  • 3. Robot-Control Plugin Tools
  • 4. Openclaw Skills Development
  • 5. Openclaw Scheduled Tasks
  • 6. Openclaw Multi Agent System
  • 7. Openclaw Proactive Interaction
  • 8. Openclaw Vector Memory
16.Openclaw Embodied Intelligence Course
  • 1. OpenClaw Natural Interaction + Basic Control
  • 2. OpenClaw Natural Interaction + Slam Navigation
  • 3. OpenClaw Natural Interaction + Multimodal Visual Understand
  • 4. OpenClaw Natural Interaction + Multimodal Visual Understand + Slam Navigation + Visual Follow
  • 5. OpenClaw Natural Interaction + Multimodal Visual Understand + Slam Navigation + Visual Track
17.Multi-machine Course
  • 1. Multi Machine Handle Control
  • 2. Multi Machine Keyboard Control
  • 3. Multi Machine Navigation
18.MicroROS-V2 Control Board Development Environment
  • 1. Set Up the ESP32-IDF Development Environment
  • 2. ESP32-IDF Configuration Tool
  • 3. ESP Flash Tool Flashing Firmware
  • 4. Install ESP32 Microros Components
  • 5. Install And Start Microros Agent
19.MicroROS-V2 Control Board ESP32 Basic Course
  • 1. Led Light Up
  • 2. Button Function
  • 3. Drive Buzzer
  • 4. Oled
  • 5. Usb Host Function
  • 6. Serial Communication
  • 7. Battery Voltage Detection
  • 8. Drive Pwm Servo
  • 9. Drive Motors
  • 10. Read Motor Encoder Data
  • 11. Pid Motor Speed Control
  • 12. Robot Kinematics Analysis Theory
  • 13. Read Imu Data
  • 14. Read Lidar Data
  • 15. Flash Data Storage
  • 16. Custom Partition Table
  • 17. Bluetooth Communication
  • 18. Wifi Connection
  • 19. ESP32 Visual Recognition Module
20.MicroROS-V2 Control Board Micro_ros Basic Course
  • 1. Publish Topics
  • 2. Subscribe To Topics
  • 3. Multi Topic Subscription And Publishing
  • 4. Subscribe To Buzzer Topic
  • 5. Subscribe To Pwm Servo Topic
  • 6. Subscribe To Speed Control Topic
  • 7. Publish Odometry Topic
  • 8. Publish Imu Data Topic
  • 9. Publish Lidar Data Topic
21. Linux System Course
  • 1.Introduction to Linux system
  • 2.Ubuntu file system
  • 3.Ubuntu common commands
  • 4.Ubuntu common editors
  • 5.Ubuntu software operation commands
  • 6.Virtual machine installation
  • 7.SSH remote control
  • 8.VNC remote control
  • 9.Transfer files remotely
  • 10.Driver library and communication
  • 11.Static IP and hotspot mode
  • 12.Bind device ID
  • 13.Capacity expansion and resource allocation
  • 14.Update system software sources
  • 15.Set root user password
  • 16.sudo free password
  • 17.Connect to WiFi network
  • 18.View system version
  • 19.Customized service management
  • 20.Back up system image
22.Docker Course
  • 1.Docker overview and docker installation
  • 2.Common commands for docker image containers
  • 3.Docker images deeply understand and publish images
23.ROS Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
Download
  • Mapping_APP(iOS_Android)
  • Code
  • Software_Tools
  • VM_System_File
  • 3D_Model_File
  • ESP32_Firmware
  • Dify LLM Base
  • Instruction_Manual
  • VMware
Download ZIP

Welcome to MicroROS V2 Robot Car repository

6. Subscribe To Speed Control Topic

Subscribing to the Speed Control Topic

1. Experiment Objective

In this experiment, you will learn how to subscribe to a speed control topic (cmd_vel) of type geometry_msgs/msg/Twist through micro-ROS and drive the motors of the MicroROS-V2 control board to implement motion control of the robot car. Through this example, you will master the receiving and parsing of the ROS2 standard motion control message, the integration of motor drivers, and the design method of a timeout automatic stop safety mechanism. This example subscribes to the /cmd_vel topic and controls the car's forward, backward, turning and in-place rotation based on linear velocity and angular velocity.

2. Experiment Principle

1. Keyword Explanation

ConceptDescription
Twist messageThe ROS2 standard motion control message type, defined in geometry_msgs/msg/Twist, containing two 3D vector fields: linear (linear velocity) and angular (angular velocity). It is the standard input interface for robot chassis control
Differential driveA kinematics model that achieves steering through the speed difference of the left and right independently driven wheels. The target linear velocity and angular velocity are decomposed into left and right wheel speeds using the formulas speed_L = Vx - Vz * d/2 and speed_R = Vx + Vz * d/2
Timeout safety mechanismWhen the micro-ROS node has not received a new cmd_vel message within a specified time (1500 ms in this example), it automatically sets the motor speed to 0 and stops motion, a safety measure that prevents the robot from running out of control due to communication interruption
micro-ROSA ROS2 client library for microcontrollers, enabling resource-constrained devices such as the ESP32 to participate in the ROS2 ecosystem. It communicates with the ROS2 Agent over Wi-Fi/UDP, implementing functions such as topic publishing, subscription and service calls
PID controlA proportional-integral-derivative control algorithm, used in motor driving to precisely control wheel speed so that the actual speed approaches the target speed. This example uses the default PID parameters (Kp=1.15, Ki=0.24, Kd=0.0)
FreeRTOS QueueThe inter-task communication mechanism provided by ESP32 FreeRTOS. This example uses a queue of length 1 to pass the latest speed command between the micro-ROS task and the motion control task, ensuring the latest control command is always executed

2. Technical Architecture

This example adopts the ESP32 → micro-ROS → Agent → ROS2 host communication chain. The control board connects via Wi-Fi to the ROS2 host running the micro-ROS Agent and subscribes to the /cmd_vel topic to obtain speed control commands.

Configuration ItemValueDescription
Node nametwist_subscriberROS2 node name
Topic namecmd_velThe subscribed ROS2 standard speed control topic
Message typegeometry_msgs/msg/TwistContains linear.x (linear velocity) and angular.z (angular velocity)
QoS modeReliable (default)Control-type messages require reliable transmission
Timeout stop1500 msAutomatically stops all motors after a timeout
Queue length1Always executes the latest speed command

In terms of software architecture, the program adopts a multi-task separation + timeout protection design:

  • micro_ros_task is responsible for ROS2 communication (subscribing to cmd_vel)

  • motion_worker_task is responsible for motor control and timeout detection (20 ms period)

  • The two are decoupled through a FreeRTOS queue and do not block each other

3. Core Topic Quick Reference

Firmware Downlink (Control Commands)

TopicMessage TypeQoSFieldRangeDirection
/cmd_velgeometry_msgs/msg/TwistReliablelinear.x (linear velocity m/s)[-1.0, 1.0]+= forward, −= backward
   angular.z (angular velocity rad/s)[-6.0, 6.0]+= turn left, −= turn right

Timeout safety: If no new cmd_vel is received within 1500 ms, the car stops automatically.

Usage Example:

# The car moves forward at 0.3 m/s
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.3}, angular: {z: 0.0}}"
# The car stops
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.0}}"

4. Middleware Configuration

micro-ROS uses a static memory model (RCUTILS_AVOID_DYNAMIC_ALLOCATION=ON), all entity memory is pre-allocated at compile time, and runtime dynamic creation is not supported.

Configuration file: ~/esp/extra_components/micro_ros_espidf_component/colcon.meta

| RMW_UXRCE_TRANSPORT | udp | UDP transport (Wi-Fi communication) | | RMW_UXRCE_MAX_PUBLISHERS | 6 | Maximum number of publishers | | RMW_UXRCE_MAX_SUBSCRIPTIONS | 6 | Maximum number of subscribers | | RMW_UXRCE_MAX_NODES | 1 | Maximum number of nodes | | RMW_UXRCE_MAX_SERVICES | 0 | Services not supported | | RMW_UXRCE_MAX_CLIENTS | 0 | Clients not supported | | RMW_UXRCE_MAX_HISTORY | 1 | History depth = 1, no message queuing | | UCLIENT_UDP_TRANSPORT_MTU | 4096 | Maximum UDP packet size 4 KB | | UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL | 1 | Agent heartbeat interval 1 ms |

Key Constraints:

  • MAX_HISTORY=1 means there is no message buffer queue, so uplink topics (firmware → host) uniformly use best_effort QoS

  • MAX_SERVICES=0, MAX_CLIENTS=0 means only topic communication is supported, not Service/Client

  • After modifying colcon.meta, the micro-ROS library must be recompiled for the changes to take effect: run idf.py clean-microros in the project directory to clean and rebuild the micro-ROS library, then idf.py build to compile the firmware

3. Experiment Steps

1. Hardware Preparation

HardwareRequirement
MicroROS-V2 control board✅ Required
USB Type-C cable✅ Required
Wi-Fi network (2.4 GHz)✅ Required
DC geared motor ×2✅ Required
Motor driver board✅ Required

2. Prerequisites

  1. The ESP32-IDF development environment has been set up

  2. The MicroROS-V2 control board is connected to the computer via USB, and the motors are correctly connected

  3. Configure the Wi-Fi SSID, password, Agent IP and port via idf.py menuconfig (the micro_ros menu item)

    xxxxxxxxxx
    cd ~/esp/microROS_samples/twist_subscriber
    source ~/esp/esp-idf/export.sh
    idf.py menuconfig

    image-20260723154206694

    1. Select example-app setting to set the domain ID to be consistent with the virtual machine

    image-20260811194850500

    After configuration, press "s" to save and press "q" to exit the configuration interface.

3. Start micro_ros_agent (Terminal 1)

Start the micro-ROS Agent on the ROS2 host:

xxxxxxxxxx
cd ~/uros_ws
source install/local_setup.bash
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8090 -v4

4. Build and Flash (Terminal 2)

​x

cd ~/esp/microROS_samples/twist_subscriber
source ~/esp/esp-idf/export.sh
idf.py build flash monitor

5. How to Stop

  1. First send a stop command to ensure the car is stationary: ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.0}}" -1

  2. Press Ctrl+] in Terminal 2 to exit the serial monitor (stop firmware execution)

  3. Press Ctrl+C in Terminal 1 to stop micro_ros_agent

Safety tip: Timeout automatic stop (1500 ms) is a backup mechanism; proactively sending a stop command is the safest way.

4. Experiment Result

After the build and flash succeed, publish speed control commands on the ROS2 host:

xxxxxxxxxx
# The car moves forward at 0.3 m/s
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.3}, angular: {z: 0.0}}"

# The car rotates in place to the left at 0.5 rad/s
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.5}}"

# The car stops
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.0}}"

Motion mode comparison table:

linear.xangular.zMotion effect
> 00Forward
< 00Backward
0> 0Rotate left in place
0< 0Rotate right in place
> 0> 0Forward + turn left (arc motion)
> 0< 0Forward + turn right (arc motion)

The control board serial port will output:

xxxxxxxxxx
I (xxx) MAIN: Agent reachable: 192.168.x.x:8888
I (xxx) MAIN: micro-ROS cmd_vel subscriber init done
I (xxx) MAIN: cmd_vel: vx=0.300, wz=0.000

When no command is sent for more than 1.5 seconds:

xxxxxxxxxx
W (xxx) MAIN: cmd_vel timeout: 1500 ms
W (xxx) MAIN: cmd_vel timeout , stop motion

5. Program Analysis

Source code paths:

  • Firmware source code: ~/esp/microROS_samples/twist_subscriber/main/main.c

  • Motion control: ~/esp/microROS_samples/twist_subscriber/components/car_motion/car_motion.h, car_motion.c

  • Motor driver: ~/esp/microROS_samples/twist_subscriber/components/motor/motor.h, motor.c

1. Main Program Logic

main/main.c adopts a multi-task separation + timeout protection design:

  1. In app_main():

    • Calls Motor_Init() to initialize the motor driver

    • Creates the FreeRTOS queue s_motion_queue (length 1, always keeps the latest command)

    • Creates the motion_worker_task task, which is responsible for motor control and timeout detection

    • Initializes the Wi-Fi network

    • Creates the micro_ros_task task

  2. In micro_ros_task:

    • Creates the node twist_subscriber

    • Subscribes to the topic cmd_vel in Reliable mode, with message type geometry_msgs/msg/Twist

    • The subscription callback twist_callback forwards the speed command to the execution task through the queue

  3. In motion_worker_task:

    • Checks for a new command every 20 ms

    • Calls Motion_Ctrl() to execute motion control

    • Continuously monitors command freshness: if no new command is received within 1500 ms, it stops the car automatically

2. Key Components

components/car_motion/car_motion.h — Motion control interface:

Parameter definition file: ~/esp/microROS_samples/twist_subscriber/components/car_motion/car_motion.h

ParameterValueDescription
ROBOT_WIDTH0.1714 mDistance between the centers of the left and right wheels
ROBOT_HALF_WIDTH0.0857 mHalf width, used for differential calculation
ROBOT_MAX_LINEAR_SPEED1.0 m/sMaximum linear velocity
ROBOT_MAX_ANGULAR_SPEED6.0 rad/sMaximum angular velocity
ROBOT_TURN_RADIUS0.30 mTurning radius
ROBOT_SPIN_MAX_WZ3.0 rad/sMaximum in-place rotation angular velocity

components/car_motion/car_motion.c — Core motion control functions:

FunctionDescription
Motion_Ctrl(float V_x, float V_y, float V_z)Controls car motion: Vx is linear velocity [-1.0, 1.0] m/s, Vy is invalid, Vz is angular velocity [-5.0, 5.0] rad/s
Motion_Stop(uint8_t brake)Stops the car (optionally coasting or braking)
Motion_Ctrl_State(uint8_t state, float speed)Controls by motion state (forward/backward/turn left/turn right/rotate in place/brake)
Motion_Get_Speed(car_motion_t* car)Gets the current actual speed

Differential kinematics model Motion_Ctrl:

Source file: ~/esp/microROS_samples/twist_subscriber/components/car_motion/car_motion.c

xxxxxxxxxx
void Motion_Ctrl(float V_x, float V_y, float V_z)
{
    line_v = limit_linear_speed(V_x);
    angular_v = limit_angular_speed(V_z);

    // Differential decomposition: left wheel speed = Vx - Vz × half width
    speed_L_setup = line_v - angular_v * ROBOT_HALF_WIDTH;
    // Right wheel speed = Vx + Vz × half width
    speed_R_setup = line_v + angular_v * ROBOT_HALF_WIDTH;

    Motor_Set_Speed(speed_L_setup, speed_R_setup);
}

The timeout automatic stop mechanism of motion_worker_task:

Source file: ~/esp/microROS_samples/twist_subscriber/main/main.c

xxxxxxxxxx
#define CMD_VEL_TIMEOUT_MS         1500

static void motion_worker_task(void *arg)
{
    (void)arg;

    motion_cmd_t cmd = {0};
    int64_t last_cmd_us = 0;
    bool stopped_by_timeout = false;

    while (1) {
        /* Check every 20 ms whether there is a new command */
        if (xQueueReceive(s_motion_queue, &cmd, pdMS_TO_TICKS(20)) == pdTRUE) {
            last_cmd_us = cmd.stamp_us;
            stopped_by_timeout = false;

            Motion_Ctrl(cmd.linear_x, 0.0f, cmd.angular_z);

            ESP_LOGI(TAG, "cmd_vel: vx=%.3f, wz=%.3f",
                     (double)cmd.linear_x, (double)cmd.angular_z);
        }

        /* Timeout automatic stop to prevent the car from continuing to move after the host disconnects */
        if (!stopped_by_timeout && last_cmd_us > 0) {
            int64_t now_us = esp_timer_get_time();
            if ((now_us - last_cmd_us) > ((int64_t)CMD_VEL_TIMEOUT_MS * 1000)) {
                int64_t timeout_ms = (now_us - last_cmd_us) / 1000;
                ESP_LOGW(TAG, "cmd_vel timeout: %lld ms", timeout_ms);
                Motion_Ctrl(0.0f, 0.0f, 0.0f);
                stopped_by_timeout = true;
                ESP_LOGW(TAG, "cmd_vel timeout , stop motion");
            }
        }
    }
}

twist_callback subscription callback:

Source file: ~/esp/microROS_samples/twist_subscriber/main/main.c

xxxxxxxxxx
static void twist_callback(const void *msgin)
{
    if (msgin == NULL || s_motion_queue == NULL) {
        return;
    }

    const geometry_msgs__msg__Twist *msg =
        (const geometry_msgs__msg__Twist *)msgin;

    motion_cmd_t cmd = {
        .linear_x = (float)msg->linear.x,
        .angular_z = (float)msg->angular.z,
        .stamp_us = esp_timer_get_time(),
    };

    /* Queue length is 1, always overwrites with the latest command */
    (void)xQueueOverwrite(s_motion_queue, &cmd);
}

components/motor/motor.h — Key parameters of the motor driver interface:

Parameter definition file: ~/esp/microROS_samples/twist_subscriber/components/motor/motor.h

ParameterValueDescription
WHEEL_DIAMETER67.5 mmWheel diameter
MOTOR_ENCODER_CIRCLE1320Encoder pulses per revolution
MOTOR_PID_PERIOD10 msPID control period
MOTOR_MAX_SPEED1.0 m/sMaximum speed
MOTOR_PID_DEFAULT_KP1.15Default proportional gain
MOTOR_PID_DEFAULT_KI0.24Default integral gain
MOTOR_PID_DEFAULT_KD0.0Default derivative gain

6. Common Problems

ProblemCauseSolution
The car does not moveThe motor driver is not initialized or the power supply is insufficientCheck the motor power connections and confirm the battery has sufficient charge
Linear or angular velocity is limitedExceeding the maximum limit is clampedConfirm the linear velocity does not exceed 1.0 m/s and the angular velocity does not exceed 6.0 rad/s
The car stops automatically after commands stop being sentThe timeout automatic stop mechanism is triggeredThis is a safety protection mechanism; cmd_vel must be sent continuously at a frequency of at least 1 Hz
The actual speed of the car does not match the commandPID parameters are not tunedAdjust the PID parameters with Motor_Update_PID_Parm()
Incorrect motion directionThe motor wiring sequence is reversedAdjust the motor wiring order or modify the MOTOR_ENCODER_SIGN_M1/M2 signs

Safety tip: The timeout automatic stop mechanism (1500 ms) ensures that the car can stop automatically when the host disconnects or the program malfunctions. This is a necessary safety design for mobile robot control. Please stay alert during testing and be ready to cut off power manually at any time.

Subscribe To Pwm Servo Topic
Publish Odometry Topic

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文