-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.ino
65 lines (52 loc) · 1.4 KB
/
mouse.ino
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
#include "pins.h"
#include <VL53L0X.h>
#include <Wire.h>
// Invert encoder directions if needed
const boolean INVERT_ENCODER_LEFT = false;
const boolean INVERT_ENCODER_RIGHT = false;
// Invert motor directions if needed
const boolean INVERT_MOTOR_LEFT = false;
const boolean INVERT_MOTOR_RIGHT = false;
// Loop count, used for print statements
int count = 0;
// Sensor states
float velocity_angular = 0;
float velocity_linear = 0;
float left_dist;
float right_dist;
float center_dist;
void setup() {
Serial.begin(9600);
hardwareSetup();
}
void loop() {
// Read sensor data
left_dist = getDistanceLeft();
right_dist = getDistanceRight();
center_dist = getDistanceCenter();
velocity_linear = getLinearVelocity();
velocity_angular = getAngularVelocity();
////////////////////////////////////
// Your changes should start here //
////////////////////////////////////
float left_power = 0.2;
float right_power = 0.2;
applyPowerLeft(left_power);
applyPowerRight(right_power);
// Print debug info every 500 loops
if (count % 500 == 0) {
Serial.print(velocity_linear / 100.0);
Serial.print(" ");
Serial.print(velocity_angular);
Serial.print(" ");
Serial.print(left_dist);
Serial.print(" ");
Serial.print(center_dist);
Serial.print(" ");
Serial.print(right_dist);
Serial.println();
}
count++;
checkEncodersZeroVelocity();
updateDistanceSensors();
}