Running linorobot2_hardware on esp32-WROOM-32D using Wifi

RoboFoundry
5 min readSep 8, 2023

--

Recently, I wrote an article that described how to get some of the micro-ROS examples running on esp32-WROOM-32D board that uses Wifi transport. However, this was a very simple example publishing incrementing numbers and didnot have much practical use. However, this got me inspired to go back to one of the great ROS2 robot repos — linorobot_hardware2. I had seen a fork of this repo that supports esp32 and Pico boards so I cloned the repo and started tinkering with it to see if it will compile and run on my esp32 board. As you might expect, I ran into several issues during compiling and trying to get it to run on esp32 board using Wifi transport.

I spent several days fighting these errors and systematically troubleshooting the issues. The steps that I took to fix the original repo are described in this article and in the readme file of my fork to original repo. However, for you its really simple just clone my forked repo and follow the instructions at the end of readme file and you should be able to compile and run the linorobot2_hardware on your own esp32 board.

The main difference between the linorobot2_hardware repo and the other article I wrote is they used two different types of frameworks. The other article used ESP-IDF framework vs the linorobot2_hardware repo uses arduino framework in platformIO projects.

Here are the fixes I had to do in order to get it running using Wifi transport on my esp32 board.

Step 1. Add a new robot config file

  • Added a new robot config file at — config/custom/myrobot_config.h
  • The biggest issue I had to fix was the pin numbers for Encoder and Motor pins. Without this fix esp32 kept rebooting with errors
  • Before you compile and run the project make sure to change “WIFI_SSID” and “WIFI_PASSWORD” with correct values for your wifi network
  • Also, don’t forget to change the ip address of your laptop or computer [which will also be microROS agent IP] in myrobot_config.h file in following two places: AGENT_IP and SYSLOG_SERVER. The default is — 192, 168, 1, 100, change this to your own value.

Step 2. Fix platform.ini file added myrobot env section

  • Added myrobot env section. This new section passes correct flags e.g. for wifi transport and new myrobot config file. To keep it simple, removed all other board envs except default teensy and new myrobot env.
  • Updated reference to ESP32Servo library, this fixes issue with compile errors related to ESP32Servo with correct version of library

Step 3. Fix default_motor.h to use ESP32Servo.h instead of Servo.h

Step 4. Run following commands to compile and run the esp32 based robot using microROS

git clone https://github.com/robofoundry/linorobot2_hardware_hippo_esp32_fix.git
pio run — target upload -e myrobot
  • Before you execute above command to compile and upload the project [make sure you have given write permissions in order to upload the code to esp32. You can do this in two ways, you can execute sudo chmod 666 /dev/ttyUSB0 as described in original article or you can add a udev rules file to automatically give the permission whenever esp32 is connected via USB [see the separate section on how to do this].
  • If you have not installed docker on your laptop/desktop follow instructions here
  • To start docker based microROS agent
docker run -it — rm — net=host microros/micro-ros-agent:humble udp4 — port 8888 -v6
  • At this point you can disconnect the esp32 board USB cable from your laptop and power it with separate battery [untethered from your laptop]. And as soon as the esp32 comes up it will start broadcasting to agent running via command line above.
  • In another separate terminal you can run following ROS2 command to make sure the linorobot topics are getting published over wifi from esp32
ros2 topic list

You should be able to see following topics being broadcast by the esp32 over Wifi to your laptop/computer.

/battery
/cmd_vel
/imu/data
/imu/mag
/odom/unfiltered
/parameter_events
/rosout
/ultrasound

How to add Udev Rules file for esp32

Follow the steps below to add udev rules file so esp32 automatically gets write permission when you connect via USB.

Create a new and empty udev rules file for esp32 using touch command

cd /etc/udev/rules.d
touch 98-esp32.rules

Open and edit the newly created file

sudo nano 98-esp32.rules

Copy paste following content into the file, save and exit:

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"

You can reload the udev rules without rebooting like this:

udevadm control --reload-rules && udevadm trigger

After this if you connect esp32 via USB cable you and check the permissions, you’ll see something like this:

ls -l /dev/ttyUSB0

# you'll something like this
crw-rw-rw- 1 root dialout 188, 0 Sep 8 18:15 /dev/ttyUSB0

Using the udev rules file is a cool trick you can use for any of your robot hardware devices where you need to add permissions. This saves you the headache of running the chmod command each time you want to compile and upload the code to esp32.

Hope this article helps in getting linorobot2_hardware project up and running on your esp32. All the credit goes to wonderful repo by hippo5329 who had done all the hard work to write code to support esp32 and Pico boards.

My next step will be to now actually build a full diff drive robot using one of those cheap amazon wheeled robot kits and see if I can control it via joystick controller and later control it via nav2 stack running on the laptop.

Enjoy!! Happy building!!

References:

My fork with fixes:

original hippo5329 repo:

Reference to pinout for ESP32-WROOM-32D board

--

--