-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInterpolate.cpp
57 lines (45 loc) · 1.46 KB
/
Interpolate.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
#include <math.h>
#include <Arduino.h>
#include "HallSensor.h"
#include "MotorController.h"
#define OK 0
#define ERROR 1
HallSensor sensor = HallSensor(25);
float Interpolate::signalMotor (float definedRPMs) {
float targetRPM = definedRPMs[0], prevRPM = definedRPMs[0];
float rateOfChange = (speedFunction(TargetRPM) - speedFunction(currentRPM))/(TargetRPM - currentRPM);
if hasInterpolationStarted() == false {
setStepper(rateOfChange, definedRPMS);
setIterator(5);
setStartInterpolation(true);
}
MotorController.setPercentSpeed(speedFunction(currentRPM+((5-Iterator)*stepper*rateOfChange));
setIterator(getIterator() - 1);
if getIteration() == 0 {
setStartInterpolation(false);
}
}
float Interpolate::speedFunction(float inputSpeed) {
float outputPercent = 450/(4.34+ 50*(e**(-0.0087*(inputSpeed+113.074))));
return outputPercent;
}
int Interpolate::getStepper() {
return stepper;
}
void Interpolate::setStepper(float rateOfChange, float definedRPMs) {
float RPMDifference = float(definedRPMs[0]) - float(definedRPMs[0]);
float stepper = RPMDifference*rateOfChange/5;
return stepper;
}
bool Interpolate::hasInterpolationStarted() {
return startInterpolation;
}
void Interpolate::setStartInterpolation(bool inputBool) {
startInterpolation = inputBool;
}
int Interpolate::getIteration() {
return Iteration;
}
void Interpolate::setIterator(int inputInt) {
Iteration = inputInt;
}