Skip to content

Commit b5928a4

Browse files
author
Bjoern Schmidt
committed
code cleanup
1 parent 7be1bc9 commit b5928a4

File tree

7 files changed

+56
-120
lines changed

7 files changed

+56
-120
lines changed

ACAcontrollerState.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ uint16_t ui16_regen_current_max_value = 0;
8383
uint8_t ui8_possible_motor_state = 0;
8484
uint8_t ui8_dynamic_motor_state = 0;
8585
uint8_t ui8_BatteryVoltage = 0; //Battery Voltage read from ADC
86+
uint8_t ui8_battery_voltage_nominal =0;
8687
uint16_t ui16_motor_speed_erps = 0;
8788
uint32_t ui32_erps_filtered = 0; //filtered value of erps
8889
uint16_t ui16_virtual_erps_speed = 0;
@@ -270,6 +271,8 @@ void controllerstate_init(void) {
270271
eepromVal = eeprom_read(OFFSET_BATTERY_VOLTAGE_MAX);
271272
if (eepromVal > 0) ui8_s_battery_voltage_max = eepromVal;
272273

274+
ui8_battery_voltage_nominal = (((uint16_t)(ui8_s_battery_voltage_max-(ui8_s_battery_voltage_max-ui8_s_battery_voltage_min)/2))*ui8_s_battery_voltage_calibration)/256L;
275+
273276
eepromVal = eeprom_read(OFFSET_MOTOR_CONSTANT);
274277
if (eepromVal > 0) flt_s_motor_constant = int2float(eepromVal, 4.0);
275278

ACAcontrollerState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern uint16_t ui16_regen_current_max_value;
5353
extern uint8_t ui8_possible_motor_state;
5454
extern uint8_t ui8_dynamic_motor_state;
5555
extern uint8_t ui8_BatteryVoltage;
56+
extern uint8_t ui8_battery_voltage_nominal;
5657
extern uint16_t ui16_motor_speed_erps;
5758
extern uint16_t ui16_virtual_erps_speed;
5859
extern uint32_t ui32_erps_filtered; //filtered value of erps

OSEC Parameter Configurator.jar

-415 Bytes
Binary file not shown.

config.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#define REGEN_CURRENT_MAX_VALUE 50L
2222
#define MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT 238
2323
#define current_cal_a 46
24-
#define TEMP_CAL_A 1.6
25-
#define TEMP_CAL_B -110.4
2624
#define LEVEL_1 22
2725
#define LEVEL_2 33
2826
#define LEVEL_3 50
@@ -35,7 +33,6 @@
3533
#define P_FACTOR 0.5
3634
#define I_FACTOR 0.2
3735
#define GEAR_RATIO 51L
38-
#define BATTERY_LI_ION_CELLS_NUMBER 13
3936
#define PAS_THRESHOLD 1.9
4037
#define RAMP_START 64000
4138
#define limit_with_throttle_override 35
@@ -50,7 +47,7 @@
5047
#define TQS_CALIB 0.0
5148
#define ACA 4764
5249
#define EEPROM_NOINIT // eeprom will not be cleared
53-
#define EEPROM_INIT_MAGIC_BYTE 128 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
50+
#define EEPROM_INIT_MAGIC_BYTE 177 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
5451
#define ADC_BATTERY_VOLTAGE_K 67
5552
#define ACA_EXPERIMENTAL 128
5653
#define BATTERY_VOLTAGE_MAX_VALUE 208

display.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint8_t ui8_tx_buffer[12];
4444
uint8_t ui8_j;
4545
uint8_t ui8_crc;
4646
uint16_t ui16_wheel_period_ms = 4500;
47-
uint16_t ui16_battery_volts = 36;
47+
uint16_t ui16_battery_bars_calc = 0;
4848
uint8_t ui8_battery_soc = 12;
4949
uint8_t ui16_error;
5050
uint8_t ui8_rx_buffer[13];
@@ -86,17 +86,20 @@ void send_message() {
8686
}
8787

8888
// calc battery pack state of charge (SOC)
89-
ui16_battery_volts = ((uint16_t) ui8_adc_read_battery_voltage()) * ((uint16_t) ui8_s_battery_voltage_calibration);
90-
if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_80)) {
89+
ui16_battery_bars_calc = ui8_adc_read_battery_voltage() - ui8_s_battery_voltage_min;
90+
ui16_battery_bars_calc<<8;
91+
ui16_battery_bars_calc /=(ui8_s_battery_voltage_max-ui8_s_battery_voltage_min);
92+
93+
if (ui16_battery_bars_calc > 200) {
9194
ui8_battery_soc = 16;
9295
}// 4 bars | full
93-
else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_60)) {
96+
else if (ui16_battery_bars_calc > 150) {
9497
ui8_battery_soc = 12;
9598
}// 3 bars
96-
else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_40)) {
99+
else if (ui16_battery_bars_calc > 100) {
97100
ui8_battery_soc = 8;
98101
}// 2 bars
99-
else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_20)) {
102+
else if (ui16_battery_bars_calc > 50) {
100103
ui8_battery_soc = 4;
101104
}// 1 bar
102105
else {
@@ -107,7 +110,7 @@ void send_message() {
107110
// B1: battery level
108111
ui8_tx_buffer [1] = ui8_battery_soc;
109112
// B2: 24V controller
110-
ui8_tx_buffer [2] = (uint8_t) COMMUNICATIONS_BATTERY_VOLTAGE;
113+
ui8_tx_buffer [2] = ui8_battery_voltage_nominal;
111114
// B3: speed, wheel rotation period, ms; period(ms)=B3*256+B4;
112115
ui8_tx_buffer [3] = (ui16_wheel_period_ms >> 8) & 0xff;
113116
ui8_tx_buffer [4] = ui16_wheel_period_ms & 0xff;

main.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,6 @@
2020
#define ADC_MOTOR_TOTAL_CURRENT_MAX_NEGATIVE 70 // +2A
2121
#define MORSE_TOLERANCE 40 // Tolerance for "morse" code detection
2222

23-
//for Kunteng Displays
24-
#define COMMUNICATIONS_BATTERY_VOLTAGE (BATTERY_LI_ION_CELLS_NUMBER * 3.45) // example: 7S battery, should be = 24
25-
26-
// Considering the follow voltage values for each li-ion battery cell
27-
// State of charge | voltage
28-
#define LI_ION_CELL_VOLTS_MAX 4.20
29-
#define LI_ION_CELL_VOLTS_100 4.20
30-
#define LI_ION_CELL_VOLTS_80 4.02
31-
#define LI_ION_CELL_VOLTS_60 3.87
32-
#define LI_ION_CELL_VOLTS_40 3.80
33-
#define LI_ION_CELL_VOLTS_20 3.73
34-
#define LI_ION_CELL_VOLTS_0 3.27
35-
#define LI_ION_CELL_VOLTS_MIN 3.10
36-
37-
#define BATTERY_PACK_VOLTS_100 (LI_ION_CELL_VOLTS_100 * BATTERY_LI_ION_CELLS_NUMBER) * 255
38-
#define BATTERY_PACK_VOLTS_80 (LI_ION_CELL_VOLTS_80 * BATTERY_LI_ION_CELLS_NUMBER) * 255
39-
#define BATTERY_PACK_VOLTS_60 (LI_ION_CELL_VOLTS_60 * BATTERY_LI_ION_CELLS_NUMBER) * 255
40-
#define BATTERY_PACK_VOLTS_40 (LI_ION_CELL_VOLTS_40 * BATTERY_LI_ION_CELLS_NUMBER) * 255
41-
#define BATTERY_PACK_VOLTS_20 (LI_ION_CELL_VOLTS_20 * BATTERY_LI_ION_CELLS_NUMBER) * 255
42-
#define BATTERY_PACK_VOLTS_0 (LI_ION_CELL_VOLTS_0 * BATTERY_LI_ION_CELLS_NUMBER) * 255
43-
44-
// Phase current: max of +-15.5 amps
45-
// 512 --> 15.5 amps
46-
// 1 ADC increment --> 0.030A
47-
// 1 ADC RMS --> 0.03 * 0.707 -- > 0.021A
48-
#define ADC_PHASE_B_CURRENT_STEP 21 // 0.021 * 1000 = 21
49-
#define ADC_PHASE_B_CURRENT_FACTOR_MA 21 // 0,030273437 * 1000 * 0.707
50-
5123

5224
#define PWM_CYCLES_COUNTER_MAX 3000 // higher values assume motor is at standstill.
5325
#define PWM_CPS_NORMAL_SPEED 15625L

tools/JavaConfigurator/src/OSEC.java

Lines changed: 41 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,8 @@ public String toString() {
106106
private JTextField GearRatio;
107107
private JTextField txtMaxregencurrent;
108108

109-
private JTextField CellsNumber;
110109
private JTextField PAS_threshold;
111110
private JTextField txtMaxphasecurrent;
112-
private JTextField TempCalA;
113-
private JTextField TempCalB;
114111
private JRadioButton rdbtnBluOsecDisplay;
115112

116113
private JRadioButton rdbtnKingmeterJlcd;
@@ -190,8 +187,8 @@ public void loadSettings(File f) throws IOException {
190187
txtMaxregencurrent.setText(in.readLine());
191188
txtMotor_specific_angle.setText(in.readLine());
192189
txtBatteryCurcala.setText(in.readLine());
193-
TempCalA.setText(in.readLine());
194-
TempCalB.setText(in.readLine());
190+
in.readLine();
191+
in.readLine();
195192
Assist_Level_1.setText(in.readLine());
196193
Assist_Level_2.setText(in.readLine());
197194
Assist_Level_3.setText(in.readLine());
@@ -204,7 +201,7 @@ public void loadSettings(File f) throws IOException {
204201
p_factor.setText(in.readLine());
205202
i_factor.setText(in.readLine());
206203
GearRatio.setText(in.readLine());
207-
CellsNumber.setText(in.readLine());
204+
in.readLine();
208205
PAS_threshold.setText(in.readLine());
209206

210207
cbTorqueSensor.setSelected(Boolean.parseBoolean(in.readLine()));
@@ -545,26 +542,39 @@ public void mouseClicked(MouseEvent e) {
545542
GearRatio.setColumns(10);
546543
GearRatio.setBounds(150, 270, 86, 20);
547544
contentPane.add(GearRatio);
545+
546+
JLabel lblUndervoltageLimit = new JLabel("Undervoltage");
547+
lblUndervoltageLimit.setBounds(15, 290, 121, 14);
548+
lblUndervoltageLimit.setForeground(Color.GRAY);
549+
contentPane.add(lblUndervoltageLimit);
548550

549-
JLabel lblTemperatureCalA = new JLabel("Temperature cal a");
550-
lblTemperatureCalA.setBounds(15, 310, 121, 14);
551-
contentPane.add(lblTemperatureCalA);
551+
txtUndervoltage = new JTextField();
552+
txtUndervoltage.setText("127");
553+
txtUndervoltage.setBounds(150, 290, 86, 20);
554+
contentPane.add(txtUndervoltage);
555+
txtUndervoltage.setColumns(3);
552556

553-
TempCalA = new JTextField();
554-
TempCalA.setText("1.6");
555-
TempCalA.setColumns(10);
556-
TempCalA.setBounds(150, 310, 86, 20);
557-
contentPane.add(TempCalA);
557+
JLabel lblOvervoltageLimit = new JLabel("Overvoltage");
558+
lblOvervoltageLimit.setBounds(15, 310, 121, 14);
559+
lblOvervoltageLimit.setForeground(Color.GRAY);
560+
contentPane.add(lblOvervoltageLimit);
558561

559-
JLabel lblTemperatureCalB = new JLabel("Temperature cal b");
560-
lblTemperatureCalB.setBounds(15, 330, 121, 14);
561-
contentPane.add(lblTemperatureCalB);
562+
txtOvervoltage = new JTextField();
563+
txtOvervoltage.setText("150");
564+
txtOvervoltage.setBounds(150, 310, 86, 20);
565+
contentPane.add(txtOvervoltage);
566+
txtOvervoltage.setColumns(3);
567+
568+
JLabel lblBatVolCal = new JLabel("Voltage Calibration");
569+
lblBatVolCal.setBounds(15, 330, 121, 14);
570+
lblBatVolCal.setForeground(Color.GRAY);
571+
contentPane.add(lblBatVolCal);
562572

563-
TempCalB = new JTextField();
564-
TempCalB.setText("110.4");
565-
TempCalB.setColumns(10);
566-
TempCalB.setBounds(150, 330, 86, 20);
567-
contentPane.add(TempCalB);
573+
batteryVoltageCalib = new JTextField();
574+
batteryVoltageCalib.setText("70");
575+
batteryVoltageCalib.setColumns(2);
576+
batteryVoltageCalib.setBounds(150, 330, 86, 20);
577+
contentPane.add(batteryVoltageCalib);
568578

569579
JLabel lblPfactor = new JLabel("Gain P");
570580
lblPfactor.setBounds(15, 350, 67, 14);
@@ -743,49 +753,6 @@ public void mouseClicked(MouseEvent e) {
743753
contentPane.add(txtMotor_specific_angle);
744754
txtMotor_specific_angle.setColumns(10);
745755

746-
JLabel lblUndervoltageLimit = new JLabel("Undervoltage");
747-
lblUndervoltageLimit.setBounds(415, 270, 121, 14);
748-
lblUndervoltageLimit.setForeground(Color.GRAY);
749-
contentPane.add(lblUndervoltageLimit);
750-
751-
txtUndervoltage = new JTextField();
752-
txtUndervoltage.setText("127");
753-
txtUndervoltage.setBounds(530, 270, 50, 20);
754-
contentPane.add(txtUndervoltage);
755-
txtUndervoltage.setColumns(3);
756-
757-
JLabel lblNumberSerialCells = new JLabel("# Cells");
758-
lblNumberSerialCells.setBounds(415, 290, 121, 14);
759-
contentPane.add(lblNumberSerialCells);
760-
761-
CellsNumber = new JTextField();
762-
CellsNumber.setText("10");
763-
CellsNumber.setColumns(10);
764-
CellsNumber.setBounds(530, 290, 50, 20);
765-
contentPane.add(CellsNumber);
766-
767-
JLabel lblOvervoltageLimit = new JLabel("Overvoltage");
768-
lblOvervoltageLimit.setBounds(415, 310, 121, 14);
769-
lblOvervoltageLimit.setForeground(Color.GRAY);
770-
contentPane.add(lblOvervoltageLimit);
771-
772-
txtOvervoltage = new JTextField();
773-
txtOvervoltage.setText("150");
774-
txtOvervoltage.setBounds(530, 310, 50, 20);
775-
contentPane.add(txtOvervoltage);
776-
txtOvervoltage.setColumns(3);
777-
778-
JLabel lblBatVolCal = new JLabel("Volt Calib");
779-
lblBatVolCal.setBounds(415, 330, 121, 14);
780-
lblBatVolCal.setForeground(Color.GRAY);
781-
contentPane.add(lblBatVolCal);
782-
783-
batteryVoltageCalib = new JTextField();
784-
batteryVoltageCalib.setText("70");
785-
batteryVoltageCalib.setColumns(2);
786-
batteryVoltageCalib.setBounds(530, 330, 50, 20);
787-
contentPane.add(batteryVoltageCalib);
788-
789756
JList list = new JList();
790757
list.setBounds(441, 177, 1, 1);
791758
contentPane.add(list);
@@ -884,35 +851,35 @@ public void actionPerformed(ActionEvent arg0) {
884851
contentPane.add(ramp_start);
885852

886853
lblSpeedLimit = new JLabel("Limit (km/h)");
887-
lblSpeedLimit.setBounds(250, 340, 80, 14);
854+
lblSpeedLimit.setBounds(250, 350, 80, 14);
888855
lblSpeedLimit.setForeground(Color.GRAY);
889856
contentPane.add(lblSpeedLimit);
890857

891858
txtSpeedlimit = new JTextField();
892859
txtSpeedlimit.setText("25");
893-
txtSpeedlimit.setBounds(350, 340, 50, 20);
860+
txtSpeedlimit.setBounds(350, 350, 50, 20);
894861
contentPane.add(txtSpeedlimit);
895862
txtSpeedlimit.setColumns(10);
896863

897864
JLabel lblSpeedLimitwopas = new JLabel("Without PAS");
898-
lblSpeedLimitwopas.setBounds(250, 360, 80, 14);
865+
lblSpeedLimitwopas.setBounds(250, 370, 80, 14);
899866
lblSpeedLimitwopas.setForeground(Color.GRAY);
900867
contentPane.add(lblSpeedLimitwopas);
901868

902869
txtSpeedlimitWithoutPas = new JTextField();
903870
txtSpeedlimitWithoutPas.setText("6");
904-
txtSpeedlimitWithoutPas.setBounds(350, 360, 50, 20);
871+
txtSpeedlimitWithoutPas.setBounds(350, 370, 50, 20);
905872
contentPane.add(txtSpeedlimitWithoutPas);
906873
txtSpeedlimitWithoutPas.setColumns(10);
907874

908875
JLabel lblSpeedLimitwto = new JLabel("Offroad");
909-
lblSpeedLimitwto.setBounds(250, 380, 80, 14);
876+
lblSpeedLimitwto.setBounds(250, 390, 80, 14);
910877
lblSpeedLimitwto.setForeground(Color.GRAY);
911878
contentPane.add(lblSpeedLimitwto);
912879

913880
txtSpeedlimitWithThrottleOverride = new JTextField();
914881
txtSpeedlimitWithThrottleOverride.setText("25");
915-
txtSpeedlimitWithThrottleOverride.setBounds(350, 380, 50, 20);
882+
txtSpeedlimitWithThrottleOverride.setBounds(350, 390, 50, 20);
916883
contentPane.add(txtSpeedlimitWithThrottleOverride);
917884
txtSpeedlimitWithThrottleOverride.setColumns(10);
918885

@@ -1200,13 +1167,8 @@ public void actionPerformed(ActionEvent arg0) {
12001167
iWriter.println(txtBatteryCurcala.getText());
12011168
pWriter.println(text_to_save);
12021169

1203-
text_to_save = "#define TEMP_CAL_A " + TempCalA.getText();
1204-
iWriter.println(TempCalA.getText());
1205-
pWriter.println(text_to_save);
1206-
1207-
text_to_save = "#define TEMP_CAL_B " + TempCalB.getText();
1208-
iWriter.println(TempCalB.getText());
1209-
pWriter.println(text_to_save);
1170+
iWriter.println("");
1171+
iWriter.println("");
12101172

12111173
text_to_save = "#define LEVEL_1 " + Assist_Level_1.getText();
12121174
iWriter.println(Assist_Level_1.getText());
@@ -1256,9 +1218,7 @@ public void actionPerformed(ActionEvent arg0) {
12561218
iWriter.println(GearRatio.getText());
12571219
pWriter.println(text_to_save);
12581220

1259-
text_to_save = "#define BATTERY_LI_ION_CELLS_NUMBER " + CellsNumber.getText();
1260-
iWriter.println(CellsNumber.getText());
1261-
pWriter.println(text_to_save);
1221+
iWriter.println("");
12621222

12631223
text_to_save = "#define PAS_THRESHOLD " + PAS_threshold.getText();
12641224
iWriter.println(PAS_threshold.getText());

0 commit comments

Comments
 (0)