Ask Your Question
1

Troubles with loginfo on Arduino

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

mattMGN gravatar image

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

Hello,

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;

//Def
std_msgs::Float32 float_msg;
std_msgs::Float32 float_msg_compas;

//Pub/sub
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() {     
  nh.getHardware()->setBaud(115200);
  nh.initNode();
  nh.advertise(pu);
  nh.advertise(compas);
  nh.subscribe(su);

  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;
  float_msg.data = voltageValue;
  pu.publish(  &float_msg );
  if (voltageValue<3.6) {nh.loginfo("Low Voltage");}  // THIS ONE NOT IS WORKING
  delay(10);
}

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 ?

Regards

Matthieu

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

eugene.katsevman gravatar image

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

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

http://playground.arduino.cc/Code/Ava...

edit flag offensive delete link more

Comments

I will check that ! Thank you

mattMGN gravatar imagemattMGN ( 2017-04-18 08:19:37 -0500 )edit

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-13 09:48:52 -0500

Seen: 381 times

Last updated: Apr 14 '17