0
$\begingroup$

Rosanswers logo

hi, i want to call the service /gazebo/set_model_state from gazebo package. I can do it by command-console:

rosservice call /gazebo/set_model_state '{model_state: { model_name: my_robot, pose: { position: { x: 0.0, y: 0.0 ,z: 0.1 }, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 0.0 } }, twist: { linear: {x: 0.0 , y: 0 ,z: 0 } , angular: { x: 0.0 , y: 0 , z: 0.0 } } , reference_frame: world } }'

i tryed to do this in c++ code. someone can say me what is wrong? this is the code:

#include "gazebo/SetModelState.h"

...

        geometry_msgs::Pose start_pose;
        start_pose.position.x = 0.0;
        start_pose.position.y = 0.0;
        start_pose.position.z = 2;
        start_pose.orientation.x = 0.0;
        start_pose.orientation.y = 0.0;
        start_pose.orientation.z = 0.0;
        start_pose.orientation.w = 0.0;

        geometry_msgs::Twist start_twist;
        start_twist.linear.x = 0.0;
        start_twist.linear.y = 0.0;
        start_twist.linear.z = 0.0;
        start_twist.angular.x = 0.0;
        start_twist.angular.y = 0.0;
        start_twist.angular.z = 0.0;

        gazebo::ModelState modelstate;
        modelstate.model_name = (std::string) "robovolc";
        modelstate.reference_frame = (std::string) "world";
        modelstate.pose = start_pose;
        modelstate.twist = start_twist;

        ros::ServiceClient client = n.serviceClient<gazebo::SetModelState>("/gazebo/set_model_state");
        //ros::ServiceClient client = n.serviceClient<gazebo::SetModelState>("/gazebo/SetModelState");

        gazebo::SetModelState setmodelstate;
        setmodelstate.request.model_state = modelstate;
        client.call(setmodelstate);

Originally posted by Maurizio88 on ROS Answers with karma: 155 on 2012-02-08

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Please see here for a similar question/answer.


Originally posted by hsu with karma: 5780 on 2012-02-08

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

i solved the problem! the line

ros::NodeHandle n;

wasn't visible for the call to node. i rewrote it close to the code.


Originally posted by Maurizio88 with karma: 155 on 2012-02-09

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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