Home Connect IR Sensor to ROS2
Post
Cancel

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

Steps:

  1. Wire IR sensor using this diagram

  2. On the arduino IDE, upload File > Examples > Firmata > StandardFirmata to the Arduino Uno board (following this tutorial)

  3. Get device location from the lower right part of Arduino IDE, for me it was /dev/ttyACM0

  4. Install pyfirmata
    1
    2
    3
    
    sudo apt install python3-pip
    python3 -m pip install pyfirmata
    python3
    
  5. Modify device location in the script ir_sensor_pyfirmata.py.

  6. Test if the range readings are read by pyfirmata by running the script.

  7. Test message publishing and subscribing using this tutorial and replacing the publisher and subscriber functions with the scripts in this repo.
    • publisher_member_function.py
    • subscriber_member_function.py

Bonus:

1
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

This post is licensed under CC BY 4.0 by the author.