Ask Your Question
0

Ros Arduino link problem

asked 2017-04-12 05:01:16 -0500

mattMGN gravatar image

Hello,

I am using this basic script on Arduino Uno to subscribe to "cmd_vel" topic and publish "cell_voltage" topic.

include 'ros.h'

include 'std_msgs/Float32.h'

include 'geometry_msgs/Twist.h'

float x; int sensorPin = A1; int sensorValue = 0; float voltageValue = 0;

ros::NodeHandle nh;

void messageCb( const geometry_msgs::Twist& vel) {

x = vel.linear.x - 1.0;

}

std_msgs::Float32 float_msg;

ros::Publisher pu("cell_voltage", &float_msg);

ros::Subscriber<geometry_msgs::twist> su("cmd_vel" , messageCb);

void setup() {

nh.getHardware()->setBaud(115200);

nh.initNode();

nh.subscribe(su);

Serial.begin(115200);

}

void loop() {

nh.spinOnce();

delay(10);

sensorValue = analogRead(sensorPin);

voltageValue = sensorValue * 5.0 /1023.0;

float_msg.data = voltageValue;

pu.publish( &float_msg ); // THIS LINE

}

When the line pu.publish( &float_msg ); is commented, everything works fine :

pi@raspberrypi:~ $ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=115200

[INFO] [WallTime: 1491989648.891986] ROS Serial Python Node

[INFO] [WallTime: 1491989648.915430] Connecting to /dev/ttyACM0 at 115200 baud

[INFO] [WallTime: 1491989652.493960] Note: subscribe buffer size is 280 bytes

[INFO] [WallTime: 1491989652.516291] Setup subscriber on cmd_vel [geometry_msgs/Twist]

But if I uncommented that line, I get this error message :

pi@raspberrypi:~ $ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=115200

[INFO] [WallTime: 1491989671.577193] ROS Serial Python Node

[INFO] [WallTime: 1491989671.604281] Connecting to /dev/ttyACM0 at 115200 baud

[ERROR] [WallTime: 1491989688.725894] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

However I am using the correct version. So I don't know why I have this message.

Any ideas ?

PS : What are the HTML tags for inserting cpp code ?

Regards

Matthieu

edit retag flag offensive close merge delete

Comments

The preformatted text button in the question editor will do block formatting for code, or you can indent each line by four spaces. ROS Answers uses a variant of markdown for post formatting, and while it also allows inline HTML, sometimes it's a bit too aggressive at trying to auto-close tags.

ahendrix gravatar image ahendrix  ( 2017-04-12 15:31:49 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-04-12 05:30:32 -0500

vmatos gravatar image

I think you forgot to advertise the topic after initlizing the node:

nh.initNode();
nh.advertise(pu);

Check tutorials: http://wiki.ros.org/rosserial_arduino...

Tip: Before trying to connect using rosserial, check if the Arduino is still running: blinking leds or something.

For formating: There's a button with zeros/ones in the top.

edit flag offensive delete link more
0

answered 2017-04-12 07:13:36 -0500

mattMGN gravatar image

You are right, I forgot the nh.advertise(pu);

Thank you for this answer !

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-04-12 05:01:16 -0500

Seen: 275 times

Last updated: Apr 12 '17