|
| 1 | +# Micro-ROS Power and Distance Sensors Demo |
| 2 | + |
| 3 | +This demo illustrates the micro-ROS capabilities and showcases the integration of micro-ROS with ROS 2 tools. Besides, it enables the comparison of micro-ROS and ROS 2 outcomes. |
| 4 | + |
| 5 | +The use-case consists in a ROS2-controlled [Raspberry Pi 4](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/?resellerType=home) with a [TFMini](https://www.sparkfun.com/products/14588) sensor that measures the <span style="color:magenta">distance</span> to a target object and a micro-ROS-controlled [Olimex STM32-E407](https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware) board with the similar TFMini sensor, which measures the <span style="color:magenta"> distance</span> to the same object. The demo explores another micro-ROS-controlled Olimex STM32-E407 board, which measures the <span style="color:magenta">power consumption</span> of both Raspberry Pi 4 and Olimex STM32-E407 boards for distance measurements, using [INA219](https://www.antratek.com/ina-219-dc-current-sensor) sensors. The last component, a tablet display, visualizes measurement results using standard ROS 2 tools (rqt). |
| 6 | + |
| 7 | +Raspberry Pi 4 is running Linux and a ROS 2 application, while Olimex STM32-E407 boards are running NuttX and micro-ROS applications.Both of them are publishing sensor messages via UDP over Ethernet LAN sending distance and power data to the display. The tablet is running Linux, ROS 2 and a [micro-ROS agent](https://micro-ros.github.io/docs/overview/) to receive these messages. |
| 8 | + |
| 9 | +## Contens |
| 10 | +- [Demo Box diagram](#demo-box-diagram) |
| 11 | +- [Topics](#topics) |
| 12 | +- [Hardware](#hardware) |
| 13 | +- [Sensor wiring](#sensor-wiring) |
| 14 | +- [Ethernet connection](#ethernet-connection) |
| 15 | +- [How to build the micro-ROS demo system on Olimex STM32-E407](#how-to-build-the-micro-ros-demo-system-on-olimex-stm32-e407) |
| 16 | +- [How to build the ROS 2 demo system on a tablet](#how-to-build-the-ros-2-demo-system-on-a-tablet) |
| 17 | +- [How to build the ROS 2 demo system on Raspberry Pi 4](#how-to-build-the-ros-2-demo-system-on-raspberry-pi-4) |
| 18 | +- [Running the demo](#running-the-demo) |
| 19 | + |
| 20 | + |
| 21 | +## Demo Box diagram |
| 22 | + |
| 23 | + |
| 24 | +## Topics |
| 25 | +In this demo there are two different micro-ROS nodes and the ROS 2 node which publish the following topics: |
| 26 | +- /distance_oli: *distance measured by a sensor on the Olimex-E407 board*, |
| 27 | +- /power_oli: *power consumtion of the distance Olimex board*, |
| 28 | +- /power_rpi: *power consumtion of the Raspberry Pi*, |
| 29 | +- /distance_rpi: *distance measured by a sensor on the Raspberry Pi*. |
| 30 | + |
| 31 | +From these topics subscribes a ROS 2 node on the tablet. |
| 32 | + |
| 33 | +## Hardware |
| 34 | +The following is a list of the demo hardware: |
| 35 | +- 1 x Raspberry Pi 4 + Power Supply + SD Card, |
| 36 | +- 2 x Olimex STM32-E407 + Power Supply + Ethernet cable, |
| 37 | +- 2 x TFMini Micro LiDAR Module, |
| 38 | +- 2 x INA219 DC Current Sensor + shunt resistor, |
| 39 | +- 1 x NETGEAR proSafe Gigabit Switch GS105 + Power Supply, |
| 40 | +- 1 x Getac 2 Tablet + Power Supply + Ethernet cable, |
| 41 | +- 1 x PC + ST-LINK/V2 to flash firmware to Olimex boards. |
| 42 | + |
| 43 | +## Sensor wiring |
| 44 | + |
| 45 | +|TFMini | | Olimex STM-E407 | |
| 46 | +|------------:|-------------|-------------| |
| 47 | +|red| <----->|5V| |
| 48 | +|black| <----->|GND| |
| 49 | +|white| <----->|Tx3| |
| 50 | +|green| <----->|Rx3| |
| 51 | + |
| 52 | +<br> |
| 53 | + |
| 54 | +|TFMini | | RPI / Pin Number | |
| 55 | +|------------:|-------------|-------------| |
| 56 | +|red| <----->|5V/2| |
| 57 | +|black| <----->|GNGND/6| |
| 58 | +|white| <----->|Tx/8| |
| 59 | +|green| <----->|Rx/10| |
| 60 | + |
| 61 | +<br> |
| 62 | + |
| 63 | +|INA219 | | Olimex STM-E407 | |
| 64 | +|------------:|-------------|-------------| |
| 65 | +|SCL| <----->|I2C1_SCL (UEXT pin 5)| |
| 66 | +|SDA| <----->|I2C1_SDA (UEXT pin 6)| |
| 67 | + |
| 68 | +<br> |
| 69 | + |
| 70 | +|Load |INA219 Address |Shunt Resistor [ohm] | |
| 71 | +|:-----------:|:-------------:|:------------:| |
| 72 | +|RPI | A0=GND, A1=GND|0.5 | |
| 73 | +|Olimex | A0=GND, A1=Vs|1 | |
| 74 | + |
| 75 | +<br> |
| 76 | + |
| 77 | +## Ethernet connection |
| 78 | + |
| 79 | + IP addresses: |
| 80 | +``` |
| 81 | +- Tablet: 192.168.10.2 |
| 82 | +- RPI: 192.168.10.4 |
| 83 | +- Distance Olimex: 192.168.10.17 |
| 84 | +- Power Olimex: 192.168.10.18 |
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | +## How to build the micro-ROS demo system on Olimex STM32-E407 |
| 89 | +The environment for setting up the Demo Box applications will be perform within a docker: |
| 90 | +- Download the micro-ROS base Foxy image from [the Docker Hub](https://hub.docker.com/), then run a docker container |
| 91 | + |
| 92 | +``` |
| 93 | +sudo docker pull microros/base:foxy |
| 94 | +sudo docker run -it --net=host --privileged -v /dev/bus/usb:/dev/bus/usb microros/base:foxy |
| 95 | +``` |
| 96 | +- Create a ROS 2 workspace in the uros_ws folder of the docker container and build the package |
| 97 | + |
| 98 | +``` |
| 99 | +source /opt/ros/$ROS_DISTRO/setup.bash |
| 100 | +git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup |
| 101 | +apt update && rosdep update |
| 102 | +rosdep install --from-path src --ignore-src -y |
| 103 | +apt-get install python3-pip |
| 104 | +apt-get -y install python3-pip |
| 105 | +colcon build |
| 106 | +source install/local_setup.bas |
| 107 | +``` |
| 108 | +- Create the Nuttx firmware on Olimex-E407 with the Demo Box sensor applications |
| 109 | +``` |
| 110 | +ros2 run micro_ros_setup create_firmware_ws.sh nuttx olimex-stm32-e407 |
| 111 | +cd firmware/NuttX |
| 112 | +git checkout -t origin/ucs_demo_f |
| 113 | +cd ../apps |
| 114 | +git checkout -t origin/ucs_demo_f |
| 115 | +cd .. |
| 116 | +``` |
| 117 | +Build an flash the firmware: |
| 118 | +- Set the configuration profile variable to select the demo distance or demo power application |
| 119 | + |
| 120 | +``` |
| 121 | +CFG_PROFILE=demo_distance_romfs |
| 122 | +``` |
| 123 | + |
| 124 | +- Build the application |
| 125 | + |
| 126 | +``` |
| 127 | +ros2 run micro_ros_setup configure_firmware.sh $CFG_PROFILE |
| 128 | +cp firmware/NuttX/configs/olimex-stm32-e407/$CFG_PROFILE/rcS.template firmware/apps/nshlib/rcS.template |
| 129 | +cd firmware/apps/nshlib/ |
| 130 | +../../NuttX/tools/mkromfsimg.sh -nofat ../../NuttX/ |
| 131 | +cd /uros_ws/ |
| 132 | +ros2 run micro_ros_setup build_firmware.sh |
| 133 | +``` |
| 134 | +- Connect ST-Link/V2 to Olimex STM32-E407 JTAG interface and flash the firmware |
| 135 | + |
| 136 | +``` |
| 137 | +ros2 run micro_ros_setup flash_firmware.sh |
| 138 | +``` |
| 139 | + |
| 140 | +- Repeat the procedure _Build the application_ with the Olimex used for monitoring the current consumption but before, the configuration needs to be changed as follow: |
| 141 | + |
| 142 | +``` |
| 143 | +CFG_PROFILE=demo_power_romfs |
| 144 | +``` |
| 145 | + |
| 146 | + |
| 147 | +## How to build the ROS 2 demo system on a tablet |
| 148 | + |
| 149 | +Use a tablet with Ubuntu 20.04 LTS (Focal Fossa) installation: |
| 150 | +- Install the ROS 2 Desktop system |
| 151 | + |
| 152 | +``` |
| 153 | +sudo apt update && sudo apt install locales |
| 154 | +sudo locale-gen en_US en_US.UTF-8 |
| 155 | +sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 |
| 156 | +export LANG=en_US.UTF-8 |
| 157 | +sudo apt update && sudo apt install curl gnupg2 lsb-release |
| 158 | +curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - |
| 159 | +sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list' |
| 160 | +sudo apt update && sudo apt install ros-foxy-desktop |
| 161 | +source /opt/ros/foxy/setup.bash |
| 162 | +sudo apt install -y python3-pip |
| 163 | +pip3 install -U argcomplete |
| 164 | +sudo apt install python3-colcon-common-extensions |
| 165 | +``` |
| 166 | +- Install a micro_ROS agent |
| 167 | + |
| 168 | +``` |
| 169 | +mkdir ~/microros_ws && cd ~/microros_ws |
| 170 | +git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup |
| 171 | +sudo apt update && rosdep update |
| 172 | +rosdep install --from-path src --ignore-src -y |
| 173 | +colcon build |
| 174 | +source install/local_setup.bash |
| 175 | +ros2 run micro_ros_setup create_agent_ws.sh |
| 176 | +ros2 run micro_ros_setup build_agent.sh |
| 177 | +``` |
| 178 | + |
| 179 | +- Install ROS 2 Demo Box packeges |
| 180 | + |
| 181 | +``` |
| 182 | +cd ~/ |
| 183 | +git clone ssh://[email protected]:6822/amalki/demo_suitcase.git |
| 184 | +cd ~/demo_suitcase/ |
| 185 | +colcon build |
| 186 | +``` |
| 187 | + |
| 188 | +- Configure the static Ethernet address |
| 189 | + |
| 190 | +``` |
| 191 | +IPv4 address: 192.168.10.2 |
| 192 | +netmask 255.255.255.0 |
| 193 | +``` |
| 194 | + |
| 195 | +## How to build the ROS 2 demo system on Raspberry Pi 4 |
| 196 | + |
| 197 | +- [Install the Ubuntu Server 20.04 on Raspberry Pi 4](https://roboticsbackend.com/install-ubuntu-on-raspberry-pi-without-monitor/) |
| 198 | + |
| 199 | +- Power on Raspberry Pi, obtain a console using ssh and install the ROS 2 Foxy system as following |
| 200 | + |
| 201 | +``` |
| 202 | +sudo locale-gen en_US en_US.UTF-8 |
| 203 | +sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 |
| 204 | +export LANG=en_US.UTF-8 |
| 205 | +sudo apt update && sudo apt install curl gnupg2 lsb-release |
| 206 | +curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - |
| 207 | +sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list' |
| 208 | +sudo apt update |
| 209 | +sudo apt install ros-foxy-ros-base |
| 210 | +sudo apt install python3-colcon-common-extensions |
| 211 | +``` |
| 212 | + |
| 213 | +- Install ROS 2 Demo Box packages |
| 214 | + |
| 215 | +``` |
| 216 | +cd ~/ |
| 217 | +git clone ssh://[email protected]:6822/amalki/demo_suitcase.git |
| 218 | +cd ~/demo_suitcase/ |
| 219 | +colcon build |
| 220 | +``` |
| 221 | + |
| 222 | +- Configure the static eth0 address assingment in the /etc/netplan/50-cloud-init.yaml file |
| 223 | + |
| 224 | +``` |
| 225 | +network: |
| 226 | + ethernets: |
| 227 | + eth0: |
| 228 | + dhcp4: no |
| 229 | + dhcp6: no |
| 230 | + addresses: [192.168.10.4/24] |
| 231 | + gateway4: 192.168.10.1 |
| 232 | +
|
| 233 | + version: 2 |
| 234 | +``` |
| 235 | + |
| 236 | +- Switch off the serial console by adjusting the /boot/firmware/cmdline.txt file |
| 237 | + |
| 238 | +``` |
| 239 | +net.ifnames=0 dwc_otg.lpm_enable=0 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc |
| 240 | +``` |
| 241 | + |
| 242 | +- Boot the Raspberry Pi and abort the boot process through pressing a key on a serial terminal and set the bootdelay variable to -2 |
| 243 | + |
| 244 | +``` |
| 245 | +U-Boot> setenv bootdelay -2 |
| 246 | +U-Boot> saveenv |
| 247 | +``` |
| 248 | + |
| 249 | +- Put the startup_rpi.sh script into a boot up sequence to run the demo application on a Rasberry Pi start up |
| 250 | + |
| 251 | +## Running the demo |
| 252 | + |
| 253 | +Connect the devices via an Ethernet switch and power them on, then run the command on the tablet |
| 254 | + |
| 255 | +``` |
| 256 | +~/demo_suitcase/startup.sh |
| 257 | +``` |
| 258 | + |
| 259 | +After some time two rqt windows should appear with sensors data histograms. |
| 260 | + |
| 261 | + |
0 commit comments