Rosserial On Arduino Due

From JR
Jump to: navigation, search

Project notes, how to bring up Rosserial on the Arduino Due.

Update 20-Sept-2013

A similar fix has been incorporated into the official rosserial codebase; I have not tested it.

http://answers.ros.org/question/81366/ros-hydro-rosserial-arduino-due/

15-18 Aug 2013

Host environment is Ubuntu 12.04 LTS, 64-bit, running in a VirtualBox VM. (Note: I am seeing USB-serial issues on my VirtualBox guest, see here.)

sudo apt-get install build-essential dkms

Install ROS groovy-desktop-full. See http://www.ros.org/wiki/groovy/Installation/Ubuntu

sudo apt-get install python-rosinstall
sudo adduser <my-user-name> dialout

Get Arduino v1.5.2(beta) at http://arduino.cc/en/Main/Software. Earlier versions of the arduino IDE do not support the Due. Extract the zip file to ~/arduino-1.5.2 .

You may need

sudo apt-get install openjdk-7-jdk
sudo apt-get install ia32-libs

The last line, installing ia32-libs 32-bit compatibility libs for 64-bit Ubuntu, seems to be necessary in order for the gcc arm compiler to run. Without this you are likely to get a misleading "arm-none-eabi-gcc: No such file" error, despite the file being present.

Install rosserial_arduino, instructions here: http://www.ros.org/wiki/rosserial_arduino/Tutorials/Arduino%20IDE%20Setup#Installing_from_Source_onto_the_ROS_workstation

These instructions will clone a rosserial git repository into your catkin workspace. Rosserial is under continuing development, and you will get the latest version, which uses an improved "version 2" of the protocol from ros-hydra. This is fine, but it means that Arduino client code you build will be incompatible with the host-side script of the original ros-groovy distribution at /opt/ros/groovy/lib/python2.7/dist-packages/rosserial_python/SerialClient.py; I found that accidentally using the old script gave me "Failed packet flags" errors and never communicated. Use the script in your catkin workspace!

It seems that the hardware serial api has changed a bit in the Due and rosserial's ArduinoHardware.h needs to be revised. Otherwise you get

ArduinoHardware.h:68: warning: undefined reference to `HardwareSerial::begin(unsigned long)'

http://answers.ros.org/question/58053/rosserial-and-arduino-due/

This is resolved by using the UARTClass (a subclass of HardwareSerial) in src/rosserial/rosserial_arduino/src/ros_lib/ArduinoHardware.h:

[...]
#include <UARTClass.h>

class ArduinoHardware {
  public:
    ArduinoHardware(HardwareSerial* io , long baud= 57600){
      iostream = static_cast<UARTClass*>(io);
[...]
  protected:
    UARTClass* iostream;
[...]

See also [1]

The arduino ros_lib "ADC" example now compiles, uploads, and talks to serial_node.py:

chuck@rosman:~/catkin_ws$ rosrun rosserial_python serial_node.py /dev/ttyACM0
[INFO] [WallTime: 1376636591.878131] ROS Serial Python Node
[INFO] [WallTime: 1376636591.892127] Connecting to /dev/ttyACM0 at 57600 baud
[INFO] [WallTime: 1376636594.234378] Note: publish buffer size is 512 bytes
[INFO] [WallTime: 1376636594.234904] Setup publisher on adc [rosserial_arduino/Adc]

Depending on your setup, it may make the rosserial link more robust if you increase the self.port.timeout value in SerialClient.py . I am using 0.05 second instead of 0.01 second.

The "pubsub" example communicates properly, but it does not toggle the LED. This is apparently because of an Arduino Due digitalRead bug [2]. Changing the toggle callback to avoid digitalRead solves it:

bool ledOn;
void messageCb( const std_msgs::Empty& toggle_msg){
  ledOn = !ledOn;   // blink the led
  digitalWrite(13, ledOn ? HIGH : LOW);
}
Personal tools
Namespaces

Variants
Actions
Puzzle Pieces
Wiki tools
Operations plan
For staff
Toolbox