Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

lines 143-144 of LiftDragPlugin.cc:

this->updateConnection = event::Events::ConnectWorldUpdateBegin(
          std::bind(&LiftDragPlugin::OnUpdate, this));

Short Answer:
This passes your Plugin's Update method (in this case, LiftDragPlugin::OnUpdate) as a callback function to the Gazebo Simulator's Events class instance, allowing Gazebo to call your Plugin's method (LiftDragPlugin::OnUpdate) at every simulation time step.

Long Answer:
- You write a Gazebo Plugin to affect the simulation - in this case the LiftDragPlugin applies rudimentary lift and drag forces to the attached model.
- In order for the LiftDragPlugin to apply these forces in the simulation, it needs to, _at every simulation time step_, 1) determine the attached model's orientation relative to gravity plane, determine model's velocity, etc., 2) carry out some simple lift-drag calculations, and 3) apply the appropriate lift-drag forces.
- Therefore, in your Gazebo Plugin, you create a Update, OnUpdate, RunEverySimulationTimeStep, etc. method - here it's LiftDragPlugin::OnUpdate, that contains the code that should be run at each simulation time step, and you pass that method to the Gazebo Simuator's Event class instance as a callback function: event::Events::ConnectWorldUpdateBegin(...).
- Now at each simulation time step, the Gazebo Simulator will call the LiftDragPlugin::OnUpdate method and everybody lives happily ever after.

lines 143-144 of LiftDragPlugin.cc:

this->updateConnection = event::Events::ConnectWorldUpdateBegin(
          std::bind(&LiftDragPlugin::OnUpdate, this));

Short Answer:
This passes your Plugin's Update method (in this case, LiftDragPlugin::OnUpdate) as a callback function to the Gazebo Simulator's Events class instance, allowing Gazebo to call your Plugin's method (LiftDragPlugin::OnUpdate) at every simulation time step.

Long Answer:
- You write a Gazebo Plugin to affect the simulation - in this case the LiftDragPlugin applies rudimentary lift and drag forces to the attached model.
- In order for the LiftDragPlugin to apply these forces in the simulation, it needs to, _at every simulation time step_, 1) determine the attached model's orientation relative to gravity plane, determine model's velocity, etc., 2) carry out some simple lift-drag calculations, and 3) apply the appropriate lift-drag forces.
- Therefore, in your Gazebo Plugin, you create a Update, OnUpdate, RunEverySimulationTimeStep, etc. method - here it's LiftDragPlugin::OnUpdate, that contains the code that should be run at each simulation time step, and you pass that method (or rather a reference to that method) to the Gazebo Simuator's Event class instance as a callback function: event::Events::ConnectWorldUpdateBegin(...).
- Now at each simulation time step, the Gazebo Simulator will call the LiftDragPlugin::OnUpdate method and everybody lives happily ever after.