-
Notifications
You must be signed in to change notification settings - Fork 0
/
HighestCornerAlgorithm.h
66 lines (61 loc) · 2.04 KB
/
HighestCornerAlgorithm.h
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
/**
* @file HighestCornerAlgorithm.h
* @author Ryan Johnson ([email protected])
* @brief Calculates the highest corner of the platform based on measured
* inclinometer angles.
* @version 0.1
* @date 2020-05-26
*
* @copyright Copyright (c) 2020
*
*/
#ifndef HIGHEST_CORNER_ALGO_H
#define HIGHEST_CORNER_ALGO_H
/**
* @brief This class calculates the highest (or lowest) corner of a plane given
* roll and pitch angles with configurable hysteresis.
*/
class HighestCornerAlgo {
public:
/**
* @brief Construct a new Highest Corner Algo object
*
* The algorithm's hysteresis is much like a thermostat - it attempts to
* level angles that exceed hystHigh until they fall below hystLow
*
* @param hystLow the lower bound for which to not attempt to correct beyond
* @param hystHigh the upper bound for which to correct deviations that are
* larger
*/
HighestCornerAlgo(double hystLow, double hystHigh)
: corners({false, false, false, false}), lowerbound(hystLow),
upperbound(hystHigh){};
void update(double roll, double pitch);
/**
* @brief Check if a given corner is high or low. Note: Corner 0 is the 1st
* quadrant in an x-y coordinate plane, and the other corners go
* counter-clockwise from there, with Corner 3 being quadrant 4.
*
* @param corner the corner to check
* @param lowestCornerMode true if checking for lowest corner(s), default
* false
* @return true if the corner is high (or low if in lowest corner mode)
* @return false if the corner is low (or high if in lowest corner mode)
*/
bool getCorner(unsigned int corner, bool lowestCornerMode = false)
{
return corners[(((lowestCornerMode) ? 2 : 0) + corner) % 4];
};
private:
bool corners[4];
double lowerbound;
double upperbound;
void resetAll()
{
corners[0] = false;
corners[1] = false;
corners[2] = false;
corners[3] = false;
}
};
#endif