SIM_splashdown is a simulation of a space craft crew module dropping into a body of water.
![Crew Module Picture](Images/CM_picture.png)
## Building the Simulation
In the ```SIM_splashdown ``` directory, type **```trick-CP```** to build the simulation executable. When it's complete, you should see:
```
=== Simulation make complete ===
```
Now **cd** into ```models/CrewModuleGraphics/``` and type **mvn package**. This builds the graphics client for the simulation.
## Running the Simulation
In the SIM_splashdown directory:
```
% S_main_*.exe RUN_test/input.py
```
The Sim Control Panel, and a graphics client called "CM Display" should appear.
Click the Start on the Trick Sim Control Panel.
Click and drag the mouse on the display to change the viewing orientation.
The black and white center of gravity symbol indicates the center of gravity of the vehicle.
The blue and white center of gravity symbol indicates the center of gravity of the water that is displaced by the vehicle, that is: the center of buoyancy.
<!--
| Variable | Definition|
|---|---|
|![](Images/CB_variable.png)| Center of buoyancy, that is, the center of gravity of the displaced water mass.|
|![](Images/CG_variable.png)| Center of mass of the vehicle. [Frame??]|
|![](Images/F_buoyancy_variable.png)| Force of buoyancy acting on the vehicle.|
|![](Images/F_gravity_variable.png)| Force of gravity.|
|![](Images/F_total_variable.png)|Total force acting on the vehicle.|
|![](Images/I_body_variable.png)|Inertia Tensor of the vehicle in the body frame of reference.|
|![](Images/I_world_inverse_variable.png)|Inertia Tensor of the vehicle in the world frame of reference.|
|![](Images/Linear_momentum_variable.png)|Linear momentum of the vehicle.|
|![](Images/R_variable.png)|Body to World rotation matrix.|
|![](Images/Rdot_variable.png)|Body to World rotation matrix derivative with respect to time.|
|![](Images/Torque_variable.png)| Torque acting on the vehicle.|
|![](Images/Volume_displaced_variable.png)| Volume of the water displaced by the vehicle.|
|![](Images/angular_momentum_variable.png)| Angular momentum of the vehicle.|
|![](Images/angular_velocity_variable.png)|Angular velocity of the vehicle.|
|![](Images/g_variable.png)|Acceleration of gravity.|
|![](Images/m_displaced_variable.png)|Mass of displaced water.|
|![](Images/m_vehicle_variable.png)|Mass of vehicle.|
Coordinate systems here are all right-handed. That is, if the right thumb points along the Z-axis, then the fingers move from the X-axis to the Y-axis as you close your hand.
## Body Coordinates
The geometry of the crew module is defined in **body** coordinates.
The origin of this coordinate system is the center of gravity of the vehicle.
Positive Z is toward the top of the vehicle.
## World Coordinates
-->
## Dynamics Model
### Vehicle State
The vehicle state is defined by the following variables. These are calculated by numerically integrating force, velocity, torque, and body rotation rate over time.
<aid=linear_momentum></a>
#### Linear momentum
The linear momentum of the vehicle is determined by integrating the [total force](#total_force) on the vehicle over time.
The total force acting on the crew module is the sum of the [force of gravity](#force_of_gravity), the [force of buoyancy](#force_of_buoyancy), and the [force of drag](#force_of_drag).
By Newton’s 2nd Law, the force of gravity on the vehicle is the [mass of the vehicle](#vehicle_mass) times the [acceleration of gravity](#acceleration_of_gravity).
Buoyancy is a force on an object, that opposes gravity, by a fluid within which it’s immersed. This force is equal to the [mass of the displaced water](#displaced_mass) times the [acceleration of gravity](#acceleration_of_gravity).
The [force of buoyancy](#force_of_buoyancy) acts on the [center of buoyancy](#center_of_buoyancy), that is: the center of mass of the displaced water. So the torque on the vehicle due to buoyancy is:
We won't even pretend this drag torque is accurate. It's simply opposes the [angular velocity](#angular_velocity), as a means of sapping energy from the system, to settle the rocking of the crew module.
The angular velocity of the vehicle is a function of the [angular momentum](#angular_momentum), the vehicle [inertia tensor](#inertia_tensor) and the [vehicle body rotation](#body_rotation).
The body rotation rate is the product of the skew-symetric-matrix form of the [angular velocity](#angular_velocity), and the [body rotation](#body_rotation) matrix.
<aid=Equation-9></a>
![Equation 9](Images/Rdot_equation_12_pt.png)
- **```crewModule.dyn.Rdot```** (double[3][3])
<aid=linear_velocity></a>
#### Linear Velocity
The linear velocity of the vehicle is the [linear momentum](#linear_momentum) of the vehicle divided by its [mass](#vehicle_mass).
In this simulation, the shape of the crew module is defined by a sphere, a cone, and a plane, as shown in the picture below.
![Equation 12](Images/CM_shape.png)
```bool CrewModuleShape::containsPoint(double (&test_point)[3])``` returns ```true``` if the given point is 1) in the sphere, 2) in the cone, and 3) on the correct side of the plane.
The pseudo-function ```inside(double p[3])``` used in the integrals [above](#displaced_volume) represents logic that determines whether a point is within the displaced volume of water. A point is within the displaced volume if 1) it is within the crew module volume, that is ```containsPoint``` returns ```true```, and 2) it is below the surface of the water, that is the z component of the point is less than 0.