1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2022/01/05
|
---|
6 | // filename: PlaneStateMachine.h
|
---|
7 | //
|
---|
8 | // author: Gildas Bayard, Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: state machine for plane
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #ifndef PLANESTATEMACHINE_H
|
---|
19 | #define PLANESTATEMACHINE_H
|
---|
20 |
|
---|
21 | #include <Thread.h>
|
---|
22 | #include <Vector2D.h>
|
---|
23 | #include <Vector3D.h>
|
---|
24 | #include <Euler.h>
|
---|
25 | #include <Quaternion.h>
|
---|
26 |
|
---|
27 | namespace flair {
|
---|
28 | namespace core {
|
---|
29 | class FrameworkManager;
|
---|
30 | class AhrsData;
|
---|
31 | class io_data;
|
---|
32 | }
|
---|
33 | namespace gui {
|
---|
34 | class PushButton;
|
---|
35 | class GridLayout;
|
---|
36 | class Tab;
|
---|
37 | class DoubleSpinBox;
|
---|
38 | }
|
---|
39 | namespace filter {
|
---|
40 | class ControlLaw;
|
---|
41 | class NestedSat;
|
---|
42 | class Pid;
|
---|
43 | }
|
---|
44 | namespace sensor {
|
---|
45 | class TargetController;
|
---|
46 | }
|
---|
47 | namespace meta {
|
---|
48 | class MetaDualShock3;
|
---|
49 | class Plane;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | namespace flair {
|
---|
54 | namespace meta {
|
---|
55 |
|
---|
56 | /*! \class PlaneStateMachine
|
---|
57 | *
|
---|
58 | * \brief State machine for UAV
|
---|
59 | * The Thread is created with
|
---|
60 | * the FrameworkManager as parent. FrameworkManager must be created before.
|
---|
61 | * The Thread is synchronized with Ahrs, unless a period is set with SetPeriodUS or
|
---|
62 | * SetPeriodMS
|
---|
63 | */
|
---|
64 |
|
---|
65 | class PlaneStateMachine : public core::Thread {
|
---|
66 | protected:
|
---|
67 |
|
---|
68 | enum class OrientationMode_t { Manual, Custom };
|
---|
69 | const OrientationMode_t &GetOrientationMode(void) const {
|
---|
70 | return orientationMode;
|
---|
71 | }
|
---|
72 | bool SetOrientationMode(const OrientationMode_t &orientationMode);
|
---|
73 |
|
---|
74 | enum class TorqueMode_t { Default, Custom };
|
---|
75 | const TorqueMode_t &GetTorqueMode(void) const { return torqueMode; }
|
---|
76 | bool SetTorqueMode(const TorqueMode_t &torqueMode);
|
---|
77 |
|
---|
78 | enum class Event_t {
|
---|
79 | EnteringFailSafeMode,
|
---|
80 | EnteringControlLoop,
|
---|
81 | Stopped,
|
---|
82 | EmergencyStop,
|
---|
83 | Started,
|
---|
84 | };
|
---|
85 |
|
---|
86 | PlaneStateMachine(sensor::TargetController* controller);
|
---|
87 | ~PlaneStateMachine();
|
---|
88 |
|
---|
89 | const core::Quaternion &GetCurrentQuaternion(void) const;
|
---|
90 |
|
---|
91 | const core::Vector3Df &GetCurrentAngularSpeed(void) const;
|
---|
92 |
|
---|
93 |
|
---|
94 | void EmergencyStop(void);
|
---|
95 | //! Used to signal an event
|
---|
96 | /*!
|
---|
97 | \param event the event which occured
|
---|
98 | */
|
---|
99 | virtual void SignalEvent(Event_t event);
|
---|
100 |
|
---|
101 | virtual const core::AhrsData *GetOrientation(void) const;
|
---|
102 | const core::AhrsData *GetDefaultOrientation(void) const;
|
---|
103 |
|
---|
104 | void EnterFailSafeMode(void);
|
---|
105 | bool ExitFailSafeMode(void);
|
---|
106 |
|
---|
107 | gui::GridLayout *GetButtonsLayout(void) const;
|
---|
108 | virtual void ExtraSecurityCheck(void){};
|
---|
109 | virtual void ExtraCheckJoystick(void){};
|
---|
110 | virtual void ExtraCheckPushButton(void){};
|
---|
111 |
|
---|
112 | // float GetDefaultThrustOffset(void);
|
---|
113 | const core::AhrsData *GetDefaultReferenceOrientation(void) const;
|
---|
114 | virtual const core::AhrsData *GetReferenceOrientation(void);
|
---|
115 |
|
---|
116 | /*!
|
---|
117 | * \brief Compute Custom Torques
|
---|
118 | *
|
---|
119 | * Reimplement this method to use TorqueMode_t::Custom. \n
|
---|
120 | * This method is called internally by PlaneStateMachine, do not call it by
|
---|
121 | *yourself. \n
|
---|
122 | * See GetTorques if you need torques values.
|
---|
123 | *
|
---|
124 | * \param torques custom torques
|
---|
125 | */
|
---|
126 | virtual void ComputeCustomTorques(core::Euler &torques);
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | * \brief Compute Default Torques
|
---|
130 | *
|
---|
131 | * This method is called internally by PlaneStateMachine when using
|
---|
132 | *TorqueMode_t::Default. \n
|
---|
133 | * Torques are only computed once by loop, other calls to this method will use
|
---|
134 | *previously computed torques.
|
---|
135 | *
|
---|
136 | * \param torques default torques
|
---|
137 | */
|
---|
138 | void ComputeDefaultTorques(core::Euler &torques);
|
---|
139 |
|
---|
140 | /*!
|
---|
141 | * \brief Get Torques
|
---|
142 | *
|
---|
143 | * \return torques current torques
|
---|
144 | */
|
---|
145 | // const core::Euler &GetTorques() const;
|
---|
146 |
|
---|
147 |
|
---|
148 | /*!
|
---|
149 | * \brief Add an IODevice to the control law logs
|
---|
150 | *
|
---|
151 | * The IODevice will be automatically logged among the Uz logs,
|
---|
152 | * if logging is enabled (see IODevice::SetDataToLog,
|
---|
153 | *FrameworkManager::StartLog
|
---|
154 | * and FrameworkManager::AddDeviceToLog). \n
|
---|
155 | *
|
---|
156 | * \param device IODevice to log
|
---|
157 | */
|
---|
158 | void AddDeviceToControlLawLog(const core::IODevice *device);
|
---|
159 |
|
---|
160 | /*!
|
---|
161 | * \brief Add an io_data to the control law logs
|
---|
162 | *
|
---|
163 | * The io_data will be automatically logged among the Uz logs,
|
---|
164 | * if logging is enabled (see IODevice::SetDataToLog,
|
---|
165 | *FrameworkManager::StartLog
|
---|
166 | * and FrameworkManager::AddDeviceToLog). \n
|
---|
167 | *
|
---|
168 | * \param data io_data to log
|
---|
169 | */
|
---|
170 | void AddDataToControlLawLog(const core::io_data *data);
|
---|
171 |
|
---|
172 | const sensor::TargetController *GetTargetController(void) const;
|
---|
173 | MetaDualShock3 *GetJoystick(void) const;
|
---|
174 |
|
---|
175 | filter::NestedSat *GetURoll(void);
|
---|
176 | filter::NestedSat *GetUPitch(void);
|
---|
177 | filter::Pid *GetUYaw(void);
|
---|
178 |
|
---|
179 | gui::Tab *setupLawTab, *graphLawTab;
|
---|
180 |
|
---|
181 | private:
|
---|
182 | bool failSafeMode;
|
---|
183 | void SecurityCheck(void);
|
---|
184 | void MandatorySecurityCheck(void);
|
---|
185 | void CheckJoystick();
|
---|
186 | void GenericCheckJoystick();
|
---|
187 | void CheckPushButton(void);
|
---|
188 | void GenericCheckPushButton(void);
|
---|
189 | void Run(void);
|
---|
190 | void StartActuators(void);
|
---|
191 | void StopActuators(void);
|
---|
192 | bool IsValuePossible(float value,std::string desc);
|
---|
193 |
|
---|
194 | Plane *uav;
|
---|
195 | MetaDualShock3 *joy;
|
---|
196 | sensor::TargetController *controller;
|
---|
197 |
|
---|
198 | core::Quaternion currentQuaternion;
|
---|
199 | core::Vector3Df currentAngularSpeed;
|
---|
200 |
|
---|
201 | const core::AhrsData *ComputeReferenceOrientation(void);
|
---|
202 |
|
---|
203 | void ComputeOrientation(void);
|
---|
204 |
|
---|
205 | void ComputeTorques(void);
|
---|
206 | core::Euler currentTorques, savedDefaultTorques;
|
---|
207 | bool needToComputeDefaultTorques;
|
---|
208 |
|
---|
209 | gui::PushButton *button_kill,*button_start_log, *button_stop_log;
|
---|
210 | gui::PushButton *button_start,*button_stop;
|
---|
211 | gui::GridLayout *buttonslayout;
|
---|
212 | gui::DoubleSpinBox *thrust;
|
---|
213 | OrientationMode_t orientationMode;
|
---|
214 | TorqueMode_t torqueMode;
|
---|
215 | bool flagBatteryLow;
|
---|
216 | bool flagConnectionLost;
|
---|
217 | bool flagCriticalSensorLost;
|
---|
218 | bool safeToFly;
|
---|
219 | filter::NestedSat *uRoll, *uPitch;
|
---|
220 | filter::Pid *uYaw;
|
---|
221 | };
|
---|
222 | };
|
---|
223 | };
|
---|
224 | #endif // PLANESTATEMACHINE_H
|
---|