Creating a ROS Node for Sparki - Part 1

A project log for Sparki SLAM

An implementation of a Simultaneous Location and Mapping algorithm for the Sparki robot to be used in middle or high school robotics classes

brnd4nbrnd4n 08/21/2014 at 04:240 Comments

I've decide to use ROS to get SLAM up and running for Sparki. I may not finish the project using ROS but it's a good way to quickly get SLAM up and running.

The first step is to create a ROS node for Sparki. My first thought was to use the rosserial library. This allows the code for node initialization and message publishing and subscribing to be run directly on Sparki's microcontroller. I started down this path and quickly realized that to expose all of Sparki's functionality to ROS, I'd need a lot of publisher and subscriber objects. This would quickly consume the flash memory (and probably the RAM too) on the micro.

Instead, I decided to create my own communication protocol that allows the Sparki to talk over serial with a ROS node written in python running externally. The protocol messages look like this: "U V 0.02 0.1 \n" (without the quotes). The first character defines the type of message. Uppercase for messages to the Sparki and lowercase from Sparki. The second letter is for an option and then the rest of the message is optional data. In this case, U means this is a command for the motors. The V option indicted that a linear velocity and angular velocity will be commanded. The data contains first the linear velocity in meter/second followed by angular in radians/second. The full protocol will be published on the project's github wiki and perhaps here as well.

I created a library called SparkiSerial that implements this protocol. It has functions to send information over serial such as accelerometer or phototransistor data as well as a function that reads in all data on the serial buffer, processes the messages, and executes the commands. I ran into another problem where, again, I exceeded the flash memory on the micro. I will be refining the library and perhaps altering the communication protocol to reduce the compile size of the library.

In the mean time, I created a slimmed-down version of the library with just enough functionality to do SLAM. I used this library to write an Arduino sketch for Sparki that can accept motor commands over serial and scan with the ultrasonic distance sensor. The sketch moves the distance sensor 5 degrees, polls the distance, and continues on, sweeping back and forth. This information is sent over serial to the ROS node.

In Part 2, I'll discuss the python side of the ROS node for Sparki.