Gazebo | Ignition | Community
Ask Your Question
0

how to use torque to control joint

asked 2013-03-15 11:22:30 -0500

lugd1229 gravatar image

Hello, may I control the joint using torque like animate_pose as follows, because it just can control the position, I want to add torque to the joint. thank you best guangda

std::map<std::string, common::numericanimationptr=""> anim;

  // Create a new animation for the "my_joint" define in the SDF file.
  // The animation will last for 5.0 seconds, and it will repeat
  anim["box::my_joint"].reset(new common::NumericAnimation(
        "my_animation", 5.0, true));

  // Create a key frame for the starting position of the joint
  common::NumericKeyFrame *key = anim["box::my_joint"]->CreateKeyFrame(0.0);
  key->SetValue(0.0);

  // Create a key frame half-way through the animation
  key = anim["box::my_joint"]->CreateKeyFrame(2.5);
  key->SetValue(-3.14);

  // Create the end key frame to be at the same position as the start
  // for a smooth animation
  key = anim["box::my_joint"]->CreateKeyFrame(5.0);
  key->SetValue(0.0);

 // Attach the animation to the model
  _model->SetJointAnimation(anim);
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-03-15 14:22:38 -0500

AndreiHaidu gravatar image

updated 2013-03-16 06:34:56 -0500

Hi,

On a joint you can only apply a force, with SetForce. See here.

model->GetJoint("joint_name")->SetForce(int _index,double _force);

If you want to apply torque, you apply it with SetTorque to the link. See here. An example:

model->GetLink("link_name")->SetTorque(vector3);

---UPDATE---

I took the example from this tutorial, you can check it out.

...
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) 
{
  this->model = _parent;

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

public: void OnUpdate(const common::UpdateInfo & /*_info*/)
{
    // Check duration here, something like:
    // if ((common::Time dt = this->model->GetWorld()->GetSimTime() - last_saved_time) < 5 )
    model->GetLink("link_name")->SetTorque(math::Vector3(0, 0, 0));
}
...

Cheers, Andrei

edit flag offensive delete link more

Comments

thank you, I find add a big torque to the link and it move a little, so ,I think this torque just continue a short time, how to maintain this torque for 5 second or more?

lugd1229 gravatar imagelugd1229 ( 2013-03-15 20:46:00 -0500 )edit

Then I don't thin you should use animation, you can maintain this torque in the onUpdate function, and if you need a given time you can always check the difference from the simulation time, I will update the answer with a generic example.

AndreiHaidu gravatar imageAndreiHaidu ( 2013-03-16 06:21:36 -0500 )edit

to apply force continuously, call it on every world update, see http://gazebosim.org/wiki/Tutorials/1.5/plugins/modelmanipulationplugin, replace the calls to "SetLinearVel" with "SetForce" example above.

hsu gravatar imagehsu ( 2013-03-16 14:56:24 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-03-15 11:22:30 -0500

Seen: 2,931 times

Last updated: Mar 16 '13