Example of a Publisher Subscriber ROSSerial node for Mbed enabled boards using String messages.

Dependencies:   mbed ros_lib_kinetic

Dependents:   roscar_ver_20190501_anglechange_copy

main.cpp

Committer:
FernandoLG
Date:
2018-08-24
Revision:
2:8b3e4bfa29e5
Parent:
1:fb8f963047b0
Child:
3:6690a73cf982

File content as of revision 2:8b3e4bfa29e5:

/*
 * rosserial Subscriber Example
 * Blinks an LED on callback
 */
#include "mbed.h"
#include <ros.h>
#include <std_msgs/Char.h>

ros::NodeHandle nh;
DigitalOut myled(LED1);

std_msgs::Char commandRead;
ros::Publisher chatter("chatter", &commandRead);

// /*
void handlerFunction(const std_msgs::Char& commandSend){
    commandRead = commandSend;
}
// */

ros::Subscriber<std_msgs::> sub("cmd_vel", &handlerFunction);

int main() {
    nh.initNode();
    nh.subscribe(sub);
    nh.advertise(chatter);
    
    commandRead.data= 'X';

    while (1) {
        chatter.publish( &commandRead);
        nh.spinOnce();
        wait_ms(10);
    }
}