0
$\begingroup$

Rosanswers logo

I want LED 13 on my Arduino Uno board to glow when I pass the number 100 as command line argument from ROS. Here is my arduino code:

#include <ros.h>
#include <Arduino.h>
#include <std_msgs/Int8.h>

ros::NodeHandle  nh;

void ledGlow(const std_msgs::Int8& val){
 
  if(val.data==100){
  digitalWrite(13, HIGH);
  }
  else{
  digitalWrite(13, LOW);
  }
}

ros::Subscriber<std_msgs::Int8> led("led/start", &ledGlow);

void setup() { 
  pinMode(13, OUTPUT);
  nh.initNode();  
  nh.subscribe(led);
}

void loop() {  
  nh.spinOnce();
  delay(10);
}

I am giving the following commands in the terminal:

  1. roscore
  2. rostopic pub led/start std_msgs/Int8 100

After giving the second command LED 13 doesn't glow, also RX led on arduino board doesn't blink.


Originally posted by Prateek on ROS Answers with karma: 1 on 2018-08-06

Post score: 0


Original comments

Comment by VictorLamoine on 2018-08-06:
Try adding serial output to your Arduino program to determine if the ledGlow callback is being called, if yes check what value is in the message

Comment by Prateek on 2018-08-07:
I tried adding Serial.println("Hello"); inside the callback function but I'm not getting any output on serial output screen. Also, when I try printing something inside the loop, I get garbage value on serial output screen. Please help! @VictorLamoine

Comment by VictorLamoine on 2018-08-07:
Make sure to adjust the baudrate of the serial terminal

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

  1. You need to start up your node by running "rosrun your_package your_node" or an equivalent roslaunch command. I assume you're doing that and that the code you quoted is not complete.

  2. If your node lives in its own namespace "my_node_ns", then it would try to subscribe to "/my_node_ns/led/start". Make sure to publish to the right topic.

  3. Debug by:

  • adding ROS_INFO("test"); or similar in your functions so you know they are being called.
  • Using rostopic list /led/start --verbose to check if your node is subscribing correctly to the topic.
  • Checking your serial ports and USB connection. It seems like a problem with your Arduino connection, not the ROS side.

Originally posted by fvd with karma: 2180 on 2018-08-07

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Prateek on 2018-08-07:
Thanks a lot :)

Comment by fvd on 2018-08-08:
Sure. Please update what the problem was when you solved it.

$\endgroup$
0
$\begingroup$

Rosanswers logo

Are you running the rosserial node as described in this tutorial http://wiki.ros.org/rosserial_arduino/Tutorials/Blink that converts the rostopic message and sends it down the serial port. Don't use serial print in your code it will interfere with that communication


Originally posted by nickw with karma: 1504 on 2018-08-07

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.