Connect IR Sensor to ROS2
Summary
Connect IR Sensor to ROS2
Why
- Outdated documentation of how to do it - rosserial is ROS1, ros2arduino was updated 2 years ago
- Approachable python interface vs more complex frameworks - micro-ros, arduino-cli, johnny-five requires nodejs install
- No need to code in Arduino C - enabled by the Firmata protocol
Software
- ROS2 Humble
- pyFirmata
- Arduino IDE
Hardware
- Sharp IR Sensor
- Arduino UNO
Steps:
-
Wire IR sensor using this diagram
-
On the arduino IDE, upload
File > Examples > Firmata > StandardFirmatato the Arduino Uno board (following this tutorial) -
Get device location from the lower right part of Arduino IDE, for me it was
/dev/ttyACM0 - Install pyfirmata
sudo apt install python3-pip python3 -m pip install pyfirmata python3 -
Modify device location in the script
ir_sensor_pyfirmata.py. -
Test if the range readings are read by pyfirmata by running the script.
- Test message publishing and subscribing using this tutorial and replacing the publisher and subscriber functions with the scripts in this repo.
publisher_member_function.pysubscriber_member_function.py
Bonus:
- If running inside docker, connect docker container with Arduino device by adding a
--deviceflag
docker run -it --net=host --device /dev/dri/ --device /dev/ttyACM0 -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/root/.Xauthority:ro osrf/ros:humble-desktop-nav2
References
Enjoy Reading This Article?
Here are some more articles you might like to read next: