While I wait for parts (extra L293D chips) to improve the current usage on my dfrobot, I thought I would play around with using ROS and the Arduino. ROS provides several tools, mostly on the host side, that will improve visualization of data coming off the robot. Also has some other handy features for messaging so I will not have to do as much serial string parsing. The main web site for ROS is http://www.ros.org/wiki/. I started out following the installation instructions located at http://www.ros.org/wiki/ROS/Installation. Since I already use macports, the specific instructions I followed are at http://www.ros.org/wiki/electric/Installation/OSX/Macports.
The instructions were straight forward so I will not repeat them here. As usual, whenever I update macports it is a several hour process where lots of out of date things are downloaded and installed. I did have one slight problem in one of the steps. The command:
Returned an error about tar returning an incorrect version:
rosinstall ~/ros "http://packages.ros.org/cgi-bin/gen_rosinstall.py?rosdistro=electric&variant=desktop-full&overlay=no"
ERROR in config: Unable to create vcs client of type tar for ~/ros: "tar --version returned invalid string: 'bsdtar 2.8.3 - libarchive 2.8.3'"I was able to fix this by changing the link as to which tar was used:
Then, the rosinstall command hung. For some reason, I had a version of rosinstall in /usr/local/bin. I am not sure how it got there. I used the full path to rosinstall to make sure that it was pulling in the right version. Something to be aware of in the future:
- $ sudo rm /usr/bin/tar
- $ sudo ln -fsv /usr/bin/gnutar /usr/bin/tar
- /opt/local/bin/rosinstall ~/ros "http://packages.ros.org/cgi-bin/gen_rosinstall.py?rosdistro=electric&variant=desktop-full&overlay=no"
Several macports project dependencies were needed. A few times I needed to kill the python install and then run the sudo maports install manually. Apparently ros wants gnu tar and macports wants bsdtar. There must be an easier way around what I did. Then restarted the install script. When that was finished, I proceeded to test the installation. First thing I needed to do was add my machine name to /etc/hosts (which now has the line below for my machine name, yoshi, which is now an alias for localhost):
- 127.0.0.1 localhost yoshi
I was then able to run a few simple commands to start an ROS session:
which let me use the mouse keys to drive a turtle around in a window (see below).
- roscore > /dev/null &
- rosmake turtlesim
- rosrun turtlesim turtlesim_node &
- rosrun turtlesim turtle_teleop_key
Once ROS was installed, I looked into how to get ROS and the Arduino to communicate. Turns out there is a package called rosserial that is used to send messages back and forth, see the link http://www.ros.org/wiki/rosserial. First I installed the packages:
- cd ~/ros
- source setup.bash
- hg clone https://kforge.ros.org/rosserial/hg rosserial
- export ROS_PACKAGE_PATH=~/ros/rosserial:$ROS_PACKAGE_PATH
Note this last step was not provided anywhere and took me a while to figure out. If you do not add the package to the ROS_PACKAGE_PATH then none of the ros commands will work. Next I needed to build rosserial. I do not usually compile aurduino code using macports (I use the Arduino.app) so I needed to install that first:
- cd ~/ros
- sudo port install avr-gcc
- rosmake rosserial_arduino
- rospack profile
- roscd rosserial_arduino/libraries
- cp -R ros_lib /Applications/Arduino.app/Contents/Resources/Java/libraries
- #include <ros.h>
- #include <rosserial_arduino/Adc.h>
- rosserial_arduino::Adc adc_msg;
- ros::NodeHandle nh;
- ros::Publisher p("adc", &adc_msg);
- void setup()
- {
- pinMode(13, OUTPUT);
- nh.initNode();
- nh.advertise(p);
- }
- void loop()
- {
- adc_msg.adc0 = analogRead(0);
- adc_msg.adc1 = analogRead(1);
- adc_msg.adc2 = analogRead(2);
- adc_msg.adc3 = analogRead(3);
- adc_msg.adc4 = analogRead(4);
- adc_msg.adc5 = analogRead(5);
- p.publish(&adc_msg);
- nh.spinOnce();
- }
Then I fired up a few ros commands (note the second command was needed to make sure the python serial interface was installed):
- roscore &
- sudo port install py26-serial
- sudo port install py26-matplotlib
- sudo port install py26-wxpython
- rosmake rxtools --rosdep-install
- rosrun rosserial_python serial_node.py /dev/cu.usbmodem621 &
- rostopic list
- rxplot adc/adc0
Note that step #4 was simply to make sure the topics was being generated properly. These steps produced the plot shown below.
Turned out setting up ros to work with the Arduino was quite a bit of work. I think it will be worth it down the road though as it opens up a wide range of tools that can be used.
Good Luck!
No comments:
Post a Comment