-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkinematics.h
More file actions
105 lines (75 loc) · 2.18 KB
/
Copy pathkinematics.h
File metadata and controls
105 lines (75 loc) · 2.18 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef _Kinematics_h
#define _Kinematics_h
#define PI 3.142
// Constant variables
const float wheelRad = 40; // mm
const float wheelDia = 80.0;
const float wheelScale = 120.0;
const float gearRatio = 1/120;
const float COUNTS_PER_SHAFT_REVOLUTION = 12.0;
const float COUNTS_PER_WHEEL_REVOLUTION = 1440.0;
const float MM_PER_COUNT = (1 / (wheelDia * PI)) * COUNTS_PER_WHEEL_REVOLUTION;
class Kinematics_c
{
public:
Kinematics_c(); // Constructor, required.
void update(long count_left, long count_right); // should calucate an update to position.
float homeAngle();
float homeAnglez();
void resetTheta();
float getTheta();
float getx_pos();
float gety_pos();
private:
//Private variables and methods go here
float x_pos;
float y_pos;
float theta;
long old_count_left;
long old_count_right;
};
// Required constructor. Initialise variables.
Kinematics_c::Kinematics_c() {
x_pos = 0;
y_pos = 0;
theta = 0;
old_count_left = 0;
old_count_right = 0;
}
void Kinematics_c :: update(long count_left, long count_right) {
long change_left = count_left - old_count_left;
long change_right = count_right - old_count_right;
float leftDist = (float)change_left / MM_PER_COUNT;
float RightDist = (float)change_right / MM_PER_COUNT;
float avgDist = (leftDist + RightDist) / 2.0f;
x_pos = x_pos + avgDist * cos(theta);
y_pos = y_pos + avgDist * sin(theta);
theta = theta + (leftDist - RightDist) / wheelScale;
old_count_left = count_left;
old_count_right = count_right;
return;
}
float Kinematics_c :: homeAngle() {
float angle = (- theta / (2 * PI) * 360) + 165;
//float angle = atan2(y_pos, x_pos);
return angle;
}
float Kinematics_c :: homeAnglez() {
float angle = ( - theta / (2 * PI) * 360 + 355
) ;
//float angle = atan2(y_pos, x_pos);
return angle;
}
void Kinematics_c :: resetTheta() {
theta = 0;
}
float Kinematics_c :: getTheta() {
return theta;
}
float Kinematics_c :: getx_pos() {
return x_pos;
}
float Kinematics_c :: gety_pos() {
return y_pos;
}
#endif