- This topic has 2 replies, 2 voices, and was last updated 8 years, 7 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Home › Forum › SOFA › Programming with SOFA › [SOLVED] Update an engine at every step
Tagged: 64_bits, engine data update energy, Linux_ubuntu, SOFA_1512
Hello,
I’m trying to create a component that at each frame computes the kinetic, potential and mechanical energy of a context.
For that purposes, I have create a DataEngine. This DataEngine has no inputs and has one output, which consist on a struct that contains the energy values for each timestep. The Update method is the following:
sofa::core::ExecParams params;
sofa::simulation::common::MechanicalOperations mop(¶ms, this->getContext());
SReal kinetic, potential;
mop.computeEnergy(kinetic, potential);
Energy *energy = m_energy.beginEdit();
energy->potentialEnergy.push_back(potential);
energy->kineticEnergy.push_back(kinetic);
energy->mechanicalEnergy.push_back(potential + kinetic);
energy->time.push_back(this->getContext()->getTime());
m_energy.endEdit();
setDirtyValue();
setDirtyOutputs();
The problem with this is that, as I don’t have input Datas, the Update method is not being called unless I open the DataViewer, so I missing a lot of time steps.
I know I could set the positions of a MechanicalObject as an input data, but this is unconvenient as I would like this component to look the energy of a context that may have more than one MechanicalObject.
How could I create a DataEngine component that performs an Update every time step?
Thanks!
Hi jjcasmar,
To solve your problem you can implement the handleEvent function of your engine to make it call the update function when you want (for instance at the beginning of each time step).
Hope this help,
Rosalie
That is a great idea! I completely forgot about events…
Thanks!
WARNING
The forum has been moved to GitHub Discussions.
Old topics and replies are kept here as an archive.