-
Notifications
You must be signed in to change notification settings - Fork 1
/
controls.h
70 lines (51 loc) · 1.64 KB
/
controls.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
#ifndef __CONTROLS_H__
#define __CONTROLS_H__
#include "flight_controller.h"
#include "heli.h"
#include <vector>
const int CURVE_CACHE_SIZE = 250;
struct ControlsInput {
float pitch_stick;
float roll_stick;
float yaw_stick;
float throttle_stick;
size_t active_curve_index;
};
class ControllerCurve {
public:
struct Point {
Point(float _in_level, float _out_level):in_level(_in_level), out_level(_out_level) {}
float in_level;
float out_level;
};
ControllerCurve(std::vector<Point> points);
float translate(float level) const;
private:
void add_line_to_cahce(const Point &point_from, const Point &point_to);
float m_cache[CURVE_CACHE_SIZE];
};
class Controls {
public:
Controls(FlightController *flight_controller,
std::vector<ControllerCurve> throttle_curves,
std::vector<ControllerCurve> lift_curves);
ServoData get_servo_data(const ControlsInput &input, float time_delta);
struct Telemetry {
ControlsInput user_input;
ServoData before_controller;
ServoData after_controller;
int active_curve_index;
};
Telemetry get_telemetry();
std::vector<ControllerCurve> get_throttle_curves() { return m_throttle_curves; }
std::vector<ControllerCurve> get_lift_curves() { return m_lift_curves; }
private:
FlightController *m_flight_controller;
std::vector<ControllerCurve> m_throttle_curves;
std::vector<ControllerCurve> m_lift_curves;
// Saved for Telemetry.
ControlsInput m_user_input;
ServoData m_before_flight_controller;
ServoData m_after_flight_controller;
};
#endif // __CONTROLS_H__