summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tobias.klauser@uzh.ch>2013-04-09 16:22:45 +0200
committerTobias Klauser <tobias.klauser@uzh.ch>2013-04-09 16:22:45 +0200
commit341623412dbec7cb1eb136ab75c11918bb2b3d96 (patch)
treeb18cfc2443ce9247969b695fa28147bd8b211505
parent4b64fef4c41ae4432eb00b8b814ed4d4d746f794 (diff)
LocomotorPrimitives: Check success of simulation
-rw-r--r--LocomotorPrimitives.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/LocomotorPrimitives.cpp b/LocomotorPrimitives.cpp
index 8ceafea..967513e 100644
--- a/LocomotorPrimitives.cpp
+++ b/LocomotorPrimitives.cpp
@@ -87,19 +87,19 @@ static void constructModel(OpenSim::Model &model, OpenSim::Storage actData)
logger.log("Finished constructing model\n");
}
-void simulateModel(OpenSim::Model &model, const double initial_time,
- const double final_time, double fixed_step_size,
- std::string output_dir)
+int simulateModel(OpenSim::Model &model, const double initial_time,
+ const double final_time, double fixed_step_size,
+ std::string output_dir)
{
if (NO_SIM) {
logger.log("Skipping simulation as per NO_SIM=%d\n", NO_SIM);
- return;
+ return 1;
}
std::string cwd = OpenSim::IO::getCwd();
if (OpenSim::IO::chDir(output_dir) != 0) {
logger.err("Failed to change to output directory %s", output_dir.c_str());
- return;
+ return 1;
}
logger.log("Simulating model %s\n", MODEL_NAME.c_str());
@@ -107,6 +107,13 @@ void simulateModel(OpenSim::Model &model, const double initial_time,
logger.log("+ Initializing system\n");
SimTK::State &si = model.initSystem();
+ if (!model.isValidSystem()) {
+ logger.err("Loaded invalid model. Press ENTER to quit");
+ if (!yes)
+ std::cin.get();
+ return 1;
+ }
+
// std::cout << "=== MODEL SUMMARY ===" << std::endl;
// model.printDetailedInfo(si, std::cout);
// std::cout << "=== END MODEL SUMMARY ===" << std::endl << std::endl;
@@ -129,6 +136,7 @@ void simulateModel(OpenSim::Model &model, const double initial_time,
manager->integrate(si);
} catch (...) {
logger.log("Got exception during integration\n");
+ return 1;
}
// Save the model states from forward integration
@@ -154,6 +162,8 @@ void simulateModel(OpenSim::Model &model, const double initial_time,
// TODO
logger.log("Finished simulating model\n");
+
+ return 0;
}
static void usage()
@@ -222,7 +232,7 @@ int main(int argc, char **argv)
saction.sa_flags = SA_RESTART;
sigaction(SIGINT, &saction, NULL);
- logger.log("Starting simulation %s with model file %s, actuation data file %s\n, fixed step size: %f\n", MODEL_NAME.c_str(), model_file.c_str(), data_file.c_str(), fixed_step_size);
+ logger.log("Starting simulation %s with model file %s, actuation data file %s, fixed step size: %f\n", MODEL_NAME.c_str(), model_file.c_str(), data_file.c_str(), fixed_step_size);
try {
// Create an OpenSim model and set its name
@@ -232,7 +242,12 @@ int main(int argc, char **argv)
osimModel.setUseVisualizer(false);
constructModel(osimModel, actData);
- simulateModel(osimModel, initial_time, final_time, fixed_step_size, output_dir);
+ if (simulateModel(osimModel, initial_time, final_time, fixed_step_size, output_dir)) {
+ logger.err("Something went wrong during simulation. Press ENTER to quit");
+ if (!yes)
+ std::cin.get();
+ return 1;
+ }
} catch (OpenSim::Exception ex) {
logger.err("Exception: %s. Press ENTER to quit", ex.getMessage());
if (!yes)