forked from codyps/avr_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
#include <avr_ros/ros.h> | ||
#include <stdio.h> | ||
#include <avr/io.h> | ||
#include "avr_ros/ros.h" | ||
#include "avr_ros/String.h" | ||
#include "libarduino2.h" | ||
|
||
namespace ros { | ||
int fputc(char c, FILE *f) { | ||
return -1; | ||
return serial_putchar(c, f); | ||
} | ||
} | ||
|
||
__attribute__((OS_main)) | ||
int main(void) | ||
ros::Publisher resp; | ||
|
||
std_msgs::String call_msg; | ||
std_msgs::String response_msg; | ||
|
||
void toggle(void) | ||
{ | ||
static char t = 0; | ||
if (!t ) { | ||
digital_set(13, true); // set the LED on | ||
t = 1; | ||
} else { | ||
digital_set(13, false); // set the LED off | ||
t = 0; | ||
} | ||
} | ||
|
||
void response(ros::Msg const *msg) | ||
{ | ||
toggle(); | ||
|
||
/* note that this is unsafe as the result could be larger than | ||
* the space avaliable in 'data' */ | ||
sprintf(response_msg.data.getRawString(), | ||
"You sent : %s", call_msg.data.getRawString()); | ||
node.publish(resp, &response_msg); | ||
} | ||
|
||
|
||
__attribute__((OS_main)) | ||
int main(void) { | ||
serial_init(); | ||
|
||
digital_init(13, PIN_OUTPUT); | ||
resp = node.advertise("response"); | ||
node.subscribe("call",response, &call_msg); | ||
|
||
call_msg.data.setMaxLength(30); | ||
response_msg.data.setMaxLength(60); | ||
|
||
|
||
for(;;) { | ||
for(;;) { | ||
int c = serial_getc(); | ||
if (c == EOF) | ||
break; | ||
node.spin(c); | ||
} | ||
|
||
/* Do other work */ | ||
} | ||
} | ||
|