carbase

Dependencies:   mbed mbed-rtos ros_lib_melodic

Committer:
howanglam3
Date:
Tue Dec 29 07:23:51 2020 +0000
Revision:
3:a1a69ae50c18
Parent:
0:f48f597ef690
Child:
4:aa8ef06b9469
init mbed workspace

Who changed what in which revision?

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