Hi,

In my gazebo plugin, I have to use the function

virtual math::Vector3 gazebo::physics::Joint::GetLinkForce ( unsigned int   _index) const pure virtual


or

virtual math::Vector3 gazebo::physics::Joint::GetLinkTorque ( unsigned int  _index) const pure virtual


These functions should return the force applied at the centre of mass of a link; the problem is that this functions are pure virtual, so I must define them. I could use the ODEJoint class (that inherits from Joint class): this owns the above functions, but only virtual.

I don't understand how to use the ODEJoint class, nay how to include this class in my plugin.

Can I use this functions without having ODEJoint?

Thank you!

edit retag close merge delete

Sort by » oldest newest most voted

Hi I solved the proble adding

joint1->SetProvideFeedback(1);


command. So I can use GetLinkForce without problem.

more

You're not the one who must define it, each of the 4 physics engines supported by Gazebo will have its implementation.

Gazebo's API is organized in a way that you can call the base class functions, and under the hood, the function for the current physics engine will be called for you. This is made so you can switch physics engines without changing your code.

So if you're using ODE as the physics engine and call Joint::GetLinkForce, ODEJoint::GetLinkForce will actually be called. The same is valid for the other physics engines.

See this plugin for example. It calls SetForce, which is also pure virtual.

more

Those functions get implemented by a specific physics engine, such as ODE or Bullet or Simbody. You can call a pure virtual function, and the correct implementation will be used automatically.

You should not try to implement that function, unless you are trying to implement a new physics engine.

Maybe you should describe what you are trying to do.

more

Hi, I would like to obtain the force applied on the link at every gazebo step. So, as usual I get the pointer to the joint in the Load function: joint=this->model->GetJoint("joint_name"); Then in the OnUpdate function (called in the Load) I try to obtain the force: force=joint->GetLinkForce(index); (I defined force as a class variable math::Vector3). This causes segmentation fault. Can my problem be caused by an error on the pointer? I thought that it was caused by the GetLinkForce function.

( 2016-03-16 13:27:28 -0500 )edit

You should generate a backtrace using gdb to see where the segmentation fault is occurring. You could have a bad pointer, but it's hard to say without more information.

( 2016-03-16 13:32:20 -0500 )edit