Follow the instructions in MicroRos_ArduinoDue_Setup_Guide to install and setup microros with Arduino Due. This setup is needed only once.
Open Arduino ide, compile and upload micro-ros_runservo_service.ino
in Arduino Due.
Everytime you connect arduino, it usually shows up under /dev/ttyACM0 but it can show up under some other port. We can add rule so that whatever port it shows up under is displayed as /dev/arduino:
- Connect Arduino to laptop
- ls /dev/
- udevadm info --name=/dev/ttyACM0 --attribute-walk
- In the output for arduino find:
ATTRS{idProduct}=="zzzz" ATTRS{idVendor}=="wwww"
- cd /etc/udev/rules.d
- sudo gedit 99-usb-serial.rules
- Add the following line:
SUBSYSTEM=="tty", ATTRS{idVendor}=="wwww", ATTRS{idProduct}=="zzzz", SYMLINK+="arduino"
- Load the new rule:
sudo udevadm trigger
- Check if the static name setting is done properly:
ls -l /dev/arduino
-
Power Cycle/Reconnect Arduino Due to laptop via USB.
-
Open a new terminal and run microros agent with --dev (port connected to Arduino):
# In a new terminal: cd ~/trail_ws/src/TRAILBot/Arduino ./run_microros_agent.sh
-
Test node: Open a new terminal and call
/runservo
service to see if you can operate servos:ros2 service call /runservo trailbot_interfaces/srv/RunServo '{servo: 1}' ros2 service call /runservo trailbot_interfaces/srv/RunServo '{servo: 2}' ros2 service call /runservo trailbot_interfaces/srv/RunServo '{servo: 3}' ros2 service call /runservo trailbot_interfaces/srv/RunServo '{servo: 4}'