Hi , i am trying to use a custom msg to write a publisher for an arduino code which is as follows :
#include <Messenger.h>
#include <ros.h>
#include <std_msgs/String.h>
#include <SPI.h>
#include <rosserial_arduino/Acc_righthand.h>
#include <rosserial_arduino/Acc_left.h>
double data[7];
double data2[7];
double data3[7];
int i;
double x, y, z, a, b, c, p , q ,r ;
char separator = '\t';
ros::NodeHandle nh;
std_msgs::String str_msg, X_msg, Y_msg, Z_msg;
rosserial_arduino::Acc_righthand Acc_righthand_msg;
rosserial_arduino::Acc_left Acc_left_msg;
ros::Publisher pub_Acc_righthand("Acc_righthand", &Acc_righthand_msg);
ros::Publisher pub_Acc_left("Acc_left", &Acc_left_msg);
Messenger message1 = Messenger(separator);
Messenger message2 = Messenger(separator);
Messenger message3 = Messenger(separator);
void message1Ready()
{
if ( message1.available() )
{
for(i=1;i<5;i++)
{
data[i] = message1.readDouble();
}
x = data[1];
y = data[2];
z = data[3];
Serial.print("Sensor1");
Serial.print("\t");
Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.println(z);
Acc_righthand_msg.x = x;
Acc_righthand_msg.y = y;
Acc_righthand_msg.z = z;
pub_Acc_righthand.publish(&Acc_righthand_msg);
nh.spinOnce();
//delay(50);
}
}
void message2Ready()
{
if ( message2.available() )
{
for(i=1;i<4;i++)
{
data2[i] = message2.readDouble();
}
a = data2[1];
b = data2[2];
c = data2[3];
Serial.print("Sensor2");
Serial.print("\t");
Serial.print(a);
Serial.print("\t");
Serial.print(b);
Serial.print("\t");
Serial.println(c);
Acc_left_msg.a = a;
Acc_left_msg.b = b;
Acc_left_msg.c = c;
pub_Acc_left.publish(&Acc_left_msg);
nh.spinOnce();
}
//delay(50);
}
void message3Ready()
{
if ( message3.available() )
{
for(i=1;i<5;i++)
{
data[i] = message3.readDouble();
}
p = data[1];
q = data[2];
r = data[3];
Serial.print("Sensor1");
Serial.print("\t");
Serial.print(p);
Serial.print("\t");
Serial.print(q);
Serial.print("\t");
Serial.println(r);
Acc_righthand_msg.p = p;
Acc_righthand_msg.q = q;
Acc_righthand_msg.r = r;
pub_Acc_righthand.publish(&Acc_righthand_msg);
nh.spinOnce();
//delay(50);
}
}
void setup()
{ nh.initNode();
nh.advertise(pub_Acc_righthand);
nh.advertise(pub_Acc_left);
// Initiate Serial Communication
Serial.begin(57600);
Serial1.begin(57600);
Serial2.begin(57600);
Serial3.begin(57600);
// Attach the callback function to the Messenger
message1.attach(message1Ready);
message2.attach(message2Ready);
message3.attach(message3Ready);
}
void loop()
{
// The following line is the most effective way of using Serial and Messenger's callback
while ( Serial1.available() )
{
message1.process(Serial1.read());
}
while ( Serial2.available() )
{
message2.process(Serial2.read());
}
while ( Serial3.available() )
{
message3.process(Serial3.read());
}
}
and i get the following error :
Acc_Recieverhand:15: error: cannot declare variable ‘Acc_righthand_msg’ to be of abstract type ‘rosserial_arduino::Acc_righthand’
/home/sp/arduino-1.0.1/libraries/ros_lib/rosserial_arduino/Acc_righthand.h:13: note: because the following virtual functions are pure within ‘rosserial_arduino::Acc_righthand’:
/home/sp/arduino-1.0.1/libraries/ros_lib/ros/msg.h:44: note: virtual int ros::Msg::serialize(unsigned char*) const
/home/sp/arduino-1.0.1/libraries/ros_lib/ros/msg.h:47: note: virtual const char* ros::Msg::getMD5()
Can anyone tell me what I am missing out on? I am still a beginner in arduino programming and I appreciate your help. Thanks in advance.
Regards,
Steve