Ask Your Question
0

subscriber's callback never called in c++, using morse

asked 2014-05-16 05:29:13 -0600

Ruthven gravatar image

Hi, I am running a simulation with Morse. tryin to get data from the robot with a C++ program using ROS.

The simulation is simple: a Quadrotor publishes its pose on a topic, and receives a navigation waypoint. The Morse file is:

from morse.builder import *

bee = Quadrotor()

waypoint = RotorcraftWaypoint()
bee.append(waypoint)
waypoint.add_stream('ros')

#The Quadrototor is called bee
beePose = Pose()
bee.append(beePose)
beePose.add_stream('ros', topic='/bee/pose')

#Environment
env = Environment('land-1/trees')

In the C++ program, the chatterCallback(...) is never called, while it should print the position of the Quadrorotor:

#include "ros/ros.h"
#include "geometry_msgs/Pose.h"
#include <sstream>

void chatterCallback(const geometry_msgs::Pose& msg)
{
        geometry_msgs::Point coord = msg.position;
        ROS_INFO("Current position: (%g, %g, %g)", coord.x, coord.y, coord.z);
}

int main(int argc, char **argv)
{
        ros::init(argc, argv, "plan_node");

/**
 * NodeHandle is the main access point to communications with the ROS system.
 */
        ros::NodeHandle n;

/**
 * The advertise() function is how you tell ROS that you want to
 * publish on a given topic name.
 */
        ros::Publisher motion = n.advertise<geometry_msgs::Pose>("/bee/waypoint", 1000);

        // subscribes to stream
        ros::Subscriber sub = n.subscribe("/bee/pose", 1000, chatterCallback);

        ros::spin();

        return 0;
}

While calling roswtf, I get the following error:

================================================================================
Static checks summary:

Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING ROS_HOSTNAME may be incorrect: ROS_HOSTNAME [localhost] resolves to [::1], which does not appear to be a local IP address ['127.0.0.1', 'a.b.c'].
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 1 error(s).

ERROR The following nodes should be connected but aren't:
 * /morse->/plan_node (/bee/pose)

The weird thing is that all the nodes are running on the same computer. No network connection problems... in theory.

Finally, I get the desired data when running on another terminal:

rostopic echo /bee/pose

Any advice?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-05-16 05:52:07 -0600

Ruthven gravatar image

updated 2014-05-16 05:54:26 -0600

Finally I found the answer.

Looking at morse initialization, there was the following message:

[WARN] [WallTime: 1400249615.593493] Could not process inbound connection: topic types do not match: [geometry_msgs/Pose] vs. [geometry_msgs/PoseStamped]{'topic': '/bee/pose', 'tcp_nodelay': '0', 'md5sum': 'e45d45a5a1ce597b249e23fb30fc871f', 'type': 'geometry_msgs/Pose', 'callerid': '/plan_node'}

So I changed the callback method:

void chatterCallback(const geometry_msgs::PoseStamped& msg)
{
        geometry_msgs::Point coord = msg.pose.position;
        ROS_INFO("Current position: (%g, %g, %g)", coord.x, coord.y, coord.z);
}

and don't forget to include:

#include "geometry_msgs/PoseStamped.h"
edit flag offensive delete link more

Comments

How to run this program? 1) first part should be copied in file_name.py. 2)second part in C++ then run but it gives ma 32 error in C++ and Id for kit: "Desktop" "CMakeProjectManager.DefaultCMakeTool" 10000512 in terminal

Nazeer gravatar imageNazeer ( 2015-02-10 04:05:10 -0600 )edit

Looks like a compiler error. Have you tried re/installing Catkin?

Ruthven gravatar imageRuthven ( 2015-10-05 12:02:59 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-05-16 05:29:13 -0600

Seen: 1,262 times

Last updated: May 16 '14