...
Code Block | ||||
---|---|---|---|---|
| ||||
namespace OpenSim { // Manages inputs to the optimization via OpenSim's XML abilities. class FlippinFelinesOptimizerTool : public Object { // ********** PART B ********** }; } // end usingnamespace OpenSim namespace // Finds a control input that achieves flip, as determined by objective function. class FlippinFelinesOptimizerSystem : public SimTK::OptimizerSystem { // ... FlippinFelinesOptimizerSystem(OpenSim::FlippinFelinesOptimizerTool & tool) : _tool(tool), // ... { // ... } // ... // The meat of this class; this is called by the Optimizer that has this system. int objectiveFunc(const SimTK::Vector & parameters, bool new_parameters, SimTK::Real & f) const { // ... f = ...; // ... } // ... // Reference to the FlippinFelinesOptimizerTool. OpenSim::FlippinFelinesOptimizerTool & _tool; // ... }; |
...
Here's a skeleton of the FlippinFelinesOptimizerSystem class. The two functions that are the most important are the constructor and objectiveFunc(). We focus on these. The definition of an optimization problem consists primarily of (1) parameters/inputs, and (2) the objective function. The constructor
Code Block | ||||
---|---|---|---|---|
| ||||
C.1: Optimization parameters
...
/**
* Finds a control input history that achieves certain desired features
* of a cat's flipping maneuver, as determined by the objective function.
* The control of the system is performed via a PrescribedController that
* uses a spline for all actuators.
*
* Parameters are ordered by actuator, then by spline point index for a
* given actuator. Parameters are nondimensionalized by the min or max
* control values for the associated actuator.
* */
class FlippinFelinesOptimizerSystem : public SimTK::OptimizerSystem {
public:
/**
* @param tool Contains all input settings.
* */
FlippinFelinesOptimizerSystem(OpenSim::FlippinFelinesOptimizerTool & tool) :
_tool(tool),
_duration(1.0),
_objectiveCalls(0),
_objectiveFcnValueBestYet(SimTK::Infinity),
{
// Parse inputs & prepare output
// --------------------------------------------------------------------
// C.1
// Add a controller to the model to control the actuators it has
// --------------------------------------------------------------------
// C.2
// Set parameter limits/bounds for the optimization.
// --------------------------------------------------------------------
// C.3
}
SimTK::Vector initialParameters()
{
// C.4
}
/**
* Defines desired features for the cat model's flip. Each call to this
* function updates the model's control, runs a forward dynamic simulation
* with this control, computes the objective value resulting from the
* simulation, and saves the results to output.
* */
int objectiveFunc(const SimTK::Vector & parameters, bool new_parameters,
SimTK::Real & f) const
{
// ...
// Unpack parameters into the model (i.e., update spline points)
// --------------------------------------------------------------------
// C.5
// Run a forward dynamics simulation
// --------------------------------------------------------------------
// C.6
// Construct the objective function, term by term
// --------------------------------------------------------------------
// C.7
// Update the log and outputs with the objective function value
// --------------------------------------------------------------------
// C.8 Collapsible.
}
// Miscellaneous functions (used, but uninteresting)
// ------------------------------------------------------------------------
// TODO collapsible.
// C.10
private:
// Objective function terms
// ------------------------------------------------------------------------
// C.7, collapsible
// Member variables
// ------------------------------------------------------------------------
//
// C.9
}; |
C.1: Optimization parameters
TODO talk about controls
TODO talk about how the parameters work.
C.2 is the part that would be custom between different pplz
CAN BE ANYTHING
iterations is not number of objective function calls.
...