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

Troubles with loginfo on Arduino

asked 2017-04-13 09:48:52 -0600

mattMGN gravatar image

updated 2017-04-13 09:50:05 -0600


I am working with a Raspberry Pi and an Arduino on ROS indigo. I would want to add a loginfo message to my script. However, each time I add this line : if (voltageValue<3.6) {nh.loginfo("Low Voltage");}, my rosserial node displays the following message and then stops to work :

[INFO] [WallTime: 1492093431.082536] Setup publisher on cell_voltage [std_msgs/Float32]
[INFO] [WallTime: 1492093431.087959] wrong checksum for topic id and msg
[WARN] [WallTime: 1492093431.112029] Serial Port read returned short (expected 78 bytes, received 73 instead).
[WARN] [WallTime: 1492093431.116379] Serial Port read failure: 
[INFO] [WallTime: 1492093431.119876] Packet Failed :  Failed to read msg data
[INFO] [WallTime: 1492093431.122835] msg len is 8
[INFO] [WallTime: 1492093431.147052] Setup publisher on cell_voltage [std_msgs/Float32]
[INFO] [WallTime: 1492093431.155512] wrong checksum for topic id and msg
[INFO] [WallTime: 1492093431.172463] Setup publisher on cell_voltage [std_msgs/Float32]
[INFO] [WallTime: 1492093431.179750] wrong checksum for topic id and msg
[INFO] [WallTime: 1492093431.200429] wrong checksum for topic id and msg
[ERROR] [WallTime: 1492093446.191686] Lost sync with device, restarting...

My Arduino script is

#include <Timer.h>
#include <ros.h>
#include <std_msgs/Float32.h>
#include <geometry_msgs/Twist.h>

// voltage sensor
int sensorPin = A1;
int sensorValue = 0;
float voltageValue = 0;

Timer _timer_2(500),  //2Hz
       _timer_100(10); //100Hz

unsigned long temps = 0;

ros::NodeHandle nh;

std_msgs::Float32 float_msg;
std_msgs::Float32 float_msg_compas;

ros::Publisher pu("cell_voltage", &float_msg);
ros::Publisher compas("compas", &float_msg_compas);
ros::Subscriber<geometry_msgs::Twist> su("cmd_vel" , messageCb);

void setup() {     

  temps = millis();
  _timer_2.start((unsigned long) millis());
  _timer_100.start((unsigned long) millis());

void messageCb( const geometry_msgs::Twist& vel)
  float xx = vel.linear.x;
  float zz = vel.angular.z;

  if (xx>0.08){ nh.loginfo("AVANCE"); // THIS ONE IS WORKING

void voltageCb(){
  sensorValue = analogRead(sensorPin);
  voltageValue = sensorValue * 5.0 /1023.0; = voltageValue;
  pu.publish(  &float_msg );
  if (voltageValue<3.6) {nh.loginfo("Low Voltage");}  // THIS ONE NOT IS WORKING

void loop() {
  if (_timer_100.delay(millis())){  nh.spinOnce();}

  if (_timer_2.delay(millis())){  voltageCb(); }

Does anybody know how to fix this problem ? I suppose the problem comes from the lack of argument in voltageCb(). But I am not sure what shall be put inside this function ?



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-14 18:14:16 -0600

eugene.katsevman gravatar image

updated 2017-04-14 18:14:50 -0600

You have to check how much of free ram is left on your arduino. If you run low on RAM, anything can happen.

edit flag offensive delete link more


I will check that ! Thank you

mattMGN gravatar image mattMGN  ( 2017-04-18 08:19:37 -0600 )edit

Question Tools

1 follower


Asked: 2017-04-13 09:48:52 -0600

Seen: 896 times

Last updated: Apr 14 '17