trick/trick_source/trick_utils/SAIntegrator/examples/MassSpringDamper
2021-01-27 12:39:52 -06:00
..
images Add periodic impulse to MassSpringDamper sim. Improve README. Fix plot script. 2021-01-05 16:00:52 -06:00
makefile Add new stand alone numerical integration library SAIntegrator #1056 #936 2020-09-27 18:36:49 -05:00
MassSpringDamper.cpp Update MassSpringDamper example for the Tutorial. #1097 2021-01-27 12:39:52 -06:00
plot_position.py Add periodic impulse to MassSpringDamper sim. Improve README. Fix plot script. 2021-01-05 16:00:52 -06:00
README.md Improvements to README similar to those of Orbit sim. 2021-01-06 16:53:00 -06:00

MassSpringDamper

The MassSpringDamper program uses the SA::EulerCromerIntegrator class to simulate a forced mass-spring-damper system.

The mass is chosen to be 1 kg. The damping constant is chosen to be 5 Ns/m. The spring constant is calculated for a frequency of 2 hz. Every 5 seconds, the system is given an impulse of 500 Newtons for 0.005 seconds.

For each numerical integration time-step, the simulation program prints

  1. time (s)
  2. position (m)
  3. velocity (m/s)

to stdout, in Comma Separated Values (CSV) format.

Building & Running the Simulation Program

To compile MassSpringDamper:

$ make

To run it, and generate a CSV file:

$ ./MassSpringDamper > msd.csv

Plotting the Results

The Python script, plot_position.py is provided to plot the results in msd.csv using (Python) matplotlib.

Plot position vs. time as follows:

$ python plot_position.py

MSD

References:

https://en.wikipedia.org/wiki/Mass-spring-damper_model