Home | Tutorials | Wiki | Issues
Ask Your Question
0

Call gazebo/set_model_state without resetting position

asked 2014-06-30 15:36:46 -0600

K. Zeng gravatar image

I asked this over at ROS forums as well, but I'm in a bit of a rush in this situation. Hi, everyone. I'm currently trying to use gazebo/set_ model_state in a C++ program to set a robot's velocity. My preliminary code is below:

 #include "ros/ros.h"
#include <gazebo_msgs/SetModelState.h>
#include <cstdlib>
//I'm going to implement user-specified twist values later.
int main (int argc, char **argv)
{
  ros::init(argc,argv,"robot_mover_mark_two");
  ros::NodeHandle n;
  ros::ServiceClient client = n.serviceClient<gazebo_msgs::SetModelState>("/gazebo/set_model_state");
  gazebo_msgs::SetModelState setmodelstate;
  gazebo_msgs::ModelState modelstate;
  modelstate.model_name = "my_robot";
  modelstate.reference_frame = "world";

  geometry_msgs::Twist model_twist;
  model_twist.linear.x = 1.0;
  model_twist.linear.y = 1.0;
  model_twist.linear.z = 0.0;
  model_twist.angular.x = 0.25;
  model_twist.angular.y = 0.0;
  model_twist.angular.z = 0.0;
  modelstate.twist = model_twist;

  setmodelstate.request.model_state = modelstate;

  if (client.call(setmodelstate))
  {
    ROS_INFO("BRILLIANT!!!");
    ROS_INFO("%f, %f",modelstate.pose.position.x,modelstate.pose.position.y);
  }  
  else
  {
    ROS_ERROR("Failed to call service ");
    return 1;
  }
  return 0;  
}

I noticed that every time I run the command, the robot's position is reset to the origin in the Gazebo simulation environment. Are the position parameters set to zero by default if I don't include them in the rosservice call? If so, are there any ways I can use this code and have the model stay in the current position (i.e. just change velocity/twist on the fly)?

edit retag flag offensive close merge delete

Comments

you need one more line: setmodelstate.request.model_state = modelstate;//request line is important or you will see the error: Updating ModelState: model [] does not exist check here: https://answers.ros.org/question/12116/calling-gazebo-service-set_model_state-in-c-code/

sammiL gravatar imagesammiL ( 2017-12-04 19:41:33 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-07-01 17:56:43 -0600

nkoenig gravatar image

I believe the position is set to zero by default.

You can try to get the model state first:

http://gazebosim.org/tutorials/?tut=ros_comm#GetModelStateExample.

edit flag offensive delete link more

Comments

Thank you. I'm going to try that right now.

K. Zeng gravatar imageK. Zeng ( 2014-07-02 10:41:34 -0600 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-06-30 15:36:46 -0600

Seen: 3,880 times

Last updated: Jul 01 '14