Sadly, it doesn't compile. When you solve all the minor problems and it finally compiles, it doesn't work. Please take a look at this answer: http://answers.ros.org/question/624/problems-using-avr_bridge-arduino-ros?answer=1092#1092 and download the latest code. You can then take imu_9drazor as an example of how to use it. I'll try to come back later, edit this post and provide a HelloWorld example I did yesterday (it uses a callback method, which imu_9drazor doesn't).
Ok, as promised, a simple HelloWorld
example follows. Begin with reading the avr_bridge Wiki, if you haven't yet done so. I'm also assuming you all dear readers already understand what Arduino is (as I'm using an Arduino Duemilanove here) and have Eclipse configured to work with it.
Take callResponse.yaml
from the HelloWorld
example provided in the old example project here, for completness, these are it's contents:
port: /dev/ttyUSB0
name: callResponse
publish: #list of published topics
response: #topic name
type: std_msgs/String #msg type
subscribe:
call:
type: std_msgs/String
Then run
rosrun avr_bridge gen_avr.py callResponse.yaml .
in the project's folder where you wish to use avr_bridge
(generally do as it says in the avr_bridge HelloWorld Wiki tutorial. I used the following main.cpp
(a slight modification of the one provided in the aforementioned tutorial):
#include "WProgram.h"
#include <stdio.h>
#include <String.h>
#include "avr_ros/Ros.h"
#include "avr_ros/ros_string.h"
Publisher resp;
std_msgs::String call_msg;
std_msgs::String response_msg;
extern "C" void __cxa_pure_virtual()
{
cli();
for (;;);
}
void toggle()
{
if (digitalRead(13) == LOW ) {
digitalWrite(13, HIGH); // set the LED on
} else {
digitalWrite(13, LOW); // set the LED off
}
}
void responseCallback(Msg* msg) {
toggle();
response_msg.data.setString(call_msg.data.getRawString());
ros.publish(resp, &response_msg);
}
unsigned long pubTimer=0;
void setup(){
//Set up the serial communicaton and wait a bit to make sure
//that the program and grab its id before we go into any other
//set up routines
Serial.begin(57600);
for (int i; i<100; i++) {ros.spin();delay(10);}
pinMode(13, OUTPUT);
resp = ros.advertise("response");
ros.subscribe("call", responseCallback, &call_msg);
call_msg.data.setMaxLength(30);
response_msg.data.setMaxLength(60);
pubTimer = millis();
}
void loop(){
ros.spin();
//Do other work
delay(10);
}
int main(void)
{
init();
setup();
for (;;) { loop(); }
return 0;
}
and added those to Ros.cpp
:
int ros_putchar(char c, FILE *stream)
{
Serial.write(c);
return 0;
}
int ros_getchar(FILE *stream)
{
return Serial.read();
}
That's not yet the neatest use of avr_bridge
, which I'm aware of (like I'm using a global variable in callbackResponse
), but it worked for me, which I hope it will for you as well. Consult avr_bridge HelloWorld Wiki tutorial as to how to run it then (paragraph 5 for the time of this writing).
Cheers.