forked from Pitt-RAS/micromouse-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensors_encoders.cpp
38 lines (29 loc) · 917 Bytes
/
sensors_encoders.cpp
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
#include <Arduino.h>
#include <EncoderMod.h>
#include "conf.h"
Encoder left_encoder(ENCODER_A1_PIN, ENCODER_A2_PIN);
Encoder right_encoder(ENCODER_B1_PIN, ENCODER_B2_PIN);
float enc_left_read() {
return (left_encoder.read() * MM_PER_STEP);
}
float enc_right_read() {
return (right_encoder.read() * MM_PER_STEP);
}
void enc_left_write(float new_distance) {
left_encoder.write( (int32_t)rint(new_distance / MM_PER_STEP) );
}
void enc_right_write(float new_distance) {
right_encoder.write( (int32_t)rint(new_distance / MM_PER_STEP) );
}
float enc_left_velocity() {
return (1000 * left_encoder.stepRate() * MM_PER_STEP);
}
float enc_right_velocity() {
return (1000 * right_encoder.stepRate() * MM_PER_STEP);
}
float enc_left_extrapolate() {
return (left_encoder.extrapolate() * MM_PER_STEP);
}
float enc_right_extrapolate() {
return (right_encoder.extrapolate() * MM_PER_STEP);
}