Coder Social home page Coder Social logo

prwtsrt / microros_esp32_diffdrive Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 31.46 MB

A ROS 2 and micro-ROS project controlling a differential drive robot with a Yahboom ESP32-S3 board, using Ubuntu 22.04 and ROS 2 Humble on an Orange Pi 5B. The ESP32 is connected via USB/UART.

CMake 28.73% C 36.70% C++ 3.75% Assembly 30.82%
differential-drive-robot esp32-idf esp32-s3 micro-ros micro-ros-esp32 robot ros2 ros2-humble serial-communication uart freertos

microros_esp32_diffdrive's Introduction

MicroROS-ESP32-Diffdrive

This is a part of ROS2 and micro-ROS project to control a differential drive robot using an Yahboom microROS control board (ESP32-S3 module). I'm using Ubuntu 22.04 and ROS2 Humble running on an orange pi 5b. The connection to ESP32 that running micro-ros is via USB/UART.

Setting up ESP-IDF Development Environment

The first few steps are taken directly from the ESP-IDF Programming Guide.

Install Prerequisites

Install related dependencies

  sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

Get ESP-IDF

Download the esp-idf-v5.1.2 version

mkdir -p ~/esp
cd ~/esp
git clone -b v5.1.2 --recursive https://github.com/espressif/esp-idf.git

Set up the Tools

Install the tools required by ESP-IDF, modifying esp32s3 to match the chip you are using.

cd ~/esp/esp-idf
./install.sh esp32s3

Set up the Environment Variables

Add the installed tools to the PATH environment variable. To make the tools usable from the command line.

source ~/esp/esp-idf/export.sh

Configure, compile and flash firmware

Now connect your ESP32 board to the computer and check under which serial port the board is visible. Navigate to your directory, set ESP32-S3 as the target, and run the project configuration utility menuconfig. You are using this menu to set up project variables.

cd ~/esp/esp-idf/examples/get-started/hello_world
idf.py set-target esp32s3
idf.py menuconfig

Build the project by running

idf.py build

If there are no errors, the build finishes by generating the firmware binary .bin files. Then, run the following command to flash the firmware onto the board.

idf.py flash

Launches the IDF Monitor application. Press Ctrl+] to exit.

idf.py monitor

Shortcut command

idf.py build flash monitor

Install ESP32-microros components

Download microros components

Download the microros component to ~/esp/Samples/extra_component.

mkdir -p ~/esp/Samples/extra_components
cd ~/esp/Samples/extra_components
git clone -b humble https://github.com/micro-ROS/micro_ros_espidf_component.git
cd micro_ros_espidf_component

Install dependencies

This component needs colcon and other Python 3 packages inside the IDF virtual environment in order to build micro-ROS packages

source ~/esp/esp-idf/export.sh
pip3 install catkin_pkg lark-parser empy colcon-common-extensions

Modify microros configuration

The default microros configuration only supports 1 node, 2 publishers, 2 subscribers, 1 service, 1 client, and 1 history record.

You can modify the colcon.meta file in the micro_ros_espidf_component directory, find the rmw_microxrcedds column, and modify these settings based on the actual requirements. For this project, I will set the publishers, subscribers, and history records to are all modified to 3, To enable communication via USB/UART, I will set the transport mode to 'custom'.

cd ~/esp/Samples/extra_components/micro_ros_espidf_component
nano colcon.meta
"rmw_microxrcedds": {
            "cmake-args": [
                "-DRMW_UXRCE_XML_BUFFER_LENGTH=400",
                "-DRMW_UXRCE_TRANSPORT=custom",
                "-DRMW_UXRCE_MAX_NODES=1",
                "-DRMW_UXRCE_MAX_PUBLISHERS=3",
                "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=3",
                "-DRMW_UXRCE_MAX_SERVICES=1",
                "-DRMW_UXRCE_MAX_CLIENTS=1",
                "-DRMW_UXRCE_MAX_HISTORY=3"
            ]
        },

If you do not modify it now and need to recompile, you can enter the following command to clear the files generated by microros compilation, and then recompile to generate a microros static library

cd ~/esp/Samples/extra_components/micro_ros_espidf_component/<your_project>
idf.py clean-microros

Install and start microros agent

Install ROS 2 Humble on your Ubuntu 22.04 LTS, as instructed here. Once you have a ROS 2 installation, follow these steps to install and start microros agent.

Install tinyxml2 dependencies

Enter the following command in the terminal to install tinyxml2.

cd ~/
git clone https://github.com/leethomason/tinyxml2.git
cd tinyxml2
mkdir build && cd build
sudo cmake ..
sudo make
sudo make install

Install python3-rosdep tool

Enter the following command in the terminal to install the rosdep tool.

sudo apt install python3-rosdep

Compile micro_ros_setup environment

Activate the ROS2 environment variable.

source /opt/ros/humble/setup.bash

Create and enter the uros_ws workspace.

mkdir ~/uros_ws && cd ~/uros_ws
mkdir src

Download the micro_ros_setup file to the src folder

git clone -b humble https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup

Initialize rosdep

sudo rosdep init

Update rosdep and install related driver packages

rosdep update && rosdep install --from-paths src --ignore-src -y

Compile workspace

colcon build

Activate micro_ros_setup environment

source install/local_setup.bash

Compile micro_ros_agent environment

ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh

Start microros agent

--dev /dev/ttyUSB0 is the serial port device number, and -b 921600 is the baud rate. Modifications can be made according to your conditions.

source /opt/ros/humble/setup.bash
source ~/uros_ws/install/local_setup.sh
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0 -b 921600 -v4

Usage

Download microros firmware

You can clone this repo directly in ~/esp/Samples/extra_component/micro_ros_espidf_component.

cd ~/esp/Samples/extra_components/micro_ros_espidf_component
git clone https://github.com/PrwTsrt/microros_esp32_diffdrive
cd microros_esp32_diffdrive

Configure, compile and flash firmware

If you encounter issues during the build or set-target process, ensure that you are running in a clean shell environment without the ROS 2 setup script sourced. Remove your build directory and retry.

source ~/esp/esp-idf/export.sh
idf.py set-target esp32s3
idf.py menuconfig

By default, micro-ROS component uses UDP transport, To enable UART transport, navigate to micro-ROS Setting -> micro-ROS network interface select then select Micro XRCE-DDS over UART.

config_2
idf.py build
idf.py flash
idf.py monitor

After startup, the serial port simulator shows garbled characters due to the incompatible default baud rate and non-character data sent by micro-ROS. Press Ctrl+] to exit. Next, start the micro-ROS agent using these commands.

source /opt/ros/humble/setup.bash
source ~/uros_ws/install/local_setup.sh
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0 -b 921600 -v4

microros_esp32_diffdrive's People

Contributors

prwtsrt avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.