ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

avr_bridge help

asked 2011-02-18 20:12:17 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I tried to run the the 'hello' example given in the tutorial. I first generated avr_ros library which i then included in the libraries folder in arduino(/usr/share/arduino).I then edited the files to make all header refference local by removing "avr-ros/" from all headers. This the final program i got

#include&nbsp;<stdio.h>
#include&nbsp;<span style="color: #006699;">"ros.h"</span> <span style="color: #7E7E7E;">//main avrRos library</span>
#include&nbsp;<span style="color: #006699;">"String.h"</span> <span style="color: #7E7E7E;">//std_msg/String library</span>

namespace&nbsp;ros&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">int</span> fputc(<span style="color: #CC6600;">char</span> c, FILE *stream) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">write</span>(c);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">return</span> 0;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

<span style="color: #7E7E7E;">//Define&nbsp;global&nbsp;message&nbsp;objects&nbsp;to&nbsp;use&nbsp;in</span>
<span style="color: #7E7E7E;">//the&nbsp;callback&nbsp;functions&nbsp;and&nbsp;throughout&nbsp;the&nbsp;program</span>
<span style="color: #7E7E7E;"><b>ros:</b></span>:Publisher resp;
<span style="color: #7E7E7E;"><b>std_msgs:</b></span>:String call_msg;
<span style="color: #7E7E7E;"><b>std_msgs:</b></span>:String response_msg;

<span style="color: #CC6600;">void</span> toggle()
{&nbsp;<span style="color: #7E7E7E;">//toggle an led to debug the program</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">static</span> <span style="color: #CC6600;">char</span> t=0;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">if</span> (!t ) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(13, <span style="color: #006699;">HIGH</span>);   <span style="color: #7E7E7E;">// set the LED on</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;=&nbsp;1;
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #CC6600;">else</span> {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(13, <span style="color: #006699;">LOW</span>);    <span style="color: #7E7E7E;">// set the LED off</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;=&nbsp;0;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

<span style="color: #CC6600;">void</span> response(Msg *msg){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toggle();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">//make sure that if you are manipulating the raw string,</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">//there is enough space in it</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">//to handle all of the data</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(response_msg.data.getRawString(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699;">"You sent : %s"</span>, call_msg.data.getRawString());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node.publish(resp ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-02-21 16:35:28 -0600

Homer Manalo gravatar image

Not sure of this one but you wrote:

node.subscribe("call",response(&call_msg));

instead of:

node.subscribe("call",response,&call_msg);
edit flag offensive delete link more
-1

answered 2011-02-24 20:40:40 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

i will try that and see. Thanks.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-02-18 20:12:17 -0600

Seen: 346 times

Last updated: Feb 24 '11