Home | Tutorials | Wiki | Issues
Ask Your Question
0

How to setforce at a constant interval?

asked 2018-06-12 03:05:14 -0500

jwchang gravatar image

I use gazebo7.12.0 and want to write a model plugin to apply torque to a joint at a constant interval of 0.01 sec. It seems that the update rate of gazebo is 1000Hz, so I wirte the following code in OnUpdate(). This is not a good way because it's not exact 1000Hz in simulation from my testing. Is there other way to do it?

int count = 0;
public: void OnUpdate()
{
  if (count <= 10)
     this->model->GetJoint("joint")->SetForce(0,5);
  else if (count > 10 && count <= 20)
     this->model->GetJoint("joint")->SetForce(0,5);
  ...
  count++;
};
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-12 10:12:58 -0500

Why do you say it's not at 1000 Hz? Try changing the callback to OnUpdate(const common::UpdateInfo &_info) and print _info.simTime.

edit flag offensive delete link more

Comments

Thank you. I change my code to store the torque values into an array, which is SetForce(0,torque[count++]); usleep(10000);, and it works.

jwchang gravatar imagejwchang ( 2018-06-13 02:26:04 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-11 21:59:08 -0500

Seen: 109 times

Last updated: Jun 12