2016-07-23 04:36:42 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
control of internal combustion engines (starter, ignition and choke)
|
|
|
|
*/
|
2019-05-20 11:57:13 -03:00
|
|
|
#pragma once
|
2016-07-23 04:36:42 -03:00
|
|
|
|
2022-07-15 08:50:11 -03:00
|
|
|
#include "AP_ICEngine_config.h"
|
|
|
|
|
|
|
|
#if AP_ICENGINE_ENABLED
|
|
|
|
|
2022-02-28 21:19:09 -04:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2022-07-15 08:50:11 -03:00
|
|
|
#include <Filter/LowPassFilter.h>
|
2023-05-12 19:37:41 -03:00
|
|
|
#include <AP_RPM/AP_RPM_config.h>
|
2023-10-26 02:17:19 -03:00
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
#include <AP_Relay/AP_Relay_config.h>
|
|
|
|
|
|
|
|
#if AP_ICENGINE_TCA9554_STARTER_ENABLED
|
|
|
|
#include "AP_ICEngine_TCA9554.h"
|
|
|
|
#endif
|
2016-07-23 04:36:42 -03:00
|
|
|
|
|
|
|
class AP_ICEngine {
|
|
|
|
public:
|
|
|
|
// constructor
|
2023-05-12 19:37:41 -03:00
|
|
|
AP_ICEngine();
|
2016-07-23 04:36:42 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2024-08-03 09:31:39 -03:00
|
|
|
// One time init call
|
|
|
|
void init();
|
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
// update engine state. Should be called at 10Hz or more
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
// check for throttle override
|
2022-07-07 20:53:29 -03:00
|
|
|
bool throttle_override(float &percent, const float base_throttle);
|
2016-07-23 04:36:42 -03:00
|
|
|
|
|
|
|
enum ICE_State {
|
2023-09-08 00:14:03 -03:00
|
|
|
ICE_DISABLED = -1,
|
2016-07-23 04:36:42 -03:00
|
|
|
ICE_OFF=0,
|
|
|
|
ICE_START_HEIGHT_DELAY=1,
|
|
|
|
ICE_START_DELAY=2,
|
|
|
|
ICE_STARTING=3,
|
|
|
|
ICE_RUNNING=4
|
|
|
|
};
|
|
|
|
|
|
|
|
// get current engine control state
|
2023-09-08 00:14:03 -03:00
|
|
|
ICE_State get_state(void) const { return !enable?ICE_DISABLED:state; }
|
2016-07-23 04:36:42 -03:00
|
|
|
|
|
|
|
// handle DO_ENGINE_CONTROL messages via MAVLink or mission
|
2021-07-19 20:53:50 -03:00
|
|
|
bool engine_control(float start_control, float cold_start, float height_delay, uint32_t flags);
|
2019-11-10 07:44:06 -04:00
|
|
|
|
|
|
|
// update min throttle for idle governor
|
|
|
|
void update_idle_governor(int8_t &min_throttle);
|
|
|
|
|
2022-11-09 22:51:18 -04:00
|
|
|
// do we have throttle while disarmed enabled?
|
2023-10-26 02:17:19 -03:00
|
|
|
bool allow_throttle_while_disarmed(void) const;
|
2022-11-09 22:51:18 -04:00
|
|
|
|
2023-12-08 00:30:34 -04:00
|
|
|
#if AP_RELAY_ENABLED
|
|
|
|
// Needed for param conversion from relay numbers to functions
|
|
|
|
bool get_legacy_ignition_relay_index(int8_t &num);
|
|
|
|
#endif
|
|
|
|
|
2019-02-20 02:24:59 -04:00
|
|
|
static AP_ICEngine *get_singleton() { return _singleton; }
|
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
private:
|
2019-02-20 02:24:59 -04:00
|
|
|
static AP_ICEngine *_singleton;
|
|
|
|
|
2023-10-26 02:17:19 -03:00
|
|
|
void set_ignition(bool on);
|
|
|
|
void set_starter(bool on);
|
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
enum ICE_State state;
|
|
|
|
|
2023-05-12 19:37:41 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2021-09-23 22:52:04 -03:00
|
|
|
// filter for RPM value
|
2024-07-27 09:12:50 -03:00
|
|
|
LowPassFilterConstDtFloat _rpm_filter;
|
2021-09-23 22:52:04 -03:00
|
|
|
float filtered_rpm_value;
|
2023-05-12 19:37:41 -03:00
|
|
|
#endif
|
2021-09-23 22:52:04 -03:00
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
// enable library
|
|
|
|
AP_Int8 enable;
|
|
|
|
|
2020-08-11 22:32:44 -03:00
|
|
|
// min pwm on start channel for engine stop
|
|
|
|
AP_Int16 start_chan_min_pwm;
|
|
|
|
|
2023-05-12 19:37:41 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2016-07-23 04:36:42 -03:00
|
|
|
// which RPM instance to use
|
|
|
|
AP_Int8 rpm_instance;
|
2023-05-12 19:37:41 -03:00
|
|
|
#endif
|
2016-07-23 04:36:42 -03:00
|
|
|
|
|
|
|
// time to run starter for (seconds)
|
|
|
|
AP_Float starter_time;
|
|
|
|
|
|
|
|
// delay between start attempts (seconds)
|
|
|
|
AP_Float starter_delay;
|
2024-08-03 09:31:39 -03:00
|
|
|
|
2023-05-12 19:37:41 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2016-07-23 04:36:42 -03:00
|
|
|
// RPM above which engine is considered to be running
|
|
|
|
AP_Int32 rpm_threshold;
|
2023-05-12 19:37:41 -03:00
|
|
|
#endif
|
2019-11-10 07:44:06 -04:00
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
// time when we started the starter
|
|
|
|
uint32_t starter_start_time_ms;
|
|
|
|
|
|
|
|
// time when we last ran the starter
|
|
|
|
uint32_t starter_last_run_ms;
|
|
|
|
|
|
|
|
// throttle percentage for engine start
|
|
|
|
AP_Int8 start_percent;
|
|
|
|
|
2019-04-13 07:13:51 -03:00
|
|
|
// throttle percentage for engine idle
|
|
|
|
AP_Int8 idle_percent;
|
|
|
|
|
2023-05-12 19:37:41 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2019-11-10 07:44:06 -04:00
|
|
|
// Idle Controller RPM setpoint
|
|
|
|
AP_Int16 idle_rpm;
|
|
|
|
|
|
|
|
// Idle Controller RPM deadband
|
|
|
|
AP_Int16 idle_db;
|
|
|
|
|
|
|
|
// Idle Controller Slew Rate
|
|
|
|
AP_Float idle_slew;
|
2023-05-12 19:37:41 -03:00
|
|
|
#endif
|
2023-10-26 02:17:19 -03:00
|
|
|
|
2016-07-23 04:36:42 -03:00
|
|
|
// height when we enter ICE_START_HEIGHT_DELAY
|
|
|
|
float initial_height;
|
|
|
|
|
|
|
|
// height change required to start engine
|
|
|
|
float height_required;
|
|
|
|
|
|
|
|
// we are waiting for valid height data
|
|
|
|
bool height_pending:1;
|
2019-11-10 07:44:06 -04:00
|
|
|
|
2021-07-19 20:53:50 -03:00
|
|
|
bool allow_single_start_while_disarmed;
|
|
|
|
|
2019-11-10 07:44:06 -04:00
|
|
|
// idle governor
|
|
|
|
float idle_governor_integrator;
|
2019-11-29 20:14:17 -04:00
|
|
|
|
|
|
|
enum class Options : uint16_t {
|
2023-09-20 14:08:24 -03:00
|
|
|
DISABLE_IGNITION_RC_FAILSAFE = (1U << 0),
|
|
|
|
DISABLE_REDLINE_GOVERNOR = (1U << 1),
|
|
|
|
THROTTLE_WHILE_DISARMED = (1U << 2),
|
|
|
|
NO_RUNNING_WHILE_DISARMED = (1U << 3),
|
2024-08-15 22:18:05 -03:00
|
|
|
CRANK_DIR_REVERSE = (1U << 4),
|
2019-11-29 20:14:17 -04:00
|
|
|
};
|
|
|
|
AP_Int16 options;
|
2020-08-11 22:31:58 -03:00
|
|
|
|
2022-07-05 03:17:02 -03:00
|
|
|
bool option_set(Options option) const {
|
|
|
|
return (options & uint16_t(option)) != 0;
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:31:58 -03:00
|
|
|
// start_chan debounce
|
2020-07-10 17:36:35 -03:00
|
|
|
uint16_t start_chan_last_value = 1500;
|
2020-08-11 22:31:58 -03:00
|
|
|
uint32_t start_chan_last_ms;
|
2021-09-23 22:52:04 -03:00
|
|
|
|
2023-10-26 02:17:19 -03:00
|
|
|
#if AP_ICENGINE_TCA9554_STARTER_ENABLED
|
|
|
|
AP_ICEngine_TCA9554 tca9554_starter;
|
|
|
|
#endif
|
|
|
|
|
2023-05-12 19:37:41 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2021-09-23 22:52:04 -03:00
|
|
|
// redline rpm
|
|
|
|
AP_Int32 redline_rpm;
|
|
|
|
struct {
|
|
|
|
bool flag;
|
|
|
|
float governor_integrator;
|
|
|
|
float throttle_percentage;
|
|
|
|
} redline;
|
2023-05-12 19:37:41 -03:00
|
|
|
#endif
|
2024-08-03 09:31:39 -03:00
|
|
|
|
|
|
|
// Param conversion function and flag
|
|
|
|
void param_conversion();
|
|
|
|
AP_Int8 param_format_version;
|
2016-07-23 04:36:42 -03:00
|
|
|
};
|
|
|
|
|
2019-02-20 02:24:59 -04:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_ICEngine *ice();
|
|
|
|
};
|
2022-07-15 08:50:11 -03:00
|
|
|
|
|
|
|
#endif // AP_ICENGINE_ENABLED
|