From 46ce99d01fb63b54ceca4e4558daa61ad1f03c2c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 15 Jan 2013 20:18:57 +0100 Subject: LocomotorPrimitives: Take command line arguments for data and model file --- LocomotorPrimitives.cpp | 51 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/LocomotorPrimitives.cpp b/LocomotorPrimitives.cpp index 0de339f..cfad6f6 100644 --- a/LocomotorPrimitives.cpp +++ b/LocomotorPrimitives.cpp @@ -11,19 +11,19 @@ #include "LocomotorPrimitivesController.h" #define FIXED_IN_SPACE 1 -#define NO_SIM 0 +#define NO_SIM 0 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) +static void constructModel(OpenSim::Model &model, std::string actDataFile) { std::cout << "Constructing " << MODEL_NAME << " model" << std::endl; // Define controller for the model - OpenSim::Storage actData("../../data/adults.sto"); + OpenSim::Storage actData(actDataFile); LocomotorPrimitivesController *control = new LocomotorPrimitivesController(actData, 0.01); control->setActuators(model.updActuators()); model.addController(control); @@ -65,7 +65,7 @@ void simulateModel(OpenSim::Model &model) SimTK::RungeKuttaMersonIntegrator integrator(model.getMultibodySystem()); integrator.setAccuracy(1.0e-4); std::cout << " + Creating simulation manager" << std::endl; - + LocomotorPrimitivesManager manager(model, integrator); // Integrate from initial time to final time @@ -83,16 +83,47 @@ void simulateModel(OpenSim::Model &model) ((OpenSim::ForceReporter &)reporter).getForceStorage().print(MODEL_NAME + "_forces.mot"); } -int main(void) +static void usage() +{ + std::cout << "usage: " << MODEL_NAME << " [OPTION...]" << std::endl << std::endl + << " -d FILE specify .sto datafile to use for muscle activation data" << std::endl + << " -m FILE specify .osim to use as model" << std::endl + << " -h show this help and exit" << std::endl; +} + +int main(int argc, char **argv) { clock_t ts_start = clock(); + /* set default values (to work on windows) */ + std::string modelFile = FIXED_IN_SPACE ? "../../locomotor-primitives-fixed.osim" : "../../locomotor-primitives.osim"; + std::string dataFile = "../../data/adults.sto"; + + for (int i = 1; (i < argc) && (argv[i][0] == '-'); i++) { + switch (argv[i][1]) { + case 'd': + dataFile = argv[++i]; + break; + case 'm': + modelFile = argv[++i]; + break; + case 'h': + usage(); + exit(0); + default: + std::cerr << "unknown option: -" << argv[i][1] << std::endl; + usage(); + exit(-1); + } + } + + std::cout << "Starting simulation " + MODEL_NAME << " with (" << modelFile << ", " << dataFile << ")" << std::endl; + try { // Create an OpenSim model and set its name - std::string modelName = FIXED_IN_SPACE ? "locomotor-primitives-fixed.osim" : "locomotor-primitives.osim"; - OpenSim::Model osimModel("../../" + modelName); + OpenSim::Model osimModel(modelFile); osimModel.setName(MODEL_NAME); - constructModel(osimModel); + constructModel(osimModel, dataFile); osimModel.setUseVisualizer(false); simulateModel(osimModel); @@ -112,7 +143,7 @@ int main(void) std::cout << "main() routine time = " << 1.e3*(clock()-ts_start)/CLOCKS_PER_SEC << "ms" << std::endl; - std::cout << "Simulation " + MODEL_NAME << " completed successfully." << std::endl; + std::cout << "Simulation " + MODEL_NAME << " completed successfully." << std::endl; std::cin.get(); return 0; -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf