From df419ba5fd0c27cda84544e3156078ca1a8a29e3 Mon Sep 17 00:00:00 2001 From: Thomas Chou Date: Wed, 21 Feb 2024 00:41:25 -0800 Subject: [PATCH] README: esp32 wifi transport guide Signed-off-by: Thomas Chou --- README.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/README.md b/README.md index 8259ba1c..678c6f49 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,154 @@ Echo IMU data: ros2 topic echo /imu/data +## Use esp32 with micro-ROS wifi transport, OTA, syslog and Lidar UDP transport + +The WIFI capability of the esp32 can be used to build low-cost mobile robots with navigation control under ROS2. + +- remote development - develop on your desktop with powerful [PlatformIO IDE for VSCode](https://platformio.org/install/ide?install=vscode). +- remote firmware update - with ArduinoOTA. +- remote debug messages - with remote syslog. +- remote lidar server - lidar raw data is forwarded to a server to publish laser scan data. +- remote ROS2/NAV2 stack - with micro-ROS wifi transport. +- no robot computer is required - a single esp32 will serve the robot. + +In traditional robot builds, there are robot computers (such as raspberry pi, jetson nono or mini PC) running the build tools and ROS2/NAV2 navigation stack. With the WIFI capability of the esp32, the robot firmware can be developed on your laptop or desktop PC. After the firmware is written to the esp32 using USB cable, the following firmware updates can be performed remotely using ArduinoOTA. The debug messages can be read using remote syslog server. Using the WIFI transport of the micro-ROS, the navigation packages NAV2 / SLAM and visualization tool RVIZ2 can be served on your laptop or desktop PC. This is a more comfortable development environment than the more restricted robot computers. No robot computer is required on the robot now. Just an esp32 micro-controller will serve. And the cost of the robot will be a little cheaper. + +If you are new to esp32, you may check the [guide to esp32](https://randomnerdtutorials.com/getting-started-with-esp32/). + +### 1. Start the micro ros wifi transport agent + + ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 + +### 2. Enable remote syslog server - Optional + +Edit syslog server config. Add the following to the end. + + sudo nano /etc/rsyslog.conf + + # provides UDP syslog reception + module(load="imudp") + input(type="imudp" port="514") + + $template Incoming-logs,"/var/log/%HOSTNAME%/%PROGRAMNAME%.log" + *.* ?Incoming-logs + +Restart the syslog service + + sudo systemctl restart rsyslog + +### 3. Modify custom configuration + +The following is the project ini, pins wiring and custom configuration changes. The first build and upload will use USB serial port. + +Change in ../config/custom/myrobot_config.h + + #define USE_WIFI_TRANSPORT // use micro ros wifi transport + #define AGENT_IP { 192, 168, 1, 100 } // eg your desktop IP addres + #define AGENT_PORT 8888 + #define WIFI_AP_LIST {{"WIFI_SSID", "WIFI_PASSWORD"}, {NULL}} + #define USE_ARDUINO_OTA + #define USE_SYSLOG + #define SYSLOG_SERVER { 192, 168, 1, 100 } // eg your desktop IP addres + #define SYSLOG_PORT 514 + #define DEVICE_HOSTNAME "myrobot" + #define APP_NAME "hardware" + +Change ini for 1st run, upoad with serial port. + + [env:myrobot] + upload_port = /dev/ttyUSB0 + upload_protocol = esptool + board_microros_transport = wifi + +### 4. Build and upload + + pio run -e myrobot -t upload + pio device monitor -e myrobot -p -b + +The serial will print the IP of esp32 after connected to wifi. + + WIFI connected + IP address: 192.168.1.101 + +The IP address is also displayed in the micro ros wifi agent messge. + + [1686587945.807239] info | UDPv4AgentLinux.cpp | init | running... | port: 8888 + [1686587945.807411] info | Root.cpp | set_verbose_level | logger setup | verbose_level: 4 + [1686588315.310850] info | Root.cpp | create_client | create | client_key: 0x0C7BC5A9, session_id: 0x81 + [1686588315.310892] info | SessionManager.hpp | establish_session | session established | client_key: 0x0C7BC5A9, address: 192.168.1.101:47138 + [1686588315.327314] info | ProxyClient.cpp | create_participant | participant created | client_key: 0x0C7BC5A9, participant_id: 0x000(1) + [1686588315.332840] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x0C7BC5A9, topic_id: 0x000(2), participant_ + +And check the syslog. + + sudo cat /var/log/myrobot/hardware.log + + 2023-06-13T14:34:41.978640-07:00 myrobot hardware initWifis ssid SSID rssi -44 ip 192.168.1.101 + 2023-06-13T14:34:44.042429-07:00 myrobot hardware setup Ready 9344 + 2023-06-13T14:34:44.548896-07:00 myrobot hardware loop agent available 9852 + 2023-06-13T14:34:44.549019-07:00 myrobot hardware createEntities 9852 + +### 5. OTA upload - Optional + +After the esp32 connected to wifi. Read the esp32 IP address. Modify the project configuration ini with the esp32 IP address. Then esp32 can be uploaded remotely with OTA. + +Change ini for the second run to upload with OTA. + + [env:myrobot] + ; upload_port = /dev/ttyUSB0 + ; upload_protocol = esptool + upload_protocol = espota + upload_port = 192.168.1.101 <- replace with the esp32 IP address + board_microros_transport = wifi + +Upload + + Configuring upload protocol... + AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa + CURRENT: upload_protocol = espota + Uploading .pio/build/myrobot/firmware.bin + 14:34:22 [DEBUG]: Options: {'esp_ip': '192.168.1.101', 'host_ip': '0.0.0.0', 'esp_port': 3232, 'host_port': 54252, 'auth': '', 'image': '.pio/build/myrobot/firmware.bin', 'spiffs': False, 'debug': True, 'progress': True, 'timeout': 10} + 14:34:22 [INFO]: Starting on 0.0.0.0:54252 + 14:34:22 [INFO]: Upload size: 951408 + Sending invitation to 192.168.1.101 + 14:34:22 [INFO]: Waiting for device... + + Uploading: [ ] 0% + Uploading: [= ] 0% + ... + Uploading: [============================================================] 99% + Uploading: [============================================================] 100% Done... + + 14:34:33 [INFO]: Waiting for result... + 14:34:34 [INFO]: Result: OK + 14:34:34 [INFO]: Success + ========================= [SUCCESS] Took 20.84 seconds ========================= + +### 6. Setup the Lidar UDP transport - Optional + +The lidar data can be pushed to a UDP server, which will decode the data and publish laser scan message. The UDP client on the esp32 should work with most Lidar. For the server side, only LdLidar is supported. Only LD19 launch file is tested. Conenct VCC and GND to Lidar. Connect Lidar TXD wire to LIDAR_RXD pin of esp32. + +change in ../config/custom/myrobot_config.h + + #define USE_LIDAR_UDP + #define LIDAR_RXD 14 // you may use any available input pin + // #define LIDAR_PWM 15 // do not use, the PWM control loop is not implememted yet + #define LIDAR_SERIAL 1 // uart number, 1 or 2 + #define LIDAR_BAUDRATE 230400 // the Lidar serial buadrate + #define LIDAR_SERVER { 192, 168, 1, 100 } // eg your desktop IP addres + #define LIDAR_PORT 8889 // the UDP port on server + +Build and launch the UDP server + + cd ~ + mkdir -p ldlidar_ros2_ws/src + cd ldlidar_ros2_ws/src + git clone https://github.com/hippo5329/ldlidar_stl_ros2.git + cd .. + colcon build + source install/setup.bash + ros2 launch ldlidar_stl_ros2 ld19_udp_server.launch.py ## URDF Once the hardware is done, you can go back to [linorobot2](https://github.com/linorobot/linorobot2#urdf) package and start defining the robot's URDF.