@@ -12,12 +12,21 @@ class Kinematics{
12
12
float wheel_track;
13
13
float wheel_diameter;
14
14
float wheel_radius;
15
+ float wheel_circumference;
15
16
float rads_to_rpm;
16
17
float rpm_to_rads;
17
18
float rads_to_degs;
18
19
float degs_to_rads;
19
20
float w;
20
21
22
+ float theta, delta_theta;
23
+ float x, y;
24
+ float delta_left, delta_right;
25
+ float delta_travel;
26
+ float delta_x, delta_y;
27
+ float travel;
28
+
29
+
21
30
22
31
public:
23
32
Kinematics (const float _wheel_track, const float _wheel_diameter){
@@ -29,13 +38,26 @@ class Kinematics{
29
38
wheel_track=_wheel_track;
30
39
wheel_diameter=_wheel_diameter;
31
40
wheel_radius=wheel_diameter/2.0 ;
41
+ wheel_circumference=wheel_diameter*PI;
32
42
33
43
rads_to_rpm=60.0 /(2.0 *PI);
34
44
rpm_to_rads=2.0 *PI/60.0 ;
35
45
36
46
rads_to_degs=180.0 /PI;
37
47
degs_to_rads=PI/180.0 ;
38
48
49
+ theta=0.0 ;
50
+ x=0.0 ;
51
+ y=0.0 ;
52
+
53
+ delta_x=0.0 ;
54
+ delta_y=0.0 ;
55
+ delta_theta=0.0 ;
56
+ delta_left=0.0 ;
57
+ delta_right=0.0 ;
58
+ delta_travel=0.0 ;
59
+ travel=0.0 ;
60
+
39
61
}
40
62
41
63
void forward (const float linear, const float angular){
@@ -67,6 +89,62 @@ class Kinematics{
67
89
return angular_velocity;
68
90
}
69
91
92
+ void updatePose (const float left_rotation, const float right_rotation){
93
+ delta_left=left_rotation*wheel_circumference;
94
+ delta_right=right_rotation*wheel_circumference;
95
+ delta_travel=(delta_left+delta_right)/2.0 ;
96
+ delta_theta=(-delta_left+delta_right)/(2.0 *wheel_track);
97
+ delta_x=delta_travel*cos (theta+delta_theta/2.0 );
98
+ delta_y=delta_travel*sin (theta+delta_theta/2.0 );
99
+ x+=delta_x;
100
+ y+=delta_y;
101
+ travel+=delta_travel;
102
+ }
103
+
104
+ void resetPose (const float initial_x=0.0 , const float initial_y=0.0 , const float initial_theta=0.0 ){
105
+ x=initial_x;
106
+ y=initial_y;
107
+ theta=initial_theta;
108
+ travel=0.0 ;
109
+ delta_x=0.0 ;
110
+ delta_y=0.0 ;
111
+ delta_theta=0.0 ;
112
+ delta_left=0.0 ;
113
+ delta_right=0.0 ;
114
+ delta_travel=0.0 ;
115
+
116
+ }
117
+
118
+ float getX (){
119
+ return x;
120
+ }
121
+
122
+ float getY (){
123
+ return y;
124
+ }
125
+
126
+ float getTheta (){
127
+ return theta;
128
+ }
129
+
130
+ float getTravel (){
131
+ return travel;
132
+ }
133
+
134
+ float getDeltaX (){
135
+ return delta_x;
136
+ }
137
+
138
+ float getDeltaY (){
139
+ return delta_y;
140
+ }
141
+
142
+ float getDeltaTheta (){
143
+ return delta_theta;
144
+ }
145
+
146
+
147
+
70
148
71
149
};
72
150
0 commit comments