The steps covered in part two are:
Using the ControllableSpring (toyLeg_example.cpp)
We can now use the ControllableSpring class in an example to see its effects. The toyLeg_example.cpp file we have provided implements a toy leg model that is driven by a PistonActuator (see toyLeg figure below).The model is built up in the sequence ground->linkage1->linkage2->block with pin joints between all the segments. The block is constrained to move only in the vertical direction. A PistonActuator called "piston" acts between the distal end of linkage1 and the center of the block. We will modify the main() routine to replace the piston actuator with a variable stiffness spring.
Ready toyLeg_example.cpp to use the ControllableSpring
Open the toyLeg_example.cpp file, if you have not already done so. Add the ControllableSpring class to the included files as shown below.
Within Visual Studios, locate the Actuators_examples project. Right click it and select "Build" in order to rebuild toyLeg_example.cpp and force the first build of ControllableSpring.h. You will need to switch from "Debug" to either "Release" or "RelWithDebInfo" if you do not have debuggable OpenSim libraries with which to link.
Add a ControllableSpring to the model
Find the line after the piston is added to the model. At this location, create a ControllableSpring. Set it up to have the identical geometry as the piston, and add it to the model.
We will use prescribed controller for the toy leg model, we give the piston actuator a constant function and the spring actuator a piece-wise linear function to simulate change in stiffness.
Save the resulting motion as a different file
Change the Save Results section in order to print the resulting toyLeg kinematics under a new file name.
Build and run the example
- Build the Actuator_examples project again (see Section 188.8.131.52 above).
- Then build the INSTALL project.
- Make sure that the <OpenSim2.0_intall_dir>/bin directory appears at the front of your PATH. To check and/or set your PATH, go to Start -> System Properties (or System). Click on the Advanced tab and then select the Environment Variables button.
- Navigate to the install directory and run the executable file, toyLeg_example. After running the executable, use the GUI to open the model toyLeg.osim and load the new motion file (SpringActuatedLeg_states_degrees.mot). Upon visualizing the motion, you should see the block oscillate at different magnitudes and frequencies as the spring stiffness is varied over time.