ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

publish from gazebo

asked 2012-03-20 23:59:08 -0600

hmmm gravatar image

updated 2012-03-22 20:13:43 -0600

kwc gravatar image

hi guys, i want to publish from a gazebo plugin. How can i do that? In the same way as i publish from a common node? so do i have to write a main() and while{} and so on? I want to publish torque in order to plot it with rxplot. this is the part of the plugin:

torque.x = inertia.x *  controllers_.roll.update(roll_command, euler.x, angular_velocity.x, dt);
torque.y = inertia.y *  controllers_.pitch.update(pitch_command, euler.y, angular_velocity.y, dt);

body_->SetTorque(torque);

i try following, is this the right way?

ros::Publisher wrench_publisher;
geometry_msgs::Wrench moment;
int main(int argc, char **argv)
{
  ros::init(argc, argv, "hector_quadrotor_gazebo_plugins");
  ros::NodeHandle node_handle;
  ros::Rate loop_rate(100);
  wrench_publisher_ = node_handle.advertise<geometry_msgs::Wrench>("force", 1);
  while(ros::ok())
  {
  ros::spinOnce();
  moment.torque.x = torque.x ;
  moment.torque.y = torque.y;

  wrench_publisher.publish(moment);
  }
  return 0;
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-03-22 16:08:01 -0600

hsu gravatar image

In fuerte, I just updated the plugin template if it's of any help

gazebo_ros_template.h and gazebo_ros_template.cpp

Similarly in electric: gazebo_ros_template.h and gazebo_ros_template.cpp

The simplest example I can think of in electric is the sim time publisher.

edit flag offensive delete link more
1

answered 2012-03-21 04:50:15 -0600

DimitriProsser gravatar image

You cannot put a main() in a Gazebo plugin because it runs as part of Gazebo's main(). You'd have to put your publish functions in one of the interface methods (probably the update() method).

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-03-20 23:59:08 -0600

Seen: 409 times

Last updated: Mar 22 '12