rosserial connection not working with custom messages! [SOLVED]
Hi community!
I've got a problem, as the title suggests, with my custom messages used in arduino.
I publish here the arduino code and explain later:
#include <pkg1/Num.h>
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
pkg1::Num type_Num;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
ros::Publisher PUB2("newmessage", &type_Num);
char hello[20]= "hello world";
int counter=0;
void setup()
{
nh.initNode();
nh.advertise(chatter);
}
void loop()
{
type_Num.first_name = "danielooow";
type_Num.last_name = "gonsaleeesss";
type_Num.score = counter;
PUB2.publish( &type_Num );
str_msg.data = hello;
chatter.publish( &str_msg );
nh.spinOnce();
counter++;
delay(100);
}
As you see, the code is only an expansion of the HelloWorld example of ros_lib.
It compiles perfectly.
Once uploaded to my Arduino UNO, I call the rosserial connection:
~/catkin_ws$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0
And i get this error:
[INFO] [WallTime: 1458399926.066204] ROS Serial Python Node
[INFO] [WallTime: 1458399926.072844] Connecting to /dev/ttyACM0 at 57600 baud
[ERROR] [WallTime: 1458399943.176784] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
The thing is, when I upload the HelloWorld example, the connection works!! and the chatter topic is properly registered in the ROS master, but when I use the new code, it doesn't .
I just don't know what's going on here.
Thoughts:
- I thought it could be a
delay
problem but removing the delay in the code hasn't made anything. - I also thought that maybe in the creation of the custom message there's a problem (something related with the CMakeLists.txt or the pakage.xml) but the message can be used in a normal non-arduino code, registering successfully in the ROS master and all that stuff, so that makes me doubt about it.
- It's maybe that i have to use a second Node Handle??
For possible answers regarding using #define USE_USBCON
-> i've already tried that and then the compiler says something about it requires the iostream
library --> i just don't think that is the way to go for solving this (maybe i'm wrong i don't know..).
Thanks to everyone in advance. I would appreciate a detailed answer.
SOLVED!!! LOOK AT THE ANSWERS!