File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Arduino_Alvik_Firmware alvik;
4
4
5
+ unsigned long tmotor=0 ;
6
+ unsigned long ttask=0 ;
7
+ uint8_t task=0 ;
8
+
5
9
void setup () {
6
10
alvik.begin ();
11
+ ttask=millis ();
12
+ tmotor=millis ();
13
+ task=0 ;
7
14
}
8
15
9
16
void loop () {
10
- alvik.drive (1 ,1 );
11
-
17
+ if (millis ()-tmotor>20 ){
18
+ tmotor=millis ();
19
+ alvik.updateMotors ();
20
+ }
21
+
22
+ if (millis ()-ttask>2000 ){
23
+ ttask=millis ();
24
+ switch (task){
25
+ case 0 :
26
+ alvik.drive (0 ,90 );
27
+ break ;
28
+ case 1 :
29
+ alvik.drive (0 ,0 );
30
+ break ;
31
+ case 2 :
32
+ alvik.drive (0 ,-90 );
33
+ break ;
34
+ case 3 :
35
+ alvik.drive (0 ,0 );
36
+ break ;
37
+ }
38
+ task++;
39
+ if (task>3 ){
40
+ task=0 ;
41
+ }
42
+ }
12
43
}
Original file line number Diff line number Diff line change @@ -608,4 +608,5 @@ void Arduino_Alvik_Firmware::errorLed(const int error_code){
608
608
609
609
void Arduino_Alvik_Firmware::drive (const float linear, const float angular){
610
610
kinematics->forward (linear, angular);
611
+ setRpm (kinematics->getLeftVelocity (),kinematics->getRightVelocity ());
611
612
}
Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ class Kinematics{
16
16
float rpm_to_rads;
17
17
float rads_to_degs;
18
18
float degs_to_rads;
19
+ float w;
19
20
20
21
21
22
public:
22
23
Kinematics (const float _wheel_track, const float _wheel_diameter){
24
+ w=0.0 ;
23
25
left_velocity=0.0 ;
24
26
right_velocity=0.0 ;
25
27
linear_velocity=0.0 ;
@@ -37,8 +39,11 @@ class Kinematics{
37
39
}
38
40
39
41
void forward (const float linear, const float angular){
40
- left_velocity=(2 *linear-angular*wheel_track)/(wheel_diameter);
41
- right_velocity=(2 *linear+angular*wheel_track)/(wheel_diameter);
42
+ w = angular*degs_to_rads;
43
+ left_velocity=(2 *linear-w*wheel_track)/(wheel_diameter);
44
+ left_velocity=rads_to_rpm*left_velocity;
45
+ right_velocity=(2 *linear+w*wheel_track)/(wheel_diameter);
46
+ right_velocity=rads_to_rpm*right_velocity;
42
47
}
43
48
44
49
void inverse (const float left_vel, const float right_vel){
You can’t perform that action at this time.
0 commit comments