ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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.
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);
}