ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I was trying to suscribe "order" topic on new arduino but i was not able to do so. i have successfully published "order" topic and both of my arduino are working. I have following code on my second arduino. However i am not able to switch on LED based on the message received. I am new to ROS arduino programming. Can someone please help me to correct the code i have.

include <ros.h>

include <std_msgs bool.h="">

ros::NodeHandle nh; const int ledPin = 13; boolean state; void messageCb( const std_msgs::Bool& pushed_msg){ if (state ==true) { digitalWrite(ledPin, HIGH); delayMicroseconds(100); digitalWrite(ledPin, LOW); } } ros::Subscriber<std_msgs::bool> sub("order", &messageCb ); void setup() { pinMode(ledPin, OUTPUT); nh.initNode(); nh.subscribe(sub); } void loop() {
nh.spinOnce(); delay(1); }