Skip to content

Commit

Permalink
test: update.
Browse files Browse the repository at this point in the history
  • Loading branch information
codyps committed Feb 10, 2011
1 parent a3e40af commit 558e9b3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
5 changes: 4 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,17 @@ ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)

# Default target.
all: build
all: ros build

rebuild: | clean build

# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib

ros:
rosrun avr_bridge gen_avr.py call_response.yaml .


elf: $(TARGET).elf
hex: $(TARGET).hex
Expand Down
8 changes: 8 additions & 0 deletions test/call_response.yaml
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
58 changes: 54 additions & 4 deletions test/main.cpp
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 */
}
}

0 comments on commit 558e9b3

Please sign in to comment.