-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotionController.h
156 lines (129 loc) · 4.24 KB
/
MotionController.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* @file MotionController.h
* @author Ryan Johnson ([email protected])
* @brief This class controls the movement of the platform based on the state
* machine that is uses
* @version 0.1
* @date 2020-05-30
*
* @copyright Copyright (c) 2020
*
*/
#ifndef MOTION_CONTROLLER_GUARD_H
#define MOTION_CONTROLLER_GUARD_H
#include "Constants.h"
#include "DisplayControl.h"
#include "HighestCornerAlgorithm.h"
#include "InclinometerModule.h"
#include "MotionStateMachine.h"
#include <stlport.h>
#include <Eigen30.h>
#include <Controllino.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
namespace {
constexpr int k_dispUpdatePeriodMillis = 1000;
/**
* @brief The hydraulic rams in the highest corner algorithm use a different
* numbering convention than the convention used onsite. This map transalates
* the conventions.
*
* @details THe highest corner algorithm's convention is to use the quadrant
* number of a 2d coordinate plane as the ram number. The quadrant is defined by
* sensor pitch representing the y-axis, and sensor roll representing the
* x-axis.
*/
enum class CORNER_REMAPPER {
RAM_1_RAISE = PIN_CAST(Constants::Pins::RAM::RAISE_2),
RAM_1_LOWER = PIN_CAST(Constants::Pins::RAM::LOWER_2),
RAM_2_RAISE = PIN_CAST(Constants::Pins::RAM::RAISE_3),
RAM_2_LOWER = PIN_CAST(Constants::Pins::RAM::LOWER_3),
RAM_3_RAISE = PIN_CAST(Constants::Pins::RAM::RAISE_4),
RAM_3_LOWER = PIN_CAST(Constants::Pins::RAM::LOWER_4),
RAM_4_RAISE = PIN_CAST(Constants::Pins::RAM::RAISE_1),
RAM_4_LOWER = PIN_CAST(Constants::Pins::RAM::LOWER_1)
};
//! "logical" version of the above remapping, for the debug display. The above
//! version is a remapping of actual outputs
enum class CORNER_REMAPPER_LOGICAL {
RAM_1 = 3,
RAM_2 = 0,
RAM_3 = 1,
RAM_4 = 2
};
} // namespace
namespace Motion {
class MotionController {
public:
MotionController(Inclinometer::Module &sensor);
/**
* @brief Set up the motion controller
*
* @return true set up worked
* @return false failed to set up
*/
bool Initialize();
/**
* @brief Requests that the controller transition to raising mode
*/
void RequestRaise();
/**
* @brief Requests that the controller transition to lowering mode
*/
void RequestLower();
/**
* @brief Requests that the controller halts motion
*/
void RequestOff();
/**
* @brief Requests that the controller transition to lowering mode
*/
void RequestClearFaultState();
Eigen::Vector2d GetLastMeasures() { return m_lastSensorMeasures; };
/**
* @brief Steps the controller and state machine (call this iteratively)
*/
void Step();
/**
* @brief Get the State of the state machine
*
* @return MotionStateMachine::STATE current state of the state machine
*/
MotionStateMachine::STATE GetState() { return m_stateMachine.GetState(); }
/**
* @brief Get the Direction of movement
*
* @return MovementDirection
*/
MovementDirection GetDirection() { return m_direction; }
/**
* @brief Shows a brief message on screen, will disappear on next update of
* motion controller
*
* @param line2 text to show on line 2
*/
void PopMessage(char *line2);
private:
Inclinometer::Module &m_sensor;
MotionStateMachine m_stateMachine;
Display::Controller m_displayController;
unsigned long m_lastDispUpdate;
HighestCornerAlgo m_cornerAlgo;
MovementDirection m_direction = NONE;
unsigned long m_lastSensorReadingTimestamp;
unsigned long m_lastSensorReadingUnstable;
Eigen::Vector2d m_lastSensorMeasures;
// Callback hooks from state machine:
void StartMovement();
void StopMovement();
void SetCorners(bool corner1, bool corner2, bool corner3, bool corner4,
bool raising);
void MovementAlgorithmStep();
bool CheckStabilityStep();
// Disp update Step
void DispUpdate();
// Let the state machine access this class' private functions
friend class MotionStateMachine;
};
} // namespace Motion
#endif // MOTION_CONTROLLER_GUARD_H