summaryrefslogtreecommitdiff
path: root/LocomotorPrimitives.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LocomotorPrimitives.cpp')
-rw-r--r--LocomotorPrimitives.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/LocomotorPrimitives.cpp b/LocomotorPrimitives.cpp
index cfad6f6..6b6f5f5 100644
--- a/LocomotorPrimitives.cpp
+++ b/LocomotorPrimitives.cpp
@@ -13,17 +13,15 @@
#define FIXED_IN_SPACE 1
#define NO_SIM 0
+clock_t ts_start;
+
static const std::string MODEL_NAME = "LocomotorPrimitives";
-// Define the initial and final simulation time
-static const double initialTime = 0.0;
-static const double finalTime = 2.0;
-static void constructModel(OpenSim::Model &model, std::string actDataFile)
+static void constructModel(OpenSim::Model &model, OpenSim::Storage actData)
{
std::cout << "Constructing " << MODEL_NAME << " model" << std::endl;
// Define controller for the model
- OpenSim::Storage actData(actDataFile);
LocomotorPrimitivesController *control = new LocomotorPrimitivesController(actData, 0.01);
control->setActuators(model.updActuators());
model.addController(control);
@@ -49,7 +47,7 @@ static void constructModel(OpenSim::Model &model, std::string actDataFile)
std::cout << "Finished constructing model" << std::endl;
}
-void simulateModel(OpenSim::Model &model)
+void simulateModel(OpenSim::Model &model, const double initialTime, const double finalTime)
{
if (NO_SIM) {
std::cout << "Skipping simulation as per NO_SIM=" << NO_SIM << std::endl;
@@ -63,7 +61,7 @@ void simulateModel(OpenSim::Model &model)
std::cout << " + Creating integrator" << std::endl;
// Create the integrator and manager for the simulation
SimTK::RungeKuttaMersonIntegrator integrator(model.getMultibodySystem());
- integrator.setAccuracy(1.0e-4);
+ integrator.setAccuracy(1.0e-3);
std::cout << " + Creating simulation manager" << std::endl;
LocomotorPrimitivesManager manager(model, integrator);
@@ -71,6 +69,10 @@ void simulateModel(OpenSim::Model &model)
// Integrate from initial time to final time
manager.setInitialTime(initialTime);
manager.setFinalTime(finalTime);
+
+ std::cout << "=== MODEL SUMMARY ===" << std::endl;
+ model.printDetailedInfo(si, std::cout);
+ std::cout << "=== END MODEL SUMMARY ===" << std::endl << std::endl;
std::cout << " + Integrating from " << std::fixed << initialTime << " to " << std::fixed << finalTime << std::endl;
manager.integrate(si);
@@ -93,7 +95,7 @@ static void usage()
int main(int argc, char **argv)
{
- clock_t ts_start = clock();
+ ts_start = clock();
/* set default values (to work on windows) */
std::string modelFile = FIXED_IN_SPACE ? "../../locomotor-primitives-fixed.osim" : "../../locomotor-primitives.osim";
@@ -117,16 +119,27 @@ int main(int argc, char **argv)
}
}
- std::cout << "Starting simulation " + MODEL_NAME << " with (" << modelFile << ", " << dataFile << ")" << std::endl;
+ OpenSim::Storage actData(dataFile);
+ const double initialTime = actData.getFirstTime();
+ const double finalTime = actData.getLastTime();
+
+ if (initialTime < 0 || finalTime < 0 || finalTime <= initialTime) {
+ std::cerr << "invalid time range in data file: " << initialTime << " - " << finalTime << std::endl;
+ exit(-1);
+ }
+
+ std::cout << "Starting simulation " + MODEL_NAME << " with (" << modelFile << ", " << dataFile << ") from time "
+ << initialTime << " to " << finalTime << std::endl;
try {
// Create an OpenSim model and set its name
OpenSim::Model osimModel(modelFile);
- osimModel.setName(MODEL_NAME);
- constructModel(osimModel, dataFile);
+ osimModel.setName(MODEL_NAME);
osimModel.setUseVisualizer(false);
- simulateModel(osimModel);
+
+ constructModel(osimModel, actData);
+ simulateModel(osimModel, initialTime, finalTime);
} catch (OpenSim::Exception ex) {
std::cout << ex.getMessage() << std::endl;
std::cin.get();