/*
 * id.h
 *
 *  Created on: Jul 28, 2025
 *      Author: herli
 */

#ifndef INC_ID_H_
#define INC_ID_H_

/* 506 033 */
/* DEBUG PARAMETERS*/
#define ENABLE_AUDI_IMMO 1
#define HAS_PREINJECTION 1

#define CYLINDERS 6

/* TIMING COMPENSATIONS */
#define PHI1 25.7

#define TEIN_NOMINAL 1550
#define TEIN_FAULT 879.5

/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_N 4.44
#define FBKW_DEM_MIN -4.44

#define FBKW_FEEDBACK_ZERO 41.67//58.28
#define FBKW_FEEDBACK_MIN -4.17
#define FBKW_FEEDBACK_MAX 16.83

#define FBKW_PID_KP 15	//16
#define FBKW_PID_KI 10	//18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 5	//16
#define FBKW_PID_BIAS 0
#define FBKW_PID_INTEGRAL 20
#define FBKW_PID_MAXRATE 10000

#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5

/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_SEND_ASYNC_RPM 200
#define CAN_EMPF2_INSTANT 0

/* ALL FUELMAP */
#define FM_N_RPM 7
#define FM_N_ME 11
#define FM_N_T 2


/* PEAK AND HOLD */
#define PH_PEAK_DEF 600

/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94

#define INJ_CLOSING_MARGIN 0 //o cero, o 20

// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 350

#define MIN_RPM 20


/* ifdef things */

#if CYLINDERS == 4
    #define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
    #define TW_PERCYL_TEETH 16
#else
	#define TW_PERCYL_TEETH 26
    #error "Unsupported number of cylinders"
#endif


#endif /* INC_ID_H_ */
