Home | Tutorials | Wiki | Issues
Ask Your Question
1

GAZEBO plugin subscribe to ROS topic

asked 2016-08-05 04:47:50 -0500

Hanteus gravatar image

Greetings, I have some problems making a GAZEBO plugin and a ROS node communicate. The ROS node pubblishes correctly the message on the topic, but the plugin isn't able to acces them.

This is the code of the plugin:

// Initialize node
node = transport::NodePtr(new transport::Node());

// Subscribe to the control node
node->Init("gazebo/quetzalcoatl");
std::cout << "Subscribing to " << "~/quetzalcoatl/cmdVelocity" << " topic" << std::endl;
commandSubscriber = node->Subscribe("~/quetzalcoatl/cmdVelocity", &SkidSteer::updateVelocity, this);
std::cout << "Subscribed to " << commandSubscriber << std::endl;

// Listen to the update event, this event is broadcast every simulation iteration
this->updateConnection = event::Events::ConnectWorldUpdateBegin(
boost::bind(&SkidSteer::OnUpdate, this, _1));

This is the code of the ROS node which pubblishes the message:

while (ros::ok())
{
    ROS_INFO("Node '%s' sending the %d message", ros::this_node::getName().c_str(), count);

    // Update the velocities
    linearVelocity = 10 + count / 100;
    angularVelocity = 0;

    // Fill the message
    cmdVelocityMsg.linearVelocity = linearVelocity;
    cmdVelocityMsg.angularVelocity = angularVelocity;
    cmdVelocityMsg.moveUp = moveUp;
    cmdVelocityMsg.moveDown = moveDown;
    cmdVelocityMsg.moveLeft = moveLeft;
    cmdVelocityMsg.moveRigth = moveRigth;

    cmdVelocityPub.publish(cmdVelocityMsg);

    ros::spinOnce();
    // Sleep untill next loop, Gazebo must be running or it won't work
    loopRate.sleep();

    // ROS_INFO("Sleeped");

    ++count;
}

This is the message used by the plugin:

package quetzalcoatlMsgs.msgs;

message cmdVelocity
{
    required float linearVelocity = 1;
    required float angularVelocity = 2;
    required bool moveUp = 3;
    required bool moveDown = 4;
    required bool moveLeft = 5;
    required bool moveRigth = 6;
}

This is the message used by the node:

float32 linearVelocity
float32 angularVelocity
bool moveUp
bool moveDown
bool moveLeft
bool moveRigth

What I'm doing wrong? Also it is correct to declare two different messages, one for the node and one for the plugin, which refer to the same topic?

edit retag flag offensive close merge delete

Comments

You probably need to use a single message description. Maybe this tutorial will help: http://gazebosim.org/tutorials?tut=guided_i6

chapulina gravatar imagechapulina ( 2016-08-05 12:09:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-08-07 10:42:41 -0500

winston gravatar image

You could not directly subscribe to ROS topics and use ROS messages by a transport node. You have 2 solutions to choose:
1. Declare a ROS node in your plugin and use it to subscribe to your ROS messages. And then fill your transport messages one field by one field.
2. Declare a transport node in your ROS node and publish your transport messages.

The second solution seems more convenient. I have not tried this way but I suggestion you tried it and told us whether it is feasible or not.

edit flag offensive delete link more

Comments

Thank you for your advice. I've choosen the first solution, since it's the one that also explained by this tutorial (http://gazebosim.org/tutorials?tut=guided_i6). Now I need to find a way to force the plugin to use my ros custom message.

Hanteus gravatar imageHanteus ( 2016-08-20 02:32:36 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-08-05 04:47:50 -0500

Seen: 1,844 times

Last updated: Aug 07 '16