Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/Modified_data/realtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

trick.frame_log_on()
trick.real_time_enable()
trick.exec_set_software_frame(0.033)
trick.itimer_enable()

trick.exec_set_enable_freeze(True)
trick.exec_set_freeze_command(True)

simControlPanel = trick.SimControlPanel()
trick.add_external_application(simControlPanel)

47 changes: 47 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/Modified_data/state_data.dr
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
global DR_GROUP_ID
global drg
try:
if DR_GROUP_ID >= 0:
DR_GROUP_ID += 1
except NameError:
DR_GROUP_ID = 0
drg = []

drg.append(trick.DRBinary("StateData"))
drg[DR_GROUP_ID].set_freq(trick.DR_Always)
drg[DR_GROUP_ID].set_cycle(0.001)
drg[DR_GROUP_ID].set_single_prec_only(False)
drg[DR_GROUP_ID].add_variable("dyn.pendulum.pos1[0]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.pos1[1]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.pos2[0]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.pos2[1]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.vel1[0]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.vel1[1]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.vel2[0]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.vel2[1]")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.gravity")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.omega1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.omega2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.omegaDot1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.omegaDot2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.force_remain")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.torque_remain")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.angle1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.angle2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.mass1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.mass2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.radius1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.radius2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.inertia1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.inertia2")

drg[DR_GROUP_ID].add_variable("dyn.pendulum.total_energy")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.potential_energy")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.kinetic_energy")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.angular_momentum1")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.angular_momentum2")
drg[DR_GROUP_ID].add_variable("dyn.pendulum.total_angular_momentum")


trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer)
drg[DR_GROUP_ID].enable()
127 changes: 127 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Double Compound Pendulum


![](images/Picture1_DoubleCompoundPendulumSketch.png)


A double compound pendulum is a mechanical system consisting of two bodies, one which is attached to a fixed base on one end and the other which is attached to the loose end of the first. “Compound” refers to the fact that the mass of the system is not concentrated completely at one point. These pendulums are both free to rotate about their attachment point, provided they maintain the above constraints.


## Simplifications

SIM_DoubleCompoundPendulum will neglect the effects of friction and air resistance. We present a classic example of a chaotic system, as slight variations in initial values can cause drastic differences and unpredictable behavior long term.

The purpose of this sim is to model a double compound pendulum’s movement and at any given point calculate:


1. Angular momentum

2. Potential energy

3. Kinetic energy

4. Total energy

In this simulation, you can set the initial conditions to what you’d like, and the equations within the sim will simulate how the simulation will behave given the starting conditions.

## Changing Inputs to the Simulation

Go to the input file from the SIM_DoubleCompoundPendulum directory


vi RUN_DoubleCompoundPendulum/input.py/


In this file is where you can change the starting angle of the system, the mass values, the lengths of the masses, and the simulation run time.



## Building and Running the Simulation

In order to build a Trick simulation, the Trick-specific command **`trick-CP`** must be run to begin compilation process. **`trick-CP`** is located in the Trick `bin` directory. Run the **`trick-CP`** command in the SIM_DoubleCompoundPendulum directory. Upon successful compulation, the following message will be displayed in the terminal:


=== Simulation make complete ===
To run, type in the terminal while in the SIM_DoubleCompoundPendulum directory:

%S_main_*.exe RUN_test/input.py


## Kinematics of the System

To the motion of this pendulum, we start by getting the kinematic equations associated with it. The following equations present the position in the x and y directions of the center of mass of each mass on the pendulum.


![](images/Picture2_FirstSetofPositionEquations.png)

![](images/Picture3_SecondSetofPositionEquations.png)


Once you have these values, you can differentiate them in order to derive the velocity of each pendulum:


![](images/Picture4_FirstsetofVelocityEquations.png)

![](images/Picture5_SecondsetofVelocityEquations.png)


Finally, you can use these values to derive the potential and kinetic energy of the system.

### Energy in the System

#### Potential Energy

The general equation for potential energy:


![](images/Picture6_GeneralPotentialEnergyEquation.png)


Can be applied to our simulation by just plugging in the values we have for the y components of position.


![](images/Picture7_PotentialEnergywithvariablespluggedin.png)


For the purpose of simplicity in coding, we included 2 variables to make the potential energy equation less hairy.


Hence:

![](images/Picture8_Mu1andMu2.png)

![](images/Picture9_FinalpotentialenergyEquation)


#### Kinetic Energy

When deriving kinetic energy there is both translational and rotational energy, and the equation must account for both. Hence the general equation for kinetic energy is as follows.


![](images/Picture10_GeneralKineticEnergyEquation.png)


If we plug in the position, velocity, and inertia for a slim rod where they belong in this equation, we arrive at an equation for kinetic energy as follows.


![](images/Picture11_KineticEnergywithvariablespluggedin.png)


Using the following trigonometric identities as well as variables to simplify the equation


![](images/Picture12_TrigonometricIdentities.png)

![](images/Picture13_J1andJ2andJ3.png)

We arrive at the equation used in the simulation.

![](images/Picture14_FinalkineticEnergyEquation.png)

