-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.ino
48 lines (36 loc) · 936 Bytes
/
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
#include "pins.h"
#include <VL53L0X.h>
#include <Wire.h>
//for lab 5
// Invert encoder directions if needed
const boolean INVERT_ENCODER_LEFT = true;
const boolean INVERT_ENCODER_RIGHT = true;
// Invert motor directions if needed
const boolean INVERT_MOTOR_LEFT = false;
const boolean INVERT_MOTOR_RIGHT = true;
// 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;
// initial power values
float left_power = 0;
float right_power = 0;
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();
PIDUpdate();
checkEncodersZeroVelocity();
updateDistanceSensors();
}