The steps covered in part two are:
Writing the main()
To run a forward dynamics simulation using our controller, we can write a main program (as in Chapter 2). Our main program below initializes the model, attaches a controller to the model, and runs a forward dynamics simulation.
Creating the controller and attaching it to the model
Next in our main program, we create an instance of the TugOfWarPDController, passing it the model we read in as well as values we choose for the position and velocity gains:
Initializing the system
Next, we set the initial states of the system, which include the position and speed values for all the coordinates in the model, as well as the muscle activations and fiber lengths:
Creating the integrator
We create the integrator for the simulation in order to perform the numerical integration of the system equations of motion during the forward dynamics simulation.
Running the simulation
We run the simulation by setting the initial and final times for the integrator and then instructing the manager to integrate starting from the initial state of the system.
At this point, you can run the main program. We can then visualize the result of the forward dynamics simulation to see how well the controller was able to make the model follow the desired trajectory.