Repository navigation
Expand file tree
/
Copy pathphys_math.h
More file actions
56 lines (45 loc) · 1.34 KB
/
Copy pathphys_math.h
File metadata and controls
56 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
# pragma once
typedef enum ics { // ics = initial conditions
M1, M2,
L1, L2,
T1, T2
} ics_t;
// holds user-given constants
typedef struct constants {
double m_1; // mass at end of 1st pendulum in kg
double m_2; // mass at end of 2nd pendulum in kg
double l_1; // length of 1st pendulum in meters
double l_2; // length of 2nd pendulum in meters
} constants_t;
// holds pendulum angles and their 1st derivatives
typedef struct state {
double theta_1;
double theta_2;
double omega_1;
double omega_2;
} state_t;
// holds 1st and 2nd derivatives of pendulum angles
typedef struct deriv {
double dtheta_1;
double dtheta_2;
double d2theta_1;
double d2theta_2;
} deriv_t;
// position in cartesian coordinates
typedef struct cart {
double x;
double y;
} cart_t;
// converts angle from degrees to radians
double deg_to_rad(double theta_deg);
// converts angle from polar to cartesian coordinates
void polar_to_car(double theta, double length, cart_t *coords);
// takes state and returns the derivative of each state variable
deriv_t deriv(state_t *s, constants_t *c);
// integrates using RK4 method to predict the state for given timestep
void runge_kutta_4(state_t *s, constants_t *c, double t);