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

Gazebo services problems

asked 2011-07-07 10:25:46 -0500

Aidan1488 gravatar image

updated 2011-07-08 05:10:52 -0500

hsu gravatar image

Hey guys it's me again, how r ya doin'? :)

I have today two dumb questions about gazebo.

First: I'm trying to simulate a simple soccer ball. To do this I'm using a simple URDF file with an sphere and gazebo services. Do you know of any example of how to make a client for this gazebo services on cpp? I've checked the how to write a service/client tutorial and also run into a few examples but the one I tried to make doesn't do anything (it compiles when I 'make' the pack, but if I call it the terminal freezes), I must be missing a few things. This is my code (its the only thing I do, I start gazebo empty_world, spawn the model and run the executable of this client) this one is called move_ball.cpp:

int main(int argc, char** argv){
  ros::init(argc, argv, "move_ball");
  ros::NodeHandle node;
  ros::Publisher ball_state = node.advertise<gazebo_msgs::ModelState>("ball/ModelState", 10);
  ros::Rate rate(10.0);
  while (node.ok()){
    gazebo_msgs::ModelState msg;
    msg.model_name = "ball";
    msg.pose.position.x = 0;
    msg.pose.position.y = 0;
    msg.pose.position.z = 0;
    msg.pose.orientation.x = 0;
    msg.pose.orientation.y = 0;
    msg.pose.orientation.z = 0;
    msg.pose.orientation.w = 0;
    msg.twist.linear.x = 0;
    msg.twist.linear.y = 0;
    msg.twist.linear.z = 0;
    msg.twist.angular.x = 0;
    msg.twist.angular.y = 0;
    msg.twist.angular.z = 0;
    ball_state.publish(msg);
    rate.sleep();
  }
  return 0;
};

I've also tried to do a spawn client with the SpawnModel service, but when I run it it tells me that the SpawnModel service it's not advertised. Is this something I have to do in the cpp file? any instruction I'm missing? this one is called spawn_ball.cpp

int main(int argc, char** argv){
  ros::init(argc, argv, "my_spawn_model");
  ros::NodeHandle node;
  ros::service::waitForService("SpawnModel");
  ros::ServiceClient add_model = node.serviceClient<gazebo_msgs::SpawnModel>  ("SpawnModel");
  gazebo_msgs::SpawnModel srv;
  srv.request.model_name= "ball.urdf";
  srv.request.model_xml= "urdf";
  srv.request.initial_pose.position.x= 0;
  srv.request.initial_pose.position.y= 0;
  srv.request.initial_pose.position.z= 0;
  srv.request.initial_pose.orientation.x= 0;
  srv.request.initial_pose.orientation.y= 0;
  srv.request.initial_pose.orientation.z= 0;
  srv.request.initial_pose.orientation.w= 0;
  add_model.call(srv);
 return 0;
};

Second: what I want to do is move the ball to simulate a "kick" by using gazebo service ModelState. But something funny happens. When I use the pose command to move the ball from one point to another, the ball disappears for one second, and when it appears it falls from the sky just above the selected point. This happens the same way if instead of pose I send a twist command, disappears, fall and then execute. I've done this before with the gazebo default models (cup, coffe_cup) without this problem. The just move smoothly. I have changed physics to the exact same configuration as this default models and nothing ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-07-08 07:13:02 -0500

Aidan1488 gravatar image

Thanks hsu :). I checked and I wasn't using a rosservice (SetModelState) but a rostopic (ModelState) so of course my code did nothing. Now I have my running client :). Also I accidentally found out what was wrong with my model, I just had to switch the kd and kp values and voila! problem solved ;).

edit flag offensive delete link more
2

answered 2011-07-08 05:25:34 -0500

hsu gravatar image

Hi Aidan,

Please take a look at the simulator tutorials first, that should answer a lot of your questions. Also, please take a look at gazebo API for topics and services available via simulator.

John

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-07-07 10:25:46 -0500

Seen: 1,450 times

Last updated: Jul 08 '11