why my listener can't get the published data?
Dear friends:
I have built two nodes :main and listener.
The main nead to read (x,y,z) from a device and publish to the listener.
The main code can read the data but the listener can't get the published data now,and i even don't know whether the publish is success,how should i handle it? Thanks for you help.
The result of rosrun talker:
X=0.013095 Y=-0.0524488 Z=-0.0401042
But the listener is like this:
X: 0 Y: 0 Z: 0
The rosmsg show is: dong@dong-H61MHB:~/Project/robot_test$ rosmsg show rosfalcon/falconPos float64 X float64 Y float64 Z The source code of publisher
int main(int argc, char* argv[])
{ ros::init(argc,argv, "main");
if(init_falcon(0))
{
std::cout << "Falcon Initialised Starting ROS Node" <<std::endl;
m_falconDevice.setFalconKinematic<libnifalcon::FalconKinematicStamper>();
ros::NodeHandle node;
ros::Publisher pub = node.advertise<rosfalcon::falconPos>("falconPos",10);
while(node.ok())
{ boost::array<double, 3> Pos;
Pos = m_falconDevice.getPosition();
rosfalcon::falconPos position;
position.X = Pos[0];
position.Y = Pos[1];
position.Z = Pos[2];
pub.publish(position);
std::cout << "X="<< position.X<< " Y="<< position.Y<< "
Z="<< position.Z << std::endl;
}
m_falconDevice.close();
} return 0;
}
And the main part of listener is:
int main(int argc, char *argv[])
{
ros::init(argc, argv, "listener");
ros::NodeHandle node;
while(node.ok())
{
ros::Subscriber sub = node.subscribe("position", 10,&positionCallback);
}
ros::spin();
return 0;
}
Can you write this in a bit readable way? ROS answers have tools for quoting your code?