forked from madhephaestus/ESP32AnalogRead
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLewanSoulHardwareManager.cpp
83 lines (65 loc) · 1.79 KB
/
LewanSoulHardwareManager.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
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
/*
* LewanSoulHardwareManager.cpp
*
* Created on: May 19, 2021
* Author: aksha
*/
#include <LewanSoulHardwareManager.h>
#include <Arduino.h>
LewanSoulHardwareManager::LewanSoulHardwareManager() {
// TODO Auto-generated constructor stub
}
LewanSoulHardwareManager::~LewanSoulHardwareManager() {
// TODO Auto-generated destructor stub
}
float LewanSoulHardwareManager::getCurrentValue(int Pin) {
return motors[Pin]->pos_read();
}
bool LewanSoulHardwareManager::isHardwareReady() {
if (!HardwareReady) {
Initialize();
if (digitalRead(0) == 0) {
for (int i = 0; i < num; i++) {
Serial.println("Calibrating " + String(i));
motors[i]->calibrate(startingAngles[i], lowerAngles[i],
upperAngles[i]);
Serial.println("Calibrated " + String(i));
int32_t pos = startingAngles[i] - motors[i]->pos_read();
if (abs(pos) > 24) {
Serial.println("Settling Error of" + String(pos));
return false;
}
}
HardwareReady = true;
}
}
return HardwareReady;
}
void LewanSoulHardwareManager::Initialize() {
if (IsInitialized)
return;
pinMode(0, INPUT_PULLUP);
servoBus.beginOnePinMode(&Serial1, 15);
motors = new LX16AServo*[num];
for (int i = 0; i < num; i++) {
hardwareIndexMap[i] = i;
motors[i] = new LX16AServo(&servoBus, i + 1);
motors[i]->disable();
}
IsInitialized = true;
}
void LewanSoulHardwareManager::SynchronizeMove(int milSec) {
for (int i = 0; i < num; i++) {
float Value = ValMap[i];
//Serial.println("Lewan Soul HW manager value of "+String(i)+" = "+String(Value));
motors[i]->move_time_and_wait_for_sync(Value, milSec+5);
}
servoBus.move_sync_start();
StartTime = millis();
TimeToTake = milSec;
IsRunning = true;
}
bool LewanSoulHardwareManager::IsMoveDone() {
IsRunning = (millis() - StartTime > TimeToTake);
return IsRunning;
}