MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / stepSimulation

Method stepSimulation

examples/InverseDynamics/InverseDynamicsExample.cpp:245–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245void InverseDynamicsExample::stepSimulation(float deltaTime)
246{
247 if (m_multiBody)
248 {
249 const int num_dofs = m_multiBody->getNumDofs();
250 btInverseDynamics::vecx nu(num_dofs), qdot(num_dofs), q(num_dofs), joint_force(num_dofs);
251 btInverseDynamics::vecx pd_control(num_dofs);
252
253 // compute joint forces from one of two control laws:
254 // 1) "computed torque" control, which gives perfect, decoupled,
255 // linear second order error dynamics per dof in case of a
256 // perfect model and (and negligible time discretization effects)
257 // 2) decoupled PD control per joint, without a model
258 for (int dof = 0; dof < num_dofs; dof++)
259 {
260 q(dof) = m_multiBody->getJointPos(dof);
261 qdot(dof) = m_multiBody->getJointVel(dof);
262
263 const btScalar qd_dot = 0;
264 const btScalar qd_ddot = 0;
265 if (m_timeSeriesCanvas)
266 m_timeSeriesCanvas->insertDataAtCurrentTime(q[dof], dof, true);
267
268 // pd_control is either desired joint torque for pd control,
269 // or the feedback contribution to nu
270 pd_control(dof) = kd * (qd_dot - qdot(dof)) + kp * (qd[dof] - q(dof));
271 // nu is the desired joint acceleration for computed torque control
272 nu(dof) = qd_ddot + pd_control(dof);
273 }
274 if (useInverseModel)
275 {
276 // calculate joint forces corresponding to desired accelerations nu
277 if (m_multiBody->hasFixedBase())
278 {
279 if (-1 != m_inverseModel->calculateInverseDynamics(q, qdot, nu, &joint_force))
280 {
281 //joint_force(dof) += damping*dot_q(dof);
282 // use inverse model: apply joint force corresponding to
283 // desired acceleration nu
284
285 for (int dof = 0; dof < num_dofs; dof++)
286 {
287 m_multiBody->addJointTorque(dof, joint_force(dof));
288 }
289 }
290 }
291 else
292 {
293 //the inverse dynamics model represents the 6 DOFs of the base, unlike btMultiBody.
294 //append some dummy values to represent the 6 DOFs of the base
295 btInverseDynamics::vecx nu6(num_dofs + 6), qdot6(num_dofs + 6), q6(num_dofs + 6), joint_force6(num_dofs + 6);
296 for (int i = 0; i < num_dofs; i++)
297 {
298 nu6[6 + i] = nu[i];
299 qdot6[6 + i] = qdot[i];
300 q6[6 + i] = q[i];
301 joint_force6[6 + i] = joint_force[i];
302 }

Callers

nothing calls this directly

Calls 12

quatRotateFunction · 0.85
getJointPosMethod · 0.80
getJointVelMethod · 0.80
hasFixedBaseMethod · 0.80
addJointTorqueMethod · 0.80
nextTickMethod · 0.80
getLinkMethod · 0.80
getRotationMethod · 0.80
getNumDofsMethod · 0.45
forwardKinematicsMethod · 0.45

Tested by

no test coverage detected