Rosanswers logo

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;
  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::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;
 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. Why is this happening? I've also tried to make a model on gazebo standards instead of urdf but the ball or just don't appear or it asks me for a mesh file (even though the only thing I want is a red sphere). Is absolutely necessary for it to be a gazebo file? or is there something I'm not adding to the urdf file?

This is what is inside the gazebo tag the rest of the urdf its just a red ball. The inertial matrix it's the identity.

<gazebo reference="ball_link">
  <<massMatrix true</massMatrix>

All this are my 'try and error' experiments.But no change in any case. I've also used a .launch file to load it into the param server and then spawn it but no changes either.

Thanks again for your time and patience and again forgive all this silly questions ;).

Originally posted by Aidan1488 on ROS Answers with karma: 46 on 2011-07-07

Post score: 0


2 Answers 2


Rosanswers logo

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.


Originally posted by hsu with karma: 5780 on 2011-07-08

This answer was NOT ACCEPTED on the original site

Post score: 2


Rosanswers logo

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

Originally posted by Aidan1488 with karma: 46 on 2011-07-08

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.