Home | Tutorials | Wiki | Issues
Ask Your Question
0

GetAngle don't give an exacte value

asked 2015-05-18 11:37:28 -0500

djou07 gravatar image

updated 2015-05-21 18:14:54 -0500

Hi every body

When I set the joint of an angle to a specific value and then I read it I don't have the same value. And each time a different value.

Example:

this->jointController->SetJointPosition(joint, 0.0);

I get the joint by:

this->joint->GetAngle(2).Radian();

and the value I get are either:

-0.002423015843935 or -0.000104254624437 or 0.000201667337713....

And if I set the angle to 0.5 I get:

0.5000000001 or 0.49999999

This really affects the results of my work. What do you think ?

thanks in advance!


EDIT
The source code

#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{   
    class SetJoints : public ModelPlugin
    {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) 
    {
        this->model = _parent;

        this->controller = new physics::JointController(model);

        this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&SetJoints::OnUpdate, this, _1));
    }

    public: void OnUpdate(const common::UpdateInfo & )
    {
        //If I set the index it will not set the angle to specific angle
        //controller->SetJointPosition(this->model->GetJoint("joint"), 2, 1); 

        controller->SetJointPosition(this->model->GetJoint("joint"), 1.5); 

        cout.precision(15);
        cout << fixed << this->model->GetJoint("joint")->GetAngle(1).Radian() << endl;
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
    private: physics::JointController * controller;
};
GZ_REGISTER_MODEL_PLUGIN(SetJoints)
}

the SDF file

<?xml version='1.0'?>
<sdf version='1.4'>
<world name="default">
<include>
  <uri>model://ground_plane</uri>
</include>
<include>
  <uri>model://sun</uri>
</include>
<model name="monModele">     
  <link name='bras1'>
    <pose>0 0.4 0.025 0 0 0</pose>
    <collision name='collision'>
      <geometry>
        <box>
          <size>.4 .4 .05</size>
        </box>
      </geometry>
    </collision>
    <visual name='visual'>
      <geometry>
        <box>
          <size>.4 .4 .05</size>
        </box>
      </geometry>
    </visual>
  </link>
  <link name='bras2'>
    <pose>0.4 0.4 0.025 0 0 0</pose>
    <collision name='collision'>
      <geometry>
        <box>
          <size>.4 .4 .05</size>
        </box>
      </geometry>
    </collision>
    <visual name='visual'>
      <geometry>
        <box>
          <size>.4 .4 .05</size>
        </box>
      </geometry>
    </visual>
  </link>

  <joint type="revolute" name="joint">
    <pose>.2 0 0 0 0 0</pose>
    <child>bras1</child>
    <parent>bras2</parent>
    <axis>
      <xyz>0 1 0</xyz>
    </axis>
  </joint>
  <joint type="revolute" name="jointGround">
    <pose>0 0 -0.025   0 0 0</pose>
    <parent>world</parent>
    <child>bras2</child>
    <axis>
      <xyz>0 1 0</xyz>
      <limit>
        <lower>0</lower><upper>0</upper>
      </limit> 
    </axis>
  </joint>
  <plugin name="set_joints" filename="build/libset_joints.so"/>
</model>
</world>

</sdf>

edit retag flag offensive close merge delete

Comments

Is your joint interacting with physics? It might have slightly moved since you set it.

chapulina gravatar imagechapulina ( 2015-05-18 12:56:09 -0500 )edit

yes. I get the angle in the same update loop, so if the joint will move, it will be in next update loop isn't it ?

djou07 gravatar imagedjou07 ( 2015-05-18 13:40:42 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-05-18 17:59:44 -0500

nkoenig gravatar image

Looks like you are setting the joint angle using index=0, but reading the joint angle using index=2. See here

What type of joint are you using?

edit flag offensive delete link more

Comments

I am using a revolute joint. When I specify the index=2 in SetJointPosition It does not work. I mean that it don't set the angle to the specific value. But even If the joint rotate in x axis, it gives same problem.

djou07 gravatar imagedjou07 ( 2015-05-19 05:17:51 -0500 )edit

I added the source code. thanks in advance :)

djou07 gravatar imagedjou07 ( 2015-05-19 07:02:09 -0500 )edit

is there any way to get joint values directly from the ODE engine ?

djou07 gravatar imagedjou07 ( 2015-05-21 12:00:31 -0500 )edit

Revolute joints only have 1 axis, with index 0. Revolute2 joints, for example, have 2 axes, with indices 0 and 1. There are no joints with more than 2 axes, so an index 2 shouldn't work. Therefore, you probably want to use GetAngle(0).

chapulina gravatar imagechapulina ( 2015-05-21 12:18:22 -0500 )edit

thanks for the explanation. I thought that the index is the axis in witch the joint rotate. o for x, 1 for y and 2 for z

djou07 gravatar imagedjou07 ( 2015-05-21 18:20:16 -0500 )edit

Even when I use GetAngle(0) I get different values :/

djou07 gravatar imagedjou07 ( 2015-05-23 05:11:09 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-05-18 11:37:28 -0500

Seen: 3,012 times

Last updated: May 21 '15