|
33 | 33 | using namespace OpenSim; |
34 | 34 | using namespace std; |
35 | 35 |
|
36 | | -void testPendulum(); // test manager/integration process |
37 | | -void testPendulumExternalLoad(); // test application of external loads point in pendulum |
38 | | -void testPendulumExternalLoadWithPointInGround(); // test application of external loads point in ground |
39 | | -void testArm26(); // now add computation of controls and generation of muscle forces |
40 | | -void testGait2354(); // controlled muscles and ground reactions forces |
41 | | -void testGait2354WithController(); // included additional controller |
| 36 | +void testPendulum(); |
| 37 | +void testPendulumExternalLoad(); |
| 38 | +void testPendulumExternalLoadWithPointInGround(); |
| 39 | +void testArm26(); |
| 40 | +void testGait2354(); |
| 41 | +void testGait2354WithController(); |
| 42 | +void testGait2354WithControllerGUI(); |
| 43 | + |
42 | 44 |
|
43 | 45 | int main() { |
44 | 46 | Object::renameType("Thelen2003Muscle", "Thelen2003Muscle_Deprecated"); |
45 | 47 |
|
46 | | - SimTK::Array_<std::string> failures; |
47 | | - |
48 | | - // test manager/integration process |
49 | | - try { testPendulum(); cout << "\nPendulum test PASSED " << endl; } |
50 | | - catch (const std::exception& e) |
51 | | - { cout << e.what() <<endl; failures.push_back("testPendulum"); } |
52 | | - |
53 | | - // test application of external loads |
54 | | - try { testPendulumExternalLoad(); |
55 | | - cout << "\nPendulum with external load test PASSED " << endl; } |
56 | | - catch (const std::exception& e) |
57 | | - { cout << e.what() <<endl; failures.push_back("testPendulumExternalLoad"); } |
58 | | - |
59 | | - // test application of external loads |
60 | | - try { testPendulumExternalLoadWithPointInGround(); |
61 | | - cout << "\nPendulum with external load and point in ground PASSED " << endl; } |
62 | | - catch (const std::exception& e) |
63 | | - { cout << e.what() <<endl; failures.push_back("testPendulumExternalLoadWithPointInGround"); } |
64 | | - |
65 | | - // now add computation of controls and generation of muscle forces |
66 | | - try { testArm26(); |
67 | | - cout << "\narm26 test PASSED " << endl; } |
68 | | - catch (const std::exception& e) |
69 | | - { cout << e.what() <<endl; failures.push_back("testArm26"); } |
70 | | - |
71 | | - // include applied ground reactions forces |
72 | | - try { testGait2354(); |
73 | | - cout << "\ngait2354 test PASSED " << endl; } |
74 | | - catch (const std::exception& e) |
75 | | - { cout << e.what() <<endl; failures.push_back("testGait2354"); } |
76 | | - |
77 | | - // finally include a controller |
78 | | - try { testGait2354WithController(); |
79 | | - cout << "\ngait2354 with correction controller test PASSED " << endl; } |
80 | | - catch (const std::exception& e) |
81 | | - { cout << e.what() <<endl; failures.push_back("testGait2354WithController"); } |
82 | | - |
83 | | - if (!failures.empty()) { |
84 | | - cout << "Done, with failure(s): " << failures << endl; |
85 | | - return 1; |
86 | | - } |
87 | | - |
88 | | - cout << "Done" << endl; |
89 | | - return 0; |
| 48 | + SimTK_START_TEST("testForward"); |
| 49 | + // test manager/integration process |
| 50 | + SimTK_SUBTEST(testPendulum); |
| 51 | + // test application of external loads point in pendulum |
| 52 | + SimTK_SUBTEST(testPendulumExternalLoad); |
| 53 | + // test application of external loads with point moving in ground |
| 54 | + SimTK_SUBTEST(testPendulumExternalLoadWithPointInGround); |
| 55 | + // now add computation of controls and generation of muscle forces |
| 56 | + SimTK_SUBTEST(testArm26); |
| 57 | + // controlled muscles and ground reactions forces |
| 58 | + SimTK_SUBTEST(testGait2354); |
| 59 | + // included additional controller |
| 60 | + SimTK_SUBTEST(testGait2354WithController); |
| 61 | + // implements steps GUI takes to provide a model |
| 62 | + SimTK_SUBTEST(testGait2354WithControllerGUI); |
| 63 | + SimTK_END_TEST(); |
90 | 64 | } |
91 | 65 |
|
92 | 66 | void testPendulum() { |
@@ -249,3 +223,39 @@ void testGait2354WithController() { |
249 | 223 | CHECK_STORAGE_AGAINST_STANDARD(results, *standard, rms_tols, |
250 | 224 | __FILE__, __LINE__, "testGait2354WithController failed"); |
251 | 225 | } |
| 226 | + |
| 227 | +void testGait2354WithControllerGUI() { |
| 228 | + |
| 229 | + // The following lines are the steps from ForwardToolModel.java that |
| 230 | + // associates the a previous (orgiModel) model with the ForwardTool |
| 231 | + // instead of the Tool loading the model specified in the setup |
| 232 | + ForwardTool forward("subject01_Setup_Forward_Controller.xml"); |
| 233 | + Model origModel(forward.getModelFilename()); |
| 234 | + |
| 235 | + Model* model = new Model(origModel); |
| 236 | + model->initSystem(); |
| 237 | + |
| 238 | + const std::string resultsDir{ "ResultsCorrectionControllerGUI" }; |
| 239 | + |
| 240 | + forward.setResultsDir(resultsDir); |
| 241 | + forward.updateModelForces(*model, ""); |
| 242 | + forward.setModel(*model); |
| 243 | + |
| 244 | + model->initSystem(); |
| 245 | + |
| 246 | + forward.run(); |
| 247 | + |
| 248 | + // For good measure we'll make sure we still get the identical results |
| 249 | + Storage results(resultsDir+"/subject01_states.sto"); |
| 250 | + //Storage standard("std_subject01_walk1_states.sto"); |
| 251 | + Storage standard("ResultsCorrectionController/subject01_states.sto"); |
| 252 | + |
| 253 | + int nstates = forward.getModel().getNumStateVariables(); |
| 254 | + int nq = forward.getModel().getNumCoordinates(); |
| 255 | + std::vector<double> rms_tols(2 * nstates, SimTK::SqrtEps); |
| 256 | + |
| 257 | + CHECK_STORAGE_AGAINST_STANDARD(results, standard, rms_tols, |
| 258 | + __FILE__, __LINE__, "testGait2354WithControllerGUI failed"); |
| 259 | + |
| 260 | + delete model; |
| 261 | +} |
0 commit comments