Skip to content

Commit aeed8a5

Browse files
MarkusMarkus
Markus
authored and
Markus
committed
Integrated serial_config, some changes with structs
1 parent a45937f commit aeed8a5

12 files changed

+442
-426
lines changed

.vscode/c_cpp_properties.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
"cppStandard": "c++17"
2727
}
2828
],
29-
"version": 3
29+
"version": 4
3030
}

main/calc.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ int readTPSVoltage(int voltage)
3333
// Mapping boost sensor voltage to percentage
3434
int readBoostVoltage(int voltage)
3535
{
36-
37-
int result = map(voltage, initBVoltage, 3100, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
36+
int result = voltage * 700/2.95;
37+
//int result = map(voltage, initBVoltage, 3100, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
3838
return result;
3939
}
4040

4141
int readExPresVoltage(int voltage)
4242
{
43-
44-
int result = map(voltage, initEVoltage, 5000, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
43+
int result = voltage * 700/4.6;
44+
//int result = map(voltage, initEVoltage, 5000, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
4545
return result;
4646
}
4747

main/config.cpp

+21-23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Environment configuration
55

6+
boolean trans = true;
67
// Stick control
78
boolean stickCtrl = false;
89
// External radio control
@@ -54,28 +55,25 @@ boolean debugEnabled = true;
5455
// Datalogging (enabling this disables debug)
5556
boolean datalogger = true;
5657

57-
struct ConfigParam readConfig()
58-
{
59-
struct ConfigParam config;
60-
config.boostMax = 700; // boost sensor max kpa
61-
config.boostDrop = 50; // kpa to drop on shifts
62-
config.boostSpring = 120; // kpa for wastegate spring pressure
63-
config.fuelMaxRPM = 2000; // RPM limit to turn on fuel pumps
64-
config.maxRPM = 7000; // Max engine RPM
65-
config.tireWidth = 195;
66-
config.tireProfile = 65;
67-
config.tireInches = 15;
68-
config.diffRatio = 3.27;
69-
config.rearDiffTeeth = 29; // number of teeth in diff
70-
config.nextShiftDelay = 2000; // ms. to wait before next shift to avoid accidental overshifting.
71-
config.maxSlip = 0.5; // Maximum allowed slip before error
72-
config.stallSpeed = 2200; // torque converter stall speed
73-
config.batteryLimit = 11500; // battery voltage limit in 11.5v
74-
config.firstTccGear = 2; // first gear when tcc is used.
75-
config.triggerWheelTeeth = 6; // number of teeth in trigger wheel for RPM calculation
76-
config.tpsAgre = 2; // 1-10 how aggressive slope tps has
77-
return config;
78-
}
58+
struct ConfigParam config = {
59+
.boostMax = 700, // boost sensor max kpa
60+
.boostDrop = 50, // kpa to drop on shifts
61+
.boostSpring = 120, // kpa for wastegate spring pressure
62+
.fuelMaxRPM = 2000, // RPM limit to turn on fuel pumps
63+
.maxRPM = 7000, // Max engine RPM
64+
.tireWidth = 195,
65+
.tireProfile = 65,
66+
.tireInches = 15,
67+
.rearDiffTeeth = 29, // number of teeth in diff
68+
.nextShiftDelay = 2000, // ms. to wait before next shift to avoid accidental overshifting.
69+
.stallSpeed = 2200, // torque converter stall speed
70+
.batteryLimit = 11500, // battery voltage limit in 11.5v
71+
.firstTccGear = 2, // first gear when tcc is used.
72+
.triggerWheelTeeth = 6, // number of teeth in trigger wheel for RPM calculation
73+
.tpsAgre = 2, // 1-10 how aggressive slope tps has
74+
.diffRatio = 3.27,
75+
.maxSlip = 0.5 // Maximum allowed slip before error
76+
};
7977

8078
// End of environment conf
8179

@@ -93,4 +91,4 @@ boolean speedFault = false;
9391
// fault mode for battery fault
9492
boolean batteryFault = false;
9593
// fault mode for excess slip
96-
boolean slipFault = false;
94+
boolean slipFault = false;

main/core.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ double lastShiftPoint;
4242
// Send PWM signal to defined solenoid in transmission conductor plate.
4343
void switchGearStart(int cSolenoid, int spcVal, int mpcVal)
4444
{
45-
struct ConfigParam config = readConfig();
4645
delaySinceLast = millis() - shiftStopTime;
4746

4847
if (debugEnabled)
@@ -80,7 +79,6 @@ void switchGearStart(int cSolenoid, int spcVal, int mpcVal)
8079

8180
void doPreShift()
8281
{
83-
struct ConfigParam config = readConfig();
8482
struct SensorVals sensor = readSensors();
8583

8684
// Things to do before actual shift, example is for waiting boost to settle to the target. (boostControl should let it drop in this scenario).
@@ -424,7 +422,6 @@ void decideGear(Task *me)
424422
int moreGear = gear + 1;
425423
int lessGear = gear - 1;
426424
struct SensorVals sensor = readSensors();
427-
struct ConfigParam config = readConfig();
428425

429426
// Determine speed related downshift and upshift here.
430427
int autoGear = readMap(gearMap, sensor.curTps, sensor.curSpeed);
@@ -620,7 +617,6 @@ int gearFromRatio(float inputRatio)
620617
float getGearSlip()
621618
{
622619
struct SensorVals sensor = readSensors();
623-
struct ConfigParam config = readConfig();
624620
static float maxRatio[5] = {0.00, 0.00, 0.00, 0.00, 0.00}, minRatio[5] = {0.00, 0.00, 0.00, 0.00, 0.00};
625621
float slip;
626622

@@ -640,7 +636,6 @@ float getGearSlip()
640636
void faultMon(Task *me)
641637
{
642638
struct SensorVals sensor = readSensors();
643-
struct ConfigParam config = readConfig();
644639

645640
if (sensor.curSlip > config.maxSlip && sensor.curRPM > config.stallSpeed)
646641
{

main/include/config.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
12
struct ConfigParam
23
{
3-
int boostMax, boostDrop, boostSpring, fuelMaxRPM, tireWidth, tireProfile, tireInches, maxRPM, nextShiftDelay, stallSpeed, maxSlip, batteryLimit, firstTccGear, rearDiffTeeth, triggerWheelTeeth, tpsAgre;
4-
float diffRatio;
4+
int boostMax, boostDrop, boostSpring, fuelMaxRPM, maxRPM, tireWidth, tireProfile, tireInches, rearDiffTeeth, nextShiftDelay, stallSpeed, batteryLimit, firstTccGear, triggerWheelTeeth, tpsAgre;
5+
float diffRatio, maxSlip;
56
};
67

7-
struct ConfigParam readConfig();
8+
extern struct ConfigParam config;

main/include/input.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern boolean truePower;
3535
extern boolean tccLock;
3636
extern boolean stick;
3737
extern boolean autoGear;
38-
extern boolean configMode;
38+
extern boolean tpsConfigMode;
3939
extern double lastShiftPoint;
4040
extern boolean tpsInitPhase1, tpsInitPhase2;
4141
extern byte page;

main/include/serial_config.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <Arduino.h>
2+
#include <SoftTimer.h>
3+
4+
extern boolean boostSensor;
5+
extern boolean debugEnabled;
6+
extern boolean boostLimit;
7+
extern boolean fullAuto;
8+
extern boolean fuelPumpControl;
9+
extern boolean radioEnabled;
10+
extern boolean stickCtrl;
11+
extern boolean horn;
12+
extern boolean manual;
13+
extern boolean truePower;
14+
extern boolean tccLock;
15+
extern boolean stick;
16+
extern boolean autoGear;
17+
extern boolean adaptive;
18+
extern boolean evalGear;
19+
extern boolean tpsSensor;
20+
extern boolean boostSensor;
21+
extern boolean debugEnabled;
22+
extern boolean boostLimit;
23+
extern boolean diffSpeed;
24+
extern boolean rpmSpeed;
25+
extern boolean batteryMonitor;
26+
extern boolean exhaustPresSensor;
27+
extern boolean datalogger;
28+
extern boolean w124speedo;
29+
extern boolean w124rpm;
30+
extern struct ConfigParam config;
31+
void pollConfigMode();
32+
void getFeatures();
33+
void setFeatures(int asset, int value);
34+
void getConfig();
35+
void setConfig(int asset, int value);
36+
void setConfigFloat(int asset, float fvalue);
37+
void serialConfig();
38+
void serialWatch(Task* me);

main/input.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ byte wantedGear = 100;
1818
const double Kp = 7; //80,21 Pid Proporional Gain. Initial ramp up i.e Spool, Lower if over boost
1919
double Ki = 20; //40,7 Pid Integral Gain. Overall change while near Target Boost, higher value means less change, possible boost spikes
2020
const double Kd = 0; //100, 1 Pid Derivative Gain.
21-
boolean garageShift, garageShiftMove, configMode, tpsInitPhase1, tpsInitPhase2 = false;
21+
boolean garageShift, garageShiftMove, tpsConfigMode, tpsInitPhase1, tpsInitPhase2 = false;
2222
double garageTime, lastShift, lastInput;
2323
int lockVal = 0;
2424
/*
@@ -209,7 +209,6 @@ void boostControl(Task *me)
209209
if (boostLimit)
210210
{
211211
struct SensorVals sensor = readSensors();
212-
struct ConfigParam config = readConfig();
213212
pidBoost = sensor.curBoost;
214213
pidBoostLim = sensor.curBoostLim;
215214
myPID.setBangBang(100, 50);
@@ -261,7 +260,6 @@ void fuelControl(Task *me)
261260
if (fuelPumpControl)
262261
{
263262
struct SensorVals sensor = readSensors();
264-
struct ConfigParam config = readConfig();
265263

266264
if ((sensor.curRPM > config.fuelMaxRPM || millis() < 5000) && !fuelPumps)
267265
{
@@ -293,7 +291,6 @@ void fuelControl(Task *me)
293291
void polltrans(Task *me)
294292
{
295293
struct SensorVals sensor = readSensors();
296-
struct ConfigParam config = readConfig();
297294
unsigned int shiftDelay = 2000;
298295

299296
if (shiftBlocker)
@@ -594,12 +591,12 @@ void radioControl()
594591
}
595592
else if (readData == 101)
596593
{
597-
configMode = true;
594+
tpsConfigMode = true;
598595
tpsInitPhase1, tpsInitPhase2 = false;
599596
}
600597
else if (readData == 201)
601598
{
602-
configMode = false;
599+
tpsConfigMode = false;
603600
}
604601
else if (readData == 150)
605602
{

main/main.ino

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "include/core.h"
3232
#include "include/input.h"
3333
#include "include/ui.h"
34+
#include "include/serial_config.h"
3435
#include <EEPROM.h>
3536
#include <SoftTimer.h>
3637
#include <SPI.h>
@@ -47,6 +48,7 @@ Task pollTrans(50, polltrans); // 50ms to check transmission state (t
4748
Task pollFuelControl(1000, fuelControl); // 1000ms for fuel pump control
4849
Task pollBoostControl(100, boostControl); // 100ms for boost control*/
4950
Task pollFaultMon(10, faultMon); // 10ms Fault monitor
51+
Task pollSerialWatch(100, serialWatch);
5052

5153
void setup()
5254
{
@@ -189,4 +191,5 @@ void setup()
189191
SoftTimer.add(&pollTrans);
190192
SoftTimer.add(&pollFuelControl);
191193
SoftTimer.add(&pollBoostControl);
194+
SoftTimer.add(&pollSerialWatch);
192195
}

0 commit comments

Comments
 (0)