Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I assume you have a callback on WorldUpdateBegin? The argument const common::UpdateInfo to the callback has a field simTime that can be used to get the current simulated time. To apply a force every 4 seconds:

  1. Apply a force
  2. Save the time that the force was applied
  3. Don't apply a force again until the current time is greater than the last time plus 4 seconds.

For an example, see the RandomVelocityPlugin. It changes the velocity of an object every update_period. Set update_period to 4 seconds and replace setting the velocity with applying a force and you have the behavior you're looking for.