Ask Your Question
2

avr_bridge example code not working with current git version?

asked 2011-04-08 00:51:38 -0500

Hi, it seems the example code for avr_bridge does not compile with the current version in the git repo. If I clone the git repository and use the example in the "test" directory (or the downloadable example), I get generated node_handle files which have a spin() without an additional char argument, while the example code contains a spin(char). Also, I get a compile error due to Msg not being defined, because it is missing a preceding "ros::" in main.cpp. Am I doing something wrong? If not, how do I get a working example?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2011-04-08 01:31:21 -0500

tom gravatar image

updated 2011-04-08 21:46:09 -0500

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.

edit flag offensive delete link more

Comments

Thanks Tom, that helps :) What I'm still wondering about though is the missing "call_response.yaml" file that I'd have expected to be in the "imu_9drazor/src/imu_AVRdriver" directory. It'd be awesome if you could upload a example with callback and everything.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2011-04-08 01:46:12 -0500 )edit
Actually there is a imu.yaml file in the imu_9drazor/config directory and an example.yaml in avr_bridge/config.
tom gravatar image tom  ( 2011-04-08 20:14:15 -0500 )edit
Thanks again Tom, it's working now. We had some problems with running out of RAM without noticing it though before, as the example allocates 300 bytes for the buffer. After cutting that down to the 128 it works now.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2011-04-14 21:43:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-04-08 00:51:38 -0500

Seen: 8,083 times

Last updated: Apr 08 '11