ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
Loading...
Searching...
No Matches
constants.h
Go to the documentation of this file.
1
9
#pragma once
10
11
/* PID CONSTANTS */
12
13
// General Motor PID constants
14
#define PID_M_TAU 1
15
#define PID_M_MIN_OUT -PID_M_MAX_OUT
16
#define PID_M_MAX_OUT 1
17
#define PID_M_MIN_INT -PID_M_MAX_INT
18
#define PID_M_MAX_INT 1
19
20
// Left Motor (M_L) PID Constants
21
#define PID_M_L_KP 0.5
22
#define PID_M_L_KI 7.5
23
#define PID_M_L_KD 0
24
25
// Right Motor (M_R) PID Constants
26
#define PID_M_R_KP PID_M_L_KP
27
#define PID_M_R_KI PID_M_L_KI
28
#define PID_M_R_KD PID_M_L_KD
29
30
// Sensor (S) PID Constants - USED FOR LINE FOLLOW ///////////////////////////
31
#define PID_S_MIN_OUT -PID_S_MAX_OUT
32
#define PID_S_MAX_OUT 1.5
33
#define PID_S_MIN_INT -PID_S_MAX_INT
34
#define PID_S_MAX_INT 0
35
#define PID_S_KI 0
36
37
#define PID_S_TAU 0.001
38
#define PID_S_KP 0.30
39
#define PID_S_KD 0.08
40
41
// 0.4 0.15 - Oscillates high freq when 0 - might need LP
42
43
// Angle (A) PID Constants - USED FOR TURNING
44
#define PID_A_TAU 0.01
45
#define PID_A_MIN_OUT -PID_A_MAX_OUT
46
#define PID_A_MAX_OUT 0.6
47
#define PID_A_MIN_INT -PID_A_MAX_INT
48
#define PID_A_MAX_INT 0
49
#define PID_A_KP 0.2
50
#define PID_A_KI 0.1
51
#define PID_A_KD 0
52
53
54
/* OTHER CONSTANTS */
55
56
// Sensor Array Constants
57
#define SENS_SAMPLE_COUNT 1
// 5 - 311us, 3 - 195us
58
#define SENS_ANGLE_COEFF 1
59
#define SENS_DETECT_RANGE 0.4
60
61
// Line Follow Constants
62
#define LINE_FOLLOW_VELOCITY 2.1
63
#define LINE_FOLLOW_VELOCITY_UTURN 2.1
64
#define LINE_FOLLOW_STOP_DISTANCE 0.3
65
#define UTURN_ANGLE 190
66
67
#define SLOW_ACCEL_TIME 0.4
68
#define SLOW_ACCEL_DIVIDER 2
69
70
#define STOP_DETECT_TIME 1
// s
71
72
// Unused
73
#define SLOW_TURNING_GAIN 0
// Higher Means FASTER
74
#define SLOW_TURNING_THRESH 2
75
76
#define MANUAL_ACCEL_SPEED 0.5
77
#define MANUAL_ACCEL_DISTANCE 0.5
78
#define MANUAL_ACCEL_ANGLE 60
79
80
81
// Square Task Constants
82
#define SQUARE_VELOCITY_SET 0.4
83
#define SQUARE_TURNING_RIGHT_ANGLE 92
84
#define SQUARE_TURNING_LEFT_ANGLE 101.5
85
#define SQUARE_DISTANCE 1.01
86
87
// Control Timing Constants
88
#define CONTROL_UPDATE_RATE 2500
// Hz
89
#define CONTROL_UPDATE_PERIOD (1.0f / CONTROL_UPDATE_RATE)
// Seconds
90
#define CONTROL_UPDATE_PERIOD_US (int)(1'000'000 / CONTROL_UPDATE_RATE)
// Micro Seconds
91
92
// Control Timing Constants
93
#define SENSOR_UPDATE_RATE 5000
// Hz
94
#define SENSOR_UPDATE_PERIOD (1.0f / CONTROL_UPDATE_RATE)
// Seconds
95
#define SENSOR_UPDATE_PERIOD_US (int)(1'000'000 / CONTROL_UPDATE_RATE)
// Micro Seconds
96
97
// Serial Update Timing Constants
98
#define SERIAL_UPDATE_PERIOD 0.02
99
100
#define LOG_SIZE 8'500
101
102
// Encoder Constants
103
#define WHEEL_SEPERATION 0.188
104
#define WHEEL_RADIUS 0.0415
105
#define PULSE_PER_REV 256
106
#define LP_SPEED_B0 0.13575525
107
#define LP_SPEED_B1 0.13575525
108
#define LP_SPEED_A0 0.7284895
109
110
// 2 Hz Pole Freq:
111
// Filter coefficients b_i: [0.0591174 0.0591174]
112
// Filter coefficients a_i: [0.88176521]
113
// 5 Hz Pole Freq:
114
// Filter coefficients b_i: [0.13575525 0.13575525]
115
// Filter coefficients a_i: [0.7284895]
116
// 7 Hz Pole Freq:
117
// Filter coefficients b_i: [0.1802684 0.1802684]
118
// Filter coefficients a_i: [0.63946321]
119
120
// Motor Constants
121
#define MOTOR_PWM_FREQ 20000
122
123
// Bluetooth HM10 module default config constants
124
#define BT_BAUD_RATE 9600
125
126
// Maths constant
127
#define PI 3.14159265
include
constants.h
Generated by
1.10.0