Gazebo | Ignition | Community
Ask Your Question

Initial joint position *without* ROS

asked 2020-10-20 13:56:17 -0600

Please help me I'm desperate gravatar image

Hi everyone, I know this has been asked a few times but I really can't find a working solution for my use case.

I simply want my model to start with nonzero angles, i.e. an initial angle. I cannot find any way of doing this. According to the SDF spec there should be an <initial_position> element in the axis element of "Joint", and if I set it like so:

<joint type="revolute" name="left_hip_axis_3_hip_axis_2_joint">
        <pose> -0.145 0 0 0 -1.5707 0 </pose>


            <xyz> 0 0 1 </xyz>

It simply ignores the value and launches with zero angle anyway... What am I supposed to do to fix this? I'm running gazebo 9.14 (for some reason the tagging didn't work....). It is essential for me to have this feature because I cannot test my controller code otherwise.

edit retag flag offensive close merge delete


This has been a long requested feature that has had discussions on and off since 2012... see

wongrufus gravatar imagewongrufus ( 2020-10-25 21:54:07 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-20 20:39:27 -0600

initial_position is probably not implemented.

You can write a model plugin, access the joints directly, and set your initial positions. The ROS interface works in an equivalent way.

This is all you would have to do:

void MyModelPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) {
  std::map<std::string, double> positions;
  // Parse positions from _sdf->Get<whatever>("initialPositions");

  for (physics::JointPtr joint : _model->GetJoints()){
    if (positions.count(joint->GetName()) == 0) continue;
    joint->SetPosition(0, positions[joint->GetName()]);
edit flag offensive delete link more


I used this leftHip3Joint->SetPosition(0, 1); as a dumbed-down version of your code and it does start at the position but then wants to continually move to this position if I disturb it, because the PID is trying to reach its goal. This is not ok if I want to test my controller since it will be excerting a constant force. Now that I think about it though, do you reckon a good way of doing this is to simply set all joint controller gains to 0 after having reached this position?

Please help me I'm desperate gravatar imagePlease help me I'm desperate ( 2020-10-21 08:32:02 -0600 )edit

This code shouldn't affect your simulation after the initialization. Did you maybe add the SetPosition call somewhere in your update method?

nlamprian gravatar imagenlamprian ( 2020-10-21 11:40:06 -0600 )edit

I thought once you set a desired position for the Joint, the Gazebo PID's always try to reach it, that's why my thought was to set the gains to 0.

Please help me I'm desperate gravatar imagePlease help me I'm desperate ( 2020-10-21 16:37:54 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-10-20 13:56:17 -0600

Seen: 187 times

Last updated: Oct 20 '20