working with Markers
The solution of my problem is beneath.
Hi guys,
before I posted this question, I did this tutorial about markers: http://wiki.ros.org/rviz/Tutorials/Ma... (Thank you for this tutorial!)
It worked pretty well! I understood how to change the value of the coordinates x,y, and z and how to publish points. Publishing points is no problem anymore.
Now, I would like to program a "listener", which receives exactly these points and print them out.
Unfortunately, I "only" found this tutorial: http://wiki.ros.org/ROS/Tutorials/Wri...
Therefore, I began with writing this "listener":
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Int8.h"
#include <algorithm>
#include <iostream>
#include <string>
#include <unistd.h>
#include <termios.h>
#include <cmath>
#include <visualization_msgs/Marker.h>
void chatterCallback(const visualization_msgs::Marker::ConstPtr& msg)
{
std::cout << "I received: " << msg->p.x << std::endl;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("visualization_marker", 1000, chatterCallback);
ros::spin();
return 0;
}
Unfortunately, it didn't work out at all.
Can someone please help me solving the problem?
I would like to know how I can receive the coordinates and work with them. For instance:
sum = x+y+z;
ROS_INFO("The sum of a point with the coordinates x: [%d], y: [%d] and z: [%d] is : [%d]", p.x, p.y, p.z, sum);
With best regards Commander Data
SOLUTION:
The chatterCallback function needs to look like this:
void chatterCallback(const visualization_msgs::Marker::ConstPtr& msg)
{
for (int i = 0; i <= number_of_points; i=i+1) {
std::cout << "I received: " << msg->points[i].x << std::endl;
}
}
Moreover, I changed in points_and_lines.cpp the line 93 for (uint32_t i = 0; i < 100; ++i)
to for (int i = 0; i < 100; ++i)
.
I hope that this will help some researches in receiving points!
For everyone, who participate in finding the solution: THANK YOU A LOT!!!
With best regards, Commander Data