carbase

Dependencies:   mbed mbed-rtos ros_lib_melodic

Committer:
Gary Servin
Date:
Fri Nov 08 14:46:24 2019 -0300
Revision:
0:f48f597ef690
Child:
3:a1a69ae50c18
Initial commit for Melodic Morenia

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gary Servin 0:f48f597ef690 1 /*
Gary Servin 0:f48f597ef690 2 * rosserial Subscriber Example
Gary Servin 0:f48f597ef690 3 * Blinks an LED on callback
Gary Servin 0:f48f597ef690 4 */
Gary Servin 0:f48f597ef690 5 #include "mbed.h"
Gary Servin 0:f48f597ef690 6 #include <ros.h>
Gary Servin 0:f48f597ef690 7 #include <std_msgs/Empty.h>
Gary Servin 0:f48f597ef690 8
Gary Servin 0:f48f597ef690 9 ros::NodeHandle nh;
Gary Servin 0:f48f597ef690 10 DigitalOut myled(LED1);
Gary Servin 0:f48f597ef690 11
Gary Servin 0:f48f597ef690 12 void messageCb(const std_msgs::Empty& toggle_msg){
Gary Servin 0:f48f597ef690 13 myled = !myled; // blink the led
Gary Servin 0:f48f597ef690 14 }
Gary Servin 0:f48f597ef690 15
Gary Servin 0:f48f597ef690 16 ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb);
Gary Servin 0:f48f597ef690 17
Gary Servin 0:f48f597ef690 18 int main() {
Gary Servin 0:f48f597ef690 19 nh.initNode();
Gary Servin 0:f48f597ef690 20 nh.subscribe(sub);
Gary Servin 0:f48f597ef690 21
Gary Servin 0:f48f597ef690 22 while (1) {
Gary Servin 0:f48f597ef690 23 nh.spinOnce();
Gary Servin 0:f48f597ef690 24 wait_ms(1);
Gary Servin 0:f48f597ef690 25 }
Gary Servin 0:f48f597ef690 26 }