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