@@ -14,22 +14,27 @@ byte wantedGear = 100;
14
14
15
15
// INPUT
16
16
17
- // Pid tuning parameters
18
- const double Kp = 7 ; // 80,21 Pid Proporional Gain. Initial ramp up i.e Spool, Lower if over boost
19
- double Ki = 20 ; // 40,7 Pid Integral Gain. Overall change while near Target Boost, higher value means less change, possible boost spikes
20
- const double Kd = 0 ; // 100, 1 Pid Derivative Gain.
17
+ // Pid tuning parameters, for boostCtrl
18
+ const double boostKp = 7 ; // 80,21 Pid Proporional Gain. Initial ramp up i.e Spool, Lower if over boost
19
+ double boostKi = 20 ; // 40,7 Pid Integral Gain. Overall change while near Target Boost, higher value means less change, possible boost spikes
20
+ const double boostKd = 0 ; // 100, 1 Pid Derivative Gain.
21
+ double pidBoost, boostPWM, pidBoostLim;
22
+ // Load PID controller
23
+ AutoPID boostPID (&pidBoost, &pidBoostLim, &boostPWM, 0 , 255 , boostKp, boostKi, boostKd);
24
+
25
+ #ifdef ECU
26
+ // Pid tuning parameters, for injectionCtrl
27
+ const double injectKp = 7 ; // 80,21 Pid Proporional Gain. Initial ramp up, Lower if over
28
+ double injectKi = 20 ; // 40,7 Pid Integral Gain. Overall change while near Target
29
+ const double injectKd = 0 ; // 100, 1 Pid Derivative Gain.
30
+ double pidInject, injectPWM, pidInjectLim;
31
+ // Load PID controller
32
+ AutoPID injectPID (&pidInject, &pidInjectLim, &injectPWM, 0 , 255 , injectKp, injectKi, injectKd);
33
+ #endif
34
+
21
35
boolean garageShift, garageShiftMove, tpsConfigMode, tpsInitPhase1, tpsInitPhase2 = false ;
22
- double garageTime, lastShift, lastInput;
36
+ double garageTime, lastShift, lastInput, hornPressTime ;
23
37
int lockVal = 0 ;
24
- /*
25
- const double Kp = 200;
26
- double Ki = 100;
27
- const double Kd = 25; //This is not necessarily good idea.
28
- */
29
- double pidBoost, boostPWM, pidBoostLim, hornPressTime;
30
-
31
- // Load PID controller
32
- AutoPID myPID (&pidBoost, &pidBoostLim, &boostPWM, 0 , 255 , Kp, Ki, Kd);
33
38
34
39
// Polling for stick control
35
40
// This is W202 electronic gear stick, should work on any pre-canbus sticks.
@@ -211,8 +216,8 @@ void boostControl(Task *me)
211
216
struct SensorVals sensor = readSensors ();
212
217
pidBoost = sensor.curBoost ;
213
218
pidBoostLim = sensor.curBoostLim ;
214
- myPID .setBangBang (100 , 50 );
215
- myPID .setTimeStep (100 );
219
+ boostPID .setBangBang (100 , 50 );
220
+ boostPID .setTimeStep (100 );
216
221
217
222
if (shiftBlocker && !slipFault && boostLimitShift)
218
223
{
@@ -225,18 +230,18 @@ void boostControl(Task *me)
225
230
{
226
231
pidBoostLim = 0 ;
227
232
}
228
- Ki = 5 ; // New integral gain value; we want change of pressure to be aggressive here.
233
+ boostKi = 5 ; // New integral gain value; we want change of pressure to be aggressive here.
229
234
}
230
235
else
231
236
{
232
237
pidBoostLim = sensor.curBoostLim ;
233
- Ki = 20 ; // New integral gain value; we want change of pressure to be more modest.
238
+ boostKi = 20 ; // New integral gain value; we want change of pressure to be more modest.
234
239
}
235
240
236
241
// Just a sanity check to make sure PID library is not doing anything stupid.
237
242
if (sensor.curBoostLim > 0 && !slipFault && truePower)
238
243
{
239
- myPID .run ();
244
+ boostPID .run ();
240
245
analogWrite (boostCtrl, boostPWM);
241
246
// if (debugEnabled) { Serial.print("BoostPWM = "); Serial.println(boostPWM); }
242
247
}
@@ -555,21 +560,26 @@ int adaptSPC(int mapId, int xVal, int yVal)
555
560
556
561
void injectionControl (Task *me)
557
562
{
563
+ #ifdef ECU
558
564
struct SensorVals sensor = readSensors ();
559
565
int fuelRequire = sensor.curLoad / sensor.curLambda ; // eg. 100% load / 100% lambda = 1x fueling, 100% load / 10% lambda = 10x fueling
560
566
int fuelAmount = readMap (injectionMap, fuelRequire, sensor.curRPM );
561
567
fuelAmount = fuelAmount * 2.55 ;
562
- analogWrite (injectionPin, fuelAmount);
563
-
568
+ injectPID.setBangBang (100 , 50 );
569
+ injectPID.setTimeStep (100 );
570
+ // Read injectionpump travel
571
+ injectPID.run ();
572
+ analogWrite (injectionPin, injectPWM);
564
573
if (debugEnabled)
565
574
{
566
575
Serial.print (" Fueling quantity with load/lambda: " )
567
- Serial.print (sensor.curLoad );
576
+ Serial.print (sensor.curLoad );
568
577
Serial.print (" /" );
569
578
Serial.print (sensor.curLambda );
570
579
Serial.print (" is " );
571
580
Serial.print (fuelAmount);
572
581
}
582
+ #endif
573
583
}
574
584
575
585
void radioControl ()
0 commit comments