2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file engine_math.h
|
|
|
|
*
|
|
|
|
* @date Jul 13, 2013
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ENGINE_MATH_H_
|
|
|
|
#define ENGINE_MATH_H_
|
|
|
|
|
|
|
|
#include "engine_configuration.h"
|
|
|
|
|
|
|
|
#include "ec2.h"
|
|
|
|
#include "trigger_structure.h"
|
|
|
|
#include "table_helper.h"
|
|
|
|
#include "engine.h"
|
|
|
|
|
2015-01-01 15:04:13 -08:00
|
|
|
// todo: this value is too low for 6 cyl engine, get it back to 60
|
|
|
|
#define OUTPUT_SIGNAL_MAX_SIZE 90
|
|
|
|
|
|
|
|
typedef ArrayList<OutputSignal, OUTPUT_SIGNAL_MAX_SIZE> OutputSignalList;
|
|
|
|
|
2014-11-12 06:03:14 -08:00
|
|
|
#define INJECTOR_PIN_BY_INDEX(index) (io_pin_e) ((int) INJECTOR_1_OUTPUT + (index))
|
|
|
|
|
2014-11-25 09:05:03 -08:00
|
|
|
void findTriggerPosition(
|
2014-11-12 13:05:43 -08:00
|
|
|
event_trigger_position_s *position, float angleOffset DECLARE_ENGINE_PARAMETER_S);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
int isInjectionEnabled(engine_configuration_s *engineConfiguration);
|
|
|
|
|
2015-01-01 13:04:22 -08:00
|
|
|
void initializeIgnitionActions(float advance, float dwellAngle,
|
|
|
|
IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-11-25 08:04:15 -08:00
|
|
|
/**
|
|
|
|
* @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke
|
|
|
|
* I guess this implementation would be faster than 'angle % engineCycle'
|
|
|
|
*/
|
|
|
|
#define fixAngle(angle) \
|
|
|
|
while (angle < 0) \
|
|
|
|
angle += CONFIG(engineCycle); \
|
|
|
|
while (angle >= CONFIG(engineCycle)) \
|
|
|
|
angle -= CONFIG(engineCycle);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-09-12 08:05:18 -07:00
|
|
|
/**
|
|
|
|
* @return time needed to rotate crankshaft by one degree, in milliseconds.
|
2014-11-24 11:03:17 -08:00
|
|
|
* @deprecated use at least Us, maybe even Nt
|
2014-09-12 08:05:18 -07:00
|
|
|
*/
|
2014-11-24 11:03:17 -08:00
|
|
|
#define getOneDegreeTimeMs(rpm) (1000.0f * 60 / 360 / (rpm))
|
2014-09-12 08:05:18 -07:00
|
|
|
|
|
|
|
/**
|
2014-12-16 16:03:47 -08:00
|
|
|
* @return float, time needed to rotate crankshaft by one degree, in microseconds.
|
2014-09-12 08:05:18 -07:00
|
|
|
*/
|
|
|
|
#define getOneDegreeTimeUs(rpm) (1000000.0f * 60 / 360 / (rpm))
|
|
|
|
|
2014-12-16 16:03:47 -08:00
|
|
|
/**
|
|
|
|
* @return float, time needed to rotate crankshaft by one degree, in native clicks.
|
|
|
|
*/
|
|
|
|
#define getOneDegreeTimeNt(rpm) (US2NT(1000000) * 60.0f / 360 / (rpm))
|
2014-11-06 17:04:40 -08:00
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
float getCrankshaftRevolutionTimeMs(int rpm);
|
|
|
|
|
2014-11-24 09:03:09 -08:00
|
|
|
#define isCrankingR(rpm) ((rpm) > 0 && (rpm) < engineConfiguration->crankingSettings.crankingRpm)
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-11-24 18:03:34 -08:00
|
|
|
float getEngineLoadT(DECLARE_ENGINE_PARAMETER_F);
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-11-12 13:05:43 -08:00
|
|
|
float getSparkDwellMsT(int rpm DECLARE_ENGINE_PARAMETER_S);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
int getCylinderId(firing_order_e firingOrder, int index);
|
|
|
|
|
|
|
|
void setFuelRpmBin(engine_configuration_s *engineConfiguration, float l, float r);
|
|
|
|
void setFuelLoadBin(engine_configuration_s *engineConfiguration, float l, float r);
|
|
|
|
void setTimingRpmBin(engine_configuration_s *engineConfiguration, float l, float r);
|
|
|
|
void setTimingLoadBin(engine_configuration_s *engineConfiguration, float l, float r);
|
|
|
|
|
|
|
|
void setSingleCoilDwell(engine_configuration_s *engineConfiguration);
|
|
|
|
|
|
|
|
#endif /* ENGINE_MATH_H_ */
|