I am new to ROS...and trying to create a simple random number generator, which will publish the randomly generated values. For this I created a Position class :
include "stdlib.h"
namespace RandomPositionGenerator {
class Position {
private:
double x;
double y;
double z;
public:
Position();
void setPosition();
void getPosition(double &a, double &b, double &c);
};
Position::Position(){}
void Position::setPosition() {
x = rand();
y = rand();
z = rand();
}
void Position::getPosition(double &a, double &b, double &c) {
a=x;
b=y;
c=z;
}
}
and used this class to create my publisher :
include "ros/ros.h"
include "std_msgs/String.h"
include "sstream"
include "Position.cpp"
/**
* This method generates position coordinates at random.
**/
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher position_pub = n.advertise<RandomPositionGenerator:: Position> ("position", 50);
ros::Rate loop_rate(10);
double pos_x=0;
double pos_y=0;
double pos_z=0;
while (ros::ok())
{
RandomPositionGenerator:: Position pos;
pos.setPosition();
pos.getPosition(pos_x,pos_y,pos_z);
ROS_INFO("The co-ordinates are : x=",pos_x);
position_pub.publish(pos);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
And now I get the following errors:
- ‘__s_getDataType’ is not a member of ‘RandomPositionGenerator::Position’
- ‘__s_getMD5Sum’ is not a member of ‘RandomPositionGenerator::Position’
- ‘const class RandomPositionGenerator::Position’ has no member named ‘__getDataType’
and some more similar errors...Please correct me...I am not sure where am I going wrong, or if there is anything that I did right in this small bit of code !