Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Gazebo services problems

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.

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?

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

Gazebo services problems

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. 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?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"
material>Gazebo/Red</material
laserRetro>2000.0</laserRetro
kp 100000000.0 /kp
kd 1.0 /kd
mu1 1.0 /mu1
mu2 1.0 /mu2
massMatrix true /massMatrix
static true /static
turnGravityOff true /turnGravityOff

/gazebo

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

click to hide/show revision 3
No.3 Revision

Gazebo services problems

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", 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 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> 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. 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? 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"
material>Gazebo/Red</material
laserRetro>2000.0</laserRetro
kp 100000000.0 /kp
kd 1.0 /kd
mu1 1.0 /mu1
mu2 1.0 /mu2
massMatrix true /massMatrix
static true /static
turnGravityOff true /turnGravityOff
<gazebo reference="ball_link">
  <material>Gazebo/Red</material>
  <laserRetro>2000.0</laserRetro>
  <kp>100000000.0</kp>
  <kd>1.0</kd>
  <mu1>1.0</mu1>
  <mu2>1.0</mu2>
  <<massMatrix true</massMatrix>
  <static>true</static>
  <turnGravityOff>true</turnGravityOff>
</gazebo

/gazebo

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