Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 314

Publishing String from Terminal?

$
0
0
Is there any problem in my code? i just want, if i publish *"q"* Blue LED glow. Red for *"a"* and blink for *"z"* . i use > rostopic pub /servo std_msgs/String > "data: 'z'" command to publish topic.but nothing happening.the code running without error. my code is #include #include ros::NodeHandle nh; void pwm( const std_msgs::String& cmd_msg) { if (cmd_msg.data=="q") { digitalWrite (13, HIGH); //BLUE LED ON } else if (cmd_msg.data=="a") { digitalWrite (12, HIGH); //RED LED ON } else if (cmd_msg.data=="z") { for(int i=0;i<1000;i++) { digitalWrite (13, HIGH); //LED BLINKING delay(100); digitalWrite (13, LOW); digitalWrite (12, HIGH); delay(100); digitalWrite (12, LOW); } } } ros::Subscriber sub("servo", pwm); void setup() { pinMode(12, OUTPUT); pinMode(13, OUTPUT); nh.initNode(); nh.subscribe(sub); } void loop() { nh.spinOnce(); delay(10); }

Viewing all articles
Browse latest Browse all 314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>