Possible to set angle?

Is it possible to set the actuator to work like a motor, which we can set the joint’s desired angle? for example 30 degrees shift from its origin?

Not directly using the DART API, but it’s easy to recreate the effect with a simple wrapper function.

First, use Joint::setActuatorType(~) like this:


You could also use VELOCITY instead of SERVO if you don’t care about joint force limits.

After that, you can define a simple wrapper function:

// This function assumes you have a 1-dof joint which is set to SERVO or VELOCITY actuator mode
void command_position(
  const dart::dynamics::JointPtr joint,
  const double reference_position,
  const double timestep,
  const double v_limit)
  const double position = joint->getPosition(0);
  const double err = reference_position - position;
  const double v = std::max(-v_limit, std::min(v_limit, err/timestep));
  joint->setCommand(0, v);

Then to set your desired joint position, just do:

command_position(joint, ref_p, world->getTimeStep(), v_limit);

That’s cool, but when using servo or velocity actuator, will addExtForce still has its effect and works as expected?

Yes, external forces will still affect the simulation as normal. The servo actuator would “fight” the external forces within the joint force limit of the joint, just like a real motor.

However, internal joint forces that you set using joint->setForce(~) will get overwritten by the actuator command when the joint is in SERVO mode.

Wow, that’s really cool and fits in my situation. BTW, why the external force can be added, but the command force will be overwritten, are they actually two separate variables in dart, and sum to one in the end

Do you mind to illustrate the difference of the internal workflow of command and ExtForce? If any inconvinence, it’s OK.