## Angular Momentum
Angular Momentum is equal to inertia times the angular velocity of an object. As such, our equation for inertia comes out to:
![](images/Picture15_AngularMomentumFormula.png)

## Results with Default Parameterization
![](images/Picture16_Graphs.png)

91 changes: 91 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/RUN_test/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
################################################################################
# ___ ___ _ _ ___ _ ___ #
# | \ / _ \| | | | - )| | | _| #
# | |) | (_) | |_| |--| | |_| -- #
# |__ / \___/|_____|_-_)|___|___| #
# #
# __ ___ _ ____ _ _ _ _ _ _ _ #
# | _\| _| \ | | \| | | | | | | | | \ / | #
# | _/| --| \| ||) | |_| | |_| |_| | \/ | #
# |_| |___|_|\__|__/|_____|___|_____|_|\/|_| #
# #
# __ ___ ___ ____ #
# __| ___| \ / _ \| __| #
# | ___| |) | (_) | _| #
# |__ |___/ \___/|_| #
# #
# This input creates a double pendulum with DOF: #
# -Creates 2 bodies #
# -Initializes 2 DOF #
################################################################################

# ============================================================================ -
# This file is used to store several quality of life python functions.
# ============================================================================ -
exec(open("Modified_data/state_data.dr").read())
#exec(open("Modified_data/realtime.py").read())

################################################################################
# dyn DATA #
# (NOTE: dyn is our instance of BodySimObject) #
# This builds our objects, and defines their physical properties. #
################################################################################

# ============================================================================ -
# Establish the physical properties of the body...CONSTANTS!
# ============================================================================ -
gravity = 9.81
mass1 = 10
mass2 = 10

length1 = 1.0
length2 = 1.0

radius1 = length1 * 0.5
radius2 = length2 * 0.5

dyn.pendulum.mass1 = mass1
dyn.pendulum.mass2 = mass2

dyn.pendulum.radius1 = radius1
dyn.pendulum.length1 = length1

dyn.pendulum.radius2 = radius2
dyn.pendulum.length2 = length2

dyn.pendulum.gravity = gravity


dyn.pendulum.inertia1 = (1.0/3.0) * mass1 * length1 * length1
dyn.pendulum.inertia2 = (1.0/3.0) * mass2 * length2 * length2
dyn.pendulum.Ja = (0.25 * mass1 * length1 * length1) + (mass2 * length1 * length1) + ((1.0/12.0) * mass1 * length1 * length1)
dyn.pendulum.Jb = ((1.0/12) * mass2 * length2 * length2) + (0.25 * mass2 * length2 * length2)
dyn.pendulum.Jx = 0.5 * mass2 * length1 * length2
dyn.pendulum.mu1 = ((0.5 * mass1) + mass2) * gravity * length2
dyn.pendulum.mu2 = 0.5 * mass2 * gravity * length2



# ============================================================================ -
# Initialize system
# ============================================================================ -

dyn.pendulum.ANGLE1_INIT = 0.7853981633974483
dyn.pendulum.ANGLE2_INIT = 0.7853981633974483

################################################################################
# SIMULATION SET UP #
# This is where we set up the remaining inputs to create a working sim. #
################################################################################

# ============================================================================ -
# getintegrator(integration method, number of variables to be integrated)
# This sets up the integration scheme we use to analyze this system.
# ============================================================================ -
dyn_integloop.getIntegrator(trick.Runge_Kutta_4, 20)

# ============================================================================ -
# This tells the sim to stop after a few seconds
# ============================================================================ -

trick.stop(10.0)
25 changes: 25 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/S_define
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/************************TRICK HEADER*************************
PURPOSE:
( double compound pendulum simulation )
LIBRARY DEPENDENCIES:
((models/src/pendulum.cpp)
)
*************************************************************/

#include "sim_objects/default_trick_sys.sm"
##include "models/include/pendulum.hh"
class PendulumSimObject : public Trick::SimObject {
public:
PENDULUM pendulum;

PendulumSimObject() {
("default_data") pendulum.default_data() ;
("initialization") pendulum.init() ;
("derivative") pendulum.derivative() ;
("integration") trick_ret = pendulum.integ() ;
}
};

PendulumSimObject dyn;
IntegLoop dyn_integloop(0.0001) dyn;

24 changes: 24 additions & 0 deletions trick_sims/SIM_DoubleCompoundPendulum/S_overrides.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#=============================================================================
# Allow user to specify their own package locations.
# - File is skipped if not present
#=============================================================================

#=============================================================================
# Set up the include paths
#=============================================================================

TRICK_CFLAGS := -I${PWD} -I..
TRICK_CXXFLAGS := -I${PWD} -I..


#=============================================================================
# Add target to clean the documents directories of TeX related files.
#=============================================================================
clean_docs:
@rm -f *_log *execution *_hs *_summary
@cd docs; rm -f *.aux *.bbl *.blg *.lof *.log *.lot *.toc
@cd docs/tex; rm -f *.aux *.log
@echo Cleaned documents directory.

spotless: clean_docs

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading