This repository was archived by the owner on Jun 19, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsensing.cpp
More file actions
87 lines (65 loc) · 2.07 KB
/
Copy pathsensing.cpp
File metadata and controls
87 lines (65 loc) · 2.07 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// water.cpp
#include <unistd.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#include "sensing.hh"
#include "adc.hh"
// Empty constructor
Sensing::Sensing() {
lampGpio = LAMP_EN;
}
// Empty destructor
Sensing::~Sensing() {}
// Instance
Sensing& Sensing::instance() {
static Sensing inst;
return inst;
}
// Class functions
void Sensing::getResult(DRV8833& motor) {
uint16_t nir_result = 0;
uint16_t vis_result = 0;
result_t new_result;
GPIO_write(AMBER_LED, 1);
// FIXME: stepZero doesn't work
//motor.stepZero(200); // 200 micrometers/sec = 60 RPM
lampSet(true);
usleep(500 * 1000); // Sleep for 500ms to allow lamp to turn on
// Increment through each position and take a reading
for (int i = 0; i < POSITIONS; i++) {
nir_result = AdcExternal::instance().getRawResult(AdcExternal::CH0);
vis_result = AdcExternal::instance().getRawResult(AdcExternal::CH1);
printf("Position %03d:\n", i);
printf(" NIR: %.3f V\n", resultRawToFloat(nir_result));
printf(" Visible: %.3f V\n\n", resultRawToFloat(vis_result));
if (nir_result != -1) {
new_result.nir_results.at(i) = nir_result;
}
if (vis_result != -1) {
new_result.vis_results.at(i) = vis_result;
}
motor.stepSteps(10000/POSITIONS, 60); // 10k is max position
}
lampSet(false);
new_result.time = std::time(nullptr);
results.push(new_result);
GPIO_write(AMBER_LED, 0);
}
inline float Sensing::resultRawToFloat(uint16_t raw_result) {
return static_cast<float>(raw_result) / static_cast<float>(ONE_VOLT);
}
// Set lamp on or off
void Sensing::lampSet(bool on) {
GPIO_write(lampGpio, (on ? GPIO_CFG_OUT_HIGH : GPIO_CFG_OUT_LOW));
lampOn = on;
return;
}
// Toggle lamp
void Sensing::lampToggle(void) {
GPIO_toggle(lampGpio);
lampOn = !lampOn;
return;
}
result_t Sensing::queuePeek(void) {
return results.front();
}