Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

GAZEBO plugin subscribe to ROS topic

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
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;


    // Sleep untill next loop, Gazebo must be running or it won't work

    // ROS_INFO("Sleeped");


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?