CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_EFI/AP_EFI.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#pragma once
17
18
#include "AP_EFI_config.h"
19
20
#if HAL_EFI_ENABLED
21
22
#include <AP_Common/AP_Common.h>
23
#include <AP_Param/AP_Param.h>
24
#include <GCS_MAVLink/GCS_MAVLink.h>
25
#include "AP_EFI_ThrottleLinearisation.h"
26
27
#include "AP_EFI_Backend.h"
28
#include "AP_EFI_State.h"
29
30
31
/*
32
* This library aims to read data from Electronic Fuel Injection
33
* or Engine Control units. It is focused around the generic
34
* internal combustion engine state message provided by the
35
* UAVCAN protocol due to its comprehensiveness, but is extensible
36
* to use other forms of data transfer besides UAVCAN.
37
*
38
*
39
*
40
* Authors: Sriram Sami and David Ingraham
41
* With direction from Andrew Tridgell, Robert Lefebvre, Francisco Ferreira and
42
* Pavel Kirienko.
43
* Thanks to Yonah, SpektreWorks Inc, and HFE International.
44
*/
45
46
class AP_EFI {
47
public:
48
friend class AP_EFI_Backend;
49
50
// For parameter initialization
51
AP_EFI();
52
53
// Initializes backend
54
void init(void);
55
56
// Requests backend to update the frontend. Should be called at 10Hz.
57
void update();
58
59
// Returns the RPM
60
uint32_t get_rpm() const { return state.engine_speed_rpm; }
61
62
// returns enabled state of EFI
63
bool enabled() const { return type != Type::NONE; }
64
65
bool is_healthy() const;
66
67
// return timestamp of last update
68
uint32_t get_last_update_ms(void) const {
69
return state.last_updated_ms;
70
}
71
72
// get a copy of state structure
73
void get_state(EFI_State &state);
74
75
// Parameter info
76
static const struct AP_Param::GroupInfo var_info[];
77
78
// Backend driver types
79
enum class Type : uint8_t {
80
NONE = 0,
81
#if AP_EFI_SERIAL_MS_ENABLED
82
MegaSquirt = 1,
83
#endif
84
#if AP_EFI_NWPWU_ENABLED
85
NWPMU = 2,
86
#endif
87
#if AP_EFI_SERIAL_LUTAN_ENABLED
88
Lutan = 3,
89
#endif
90
// LOWEHEISER = 4,
91
#if AP_EFI_DRONECAN_ENABLED
92
DroneCAN = 5,
93
#endif
94
#if AP_EFI_CURRAWONG_ECU_ENABLED
95
CurrawongECU = 6,
96
#endif
97
#if AP_EFI_SCRIPTING_ENABLED
98
SCRIPTING = 7,
99
#endif
100
#if AP_EFI_SERIAL_HIRTH_ENABLED
101
Hirth = 8,
102
#endif
103
MAV = 9,
104
};
105
106
static AP_EFI *get_singleton(void) {
107
return singleton;
108
}
109
110
// send EFI_STATUS
111
void send_mavlink_status(mavlink_channel_t chan);
112
113
#if AP_SCRIPTING_ENABLED
114
AP_EFI_Backend* get_backend(uint8_t idx) { return idx==0?backend:nullptr; }
115
#endif
116
117
void handle_EFI_message(const mavlink_message_t &msg);
118
119
protected:
120
121
// Back end Parameters
122
AP_Float coef1;
123
AP_Float coef2;
124
125
AP_Float ecu_fuel_density;
126
127
EFI_State state;
128
129
#if AP_EFI_THROTTLE_LINEARISATION_ENABLED
130
AP_EFI_ThrLin throttle_linearisation;
131
#endif
132
133
private:
134
// Front End Parameters
135
AP_Enum<Type> type;
136
137
// Tracking backends
138
AP_EFI_Backend *backend;
139
static AP_EFI *singleton;
140
141
// Semaphore for access to shared frontend data
142
HAL_Semaphore sem;
143
144
// write to log
145
void log_status();
146
};
147
148
namespace AP {
149
AP_EFI *EFI();
150
};
151
152
#endif // HAL_EFI_ENABLED
153
154