0
$\begingroup$

Rosanswers logo

Hi! I have a very simple problem, but I just cannot understand how to solve it. I need to transfer three coordinates between two nodes. One node is talker, which defines the coordinates and send it to other node, which is listener. Listener waits for the coordinates, make some operations with them and send it to navigation stack, which operates the robot in stage. I have read the tutorial about simple publisher and subscriber, but there the string is used and I just do not know, how to change it to float without problems. I tried to use ros services, but they do not create a topic, while working, also I was unable to make it normal working too. It seems to me, that after receiving the message, the program stuck in a callback sub-program and the main part of the program just cannot receive the data. I can be mistaken, as my knowledge in programming is too small. Below is the code of my node that I want to make the listener. Now I enter the coordinates when the node is started, but it is not convenient. I just want to know what I should add (and where) to make this none subscribed to some topic (for example "coordinates"), and being able to receive X, Y and Theta coordinates. The part of publisher node also would be useful for me. I would like to understand the principle. Help me please!

 #include "ros/ros.h"
 #include "move_base_msgs/MoveBaseAction.h"
 #include "actionlib/client/simple_action_client.h"
 #include "tf/transform_datatypes.h"

typedef actionlib::SimpleActionClient MoveBaseClient;

using namespace std;

int main(int argc, char** argv) {

    if (argc 


Originally posted by Dio Eraclea on ROS Answers with karma: 23 on 2015-04-21

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi, I think the easiest way to do it in your case would be to send either Point, or Vector3
You can send it using:
On the talker part:

ros::Publisher vector_pub = n.advertise<geometry_msgs::Vector3>("coordinates", 1);
geometry_msgs::Vector3 vectSend;
vectSend.x = coordinates.x;
vectSend.y = coordinates.y;
vectSend.z = coordinates.theta;
vector_pub.publish(vectSend);



On the listener part:

ros::Subscriber vector_sub = n.subscribe("coordinates", 1, coordinatesCb);
void coordinatesCb(const geometry_msgs::Vector3::ConstPtr& msg){
    float goal_x, goal_y, goal_z;
    goal_x = msg->x;
    goal_y = msg->y;
    goal_z = msg->z;
    // do whatever you want with it and send to move_base

Originally posted by marguedas with karma: 3606 on 2015-04-21

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Dio Eraclea on 2015-04-23:
Thanks! That worked!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.