Troubles with loginfo on Arduino
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