Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. add head file

    #include <gazebo/transport/TransportTypes.hh>

  2. add definition of node and Publisher

    transport::NodePtr node; transport::PublisherPtr pub_mydata;

  3. Init node

    transport::NodePtr node(new transport::Node()); node->Init("test"); this->pub_mydata = node->Advertise<msgs::Vector3d>("~/MyData");

  4. Publish data

    msgs::Vector3d msg_Vector3d; msgs::Set(&msg_Vector3d, this->data_from_link); this->pub_mydata->Publish(msg_Vector3d);

  5. Visualize data in gazebo9 ctrl+p

  1. add head file

    #include <gazebo/transport/TransportTypes.hh>

  2. add definition of node and Publisher

    transport::NodePtr node; transport::PublisherPtr pub_mydata;

  3. Init node

    transport::NodePtr node(new transport::Node()); node->Init("test"); this->pub_mydata = node->Advertise<msgs::Vector3d>("~/MyData");

  4. Publish data

    msgs::Vector3d msg_Vector3d; msgs::Set(&msg_Vector3d, this->data_from_link); this->pub_mydata->Publish(msg_Vector3d);

  5. Visualize data in gazebo9 ctrl+p

If you want to control your robot. Then you need a plugin, for example , model plugin.

  1. You should bind a ros::Subscribe to receive your message.

    ros::SubscribeOptions PositionCommandSo = ros::SubscribeOptions::create<your_msgs::PositionCommand>("~/PositionCommand", 1, boost::bind(&YourPlugin::SetPositionCommand, this, _1),ros::VoidPtr(), &this->rosQueue);

```

void YourPlugin::SetPositionCommand(const your_msgs::PositionCommand::ConstPtr  &_msg)
{
    // TODO
    std::cout<<"recive PositionCommand massage"<<std::endl;
    //Update your cmd value tor control
    this->PID_refer_x = _msg->action[0];
}

```

  1. Update your cmd value to a controller, for example PID.
  1. add head file

    #include <gazebo/transport/TransportTypes.hh>

  2. add definition of node and Publisher

    transport::NodePtr node; transport::PublisherPtr pub_mydata;

  3. Init node

    transport::NodePtr node(new transport::Node()); node->Init("test"); this->pub_mydata = node->Advertise<msgs::Vector3d>("~/MyData");

  4. Publish data

    msgs::Vector3d msg_Vector3d; msgs::Set(&msg_Vector3d, this->data_from_link); this->pub_mydata->Publish(msg_Vector3d);

  5. Visualize data in gazebo9 ctrl+p

If you don't want to control your robot. robot by pulgin but using ros-control . Then you need to Subscribe your cmd ,and then publish the ros-controller you used.

If you want to control your robot by a plugin, for example , model plugin.

  1. You should bind a ros::Subscribe to receive your message.

    ros::SubscribeOptions PositionCommandSo = ros::SubscribeOptions::create<your_msgs::PositionCommand>("~/PositionCommand", 1, boost::bind(&YourPlugin::SetPositionCommand, this, _1),ros::VoidPtr(), &this->rosQueue);

```

void YourPlugin::SetPositionCommand(const your_msgs::PositionCommand::ConstPtr  &_msg)
{
    // TODO
    std::cout<<"recive PositionCommand massage"<<std::endl;
    //Update your cmd value tor control
    this->PID_refer_x = _msg->action[0];
}

```

  1. Update your cmd value to a controller, for example PID.
  1. add head file

    #include <gazebo/transport/TransportTypes.hh>

  2. add definition of node and Publisher

    transport::NodePtr node; transport::PublisherPtr pub_mydata;

  3. Init node

    transport::NodePtr node(new transport::Node()); node->Init("test"); this->pub_mydata = node->Advertise<msgs::Vector3d>("~/MyData");

  4. Publish data

    msgs::Vector3d msg_Vector3d; msgs::Set(&msg_Vector3d, this->data_from_link); this->pub_mydata->Publish(msg_Vector3d);

  5. Visualize data in gazebo9 ctrl+p

If you don't want to control your robot by pulgin but using ros-control . Then you need to Subscribe your cmd ,and then publish the value to ros-controller you used.

If you want to control your robot by a plugin, for example , model plugin.

  1. You should bind a ros::Subscribe to receive your message.

    ros::SubscribeOptions PositionCommandSo = ros::SubscribeOptions::create<your_msgs::PositionCommand>("~/PositionCommand", 1, boost::bind(&YourPlugin::SetPositionCommand, this, _1),ros::VoidPtr(), &this->rosQueue);

```

void YourPlugin::SetPositionCommand(const your_msgs::PositionCommand::ConstPtr  &_msg)
{
    // TODO
    std::cout<<"recive PositionCommand massage"<<std::endl;
    //Update your cmd value tor control
    this->PID_refer_x = _msg->action[0];
}

```

  1. Update your cmd value to a controller, for example PID.