Skip to content

Commit d107e7e

Browse files
author
Bjoern Schmidt
committed
added power control (instead of current) option
added safety check for torquesensor mode, no override when there is no cadence detected
1 parent 0879ad8 commit d107e7e

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

ACAcontrollerState.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ typedef enum {
146146

147147
DYNAMIC_ASSIST_LEVEL = ((uint16_t) 512),
148148

149+
POWER_BASED_CONTROL= ((uint16_t) 1024),
149150
TQ_SENSOR_MODE = ((uint16_t) 2048),
150-
ANGLE_CORRECTION_ENABLED = ((uint16_t) 4096)
151+
ANGLE_CORRECTION_ENABLED = ((uint16_t) 4096)
151152
} ACA_FLAGS;
152153

153154
typedef enum {

ACAsetPoint.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ uint16_t aca_setpoint(uint16_t ui16_time_ticks_between_speed_interrupt, uint16_t
235235
float_temp = (float) ui16_sum_torque;
236236
float_temp *= ((float) ui8_assist_percent_actual / 100.0);
237237

238-
if (((ui16_aca_flags & TQ_SENSOR_MODE) == TQ_SENSOR_MODE)) {
238+
if (flt_torquesensorCalibration != 0.0) {
239239
// flt_torquesensorCalibration is >fummelfactor * NUMBER_OF_PAS_MAGS * 64< (64 cause of <<6)
240240
float_temp *= flt_torquesensorCalibration / ((float) ui16_time_ticks_between_pas_interrupt_smoothed); // influence of cadence
241241
//printf("%lu, %u, %u, %u \r\n", uint32_current_target, ui16_sum_torque,(uint16_t) float_temp, ui16_time_ticks_between_pas_interrupt_smoothed );
@@ -263,7 +263,7 @@ uint16_t aca_setpoint(uint16_t ui16_time_ticks_between_speed_interrupt, uint16_t
263263
}
264264

265265
// map curret target to assist level, not to maximum value
266-
if ((ui16_aca_flags & ASSIST_LVL_AFFECTS_THROTTLE) == 1) {
266+
if ((ui16_aca_flags & ASSIST_LVL_AFFECTS_THROTTLE) == ASSIST_LVL_AFFECTS_THROTTLE) {
267267
float_temp *= ((float) ui8_assist_percent_actual / 100.0);
268268
controll_state_temp += 8;
269269
}
@@ -272,7 +272,15 @@ uint16_t aca_setpoint(uint16_t ui16_time_ticks_between_speed_interrupt, uint16_t
272272

273273

274274
if ((uint32_t) float_temp > uint32_current_target) {
275-
uint32_current_target = (uint32_t) float_temp; //override torque simulation with throttle / torquesensor
275+
if (((ui16_aca_flags & TQ_SENSOR_MODE) == TQ_SENSOR_MODE)) {
276+
if (uint32_current_target > ui16_current_cal_b){
277+
//override cadence based torque with torquesensor-throttle only if there is cadence based contribution
278+
uint32_current_target = (uint32_t) float_temp;
279+
}
280+
}else{
281+
//override torque simulation with throttle
282+
uint32_current_target = (uint32_t) float_temp;
283+
}
276284
controll_state_temp += 16;
277285
}
278286

@@ -293,6 +301,13 @@ uint16_t aca_setpoint(uint16_t ui16_time_ticks_between_speed_interrupt, uint16_t
293301
controll_state_temp += 128;
294302
}
295303

304+
// control power instead of current
305+
if ((ui16_aca_flags & POWER_BASED_CONTROL) == POWER_BASED_CONTROL) {
306+
// nominal voltage based on limits
307+
ui8_temp = ((ui8_s_battery_voltage_max - ui8_s_battery_voltage_min)>>1)+ui8_s_battery_voltage_min;
308+
uint32_current_target*=ui8_temp/ui8_BatteryVoltage;
309+
}
310+
296311
if ((ui16_aca_experimental_flags & DC_STATIC_ZERO) == DC_STATIC_ZERO) {
297312
ui32_dutycycle = 0;
298313
controll_state_temp += 256;

OSEC Parameter Configurator.jar

125 Bytes
Binary file not shown.

config.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define CONFIG_H_
1010

1111
#define NUMBER_OF_PAS_MAGS 12
12-
#define limit 28
12+
#define limit 25
1313
#define timeout 3125
1414
#define wheel_circumference 2230L
1515
#define limit_without_pas 6
@@ -19,7 +19,7 @@
1919
#define BATTERY_CURRENT_MAX_VALUE 150L
2020
#define PHASE_CURRENT_MAX_VALUE 300L
2121
#define REGEN_CURRENT_MAX_VALUE 50L
22-
#define MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT 238
22+
#define MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT 0
2323
#define current_cal_a 46
2424
#define TEMP_CAL_A 1.6
2525
#define TEMP_CAL_B -110.4
@@ -38,22 +38,22 @@
3838
#define BATTERY_LI_ION_CELLS_NUMBER 13
3939
#define PAS_THRESHOLD 1.9
4040
#define RAMP_START 64000
41-
#define limit_with_throttle_override 35
41+
#define limit_with_throttle_override 25
4242
#define CORRECTION_AT_ANGLE 127
4343
#define PWM_CYCLES_SECOND 15625L
44+
#define DISPLAY_TYPE_KT_LCD3
4445
#define SPEEDSENSOR_INTERNAL
4546
#define ANGLE_4_0 1
46-
#define ANGLE_6_60 38
47-
#define ANGLE_2_120 82
47+
#define ANGLE_6_60 43
48+
#define ANGLE_2_120 86
4849
#define ANGLE_3_180 128
49-
#define BLUOSEC
50-
#define ANGLE_1_240 166
51-
#define ANGLE_5_300 210
50+
#define ANGLE_1_240 171
51+
#define ANGLE_5_300 213
5252
#define TQS_CALIB 0.0
53-
#define ACA 4764
53+
#define ACA 4766
5454
#define EEPROM_NOINIT // eeprom will not be cleared
55-
#define EEPROM_INIT_MAGIC_BYTE 11 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
56-
#define ADC_BATTERY_VOLTAGE_K 68
55+
#define EEPROM_INIT_MAGIC_BYTE 193 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
56+
#define ADC_BATTERY_VOLTAGE_K 70
5757
#define ACA_EXPERIMENTAL 128
5858
#define BATTERY_VOLTAGE_MAX_VALUE 200
5959

tools/JavaConfigurator/src/OSEC.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public String toString() {
139139
private JCheckBox cbPwmOff;
140140
private JCheckBox cbDcNull;
141141
private JCheckBox cbCorrectionEnabled;
142+
private JCheckBox cbPowerBasedControlEnabled;
142143
private JCheckBox cbDynAssist;
143144

144145
private JTextField txtAngle4;
@@ -264,7 +265,7 @@ public void loadSettings(File f) throws IOException {
264265
cbBypassLowSpeedRegenPiControl.setSelected((acaFlags & 256) > 0);
265266

266267
cbDynAssist.setSelected((acaFlags & 512) > 0);
267-
268+
cbPowerBasedControlEnabled.setSelected((acaFlags & 1024) > 0);
268269
cbTorqueSensor.setSelected((acaFlags & 2048) > 0);
269270
cbCorrectionEnabled.setSelected((acaFlags & 4096) > 0);
270271
tmp = in.readLine();
@@ -710,6 +711,7 @@ public void mouseClicked(MouseEvent e) {
710711

711712
JLabel lblUndervoltageLimit = new JLabel("Undervoltage");
712713
lblUndervoltageLimit.setBounds(415, 270, 121, 14);
714+
lblUndervoltageLimit.setForeground(Color.GRAY);
713715
contentPane.add(lblUndervoltageLimit);
714716

715717
txtUndervoltage = new JTextField();
@@ -730,6 +732,7 @@ public void mouseClicked(MouseEvent e) {
730732

731733
JLabel lblOvervoltageLimit = new JLabel("Overvoltage");
732734
lblOvervoltageLimit.setBounds(415, 310, 121, 14);
735+
lblOvervoltageLimit.setForeground(Color.GRAY);
733736
contentPane.add(lblOvervoltageLimit);
734737

735738
txtOvervoltage = new JTextField();
@@ -964,15 +967,21 @@ public void itemStateChanged(ItemEvent e) {
964967
cbCorrectionEnabled.setForeground(Color.GRAY);
965968
contentPane.add(cbCorrectionEnabled);
966969

970+
cbPowerBasedControlEnabled = new JCheckBox("Power based control");
971+
cbPowerBasedControlEnabled.setSelected(false);
972+
cbPowerBasedControlEnabled.setBounds(250, 535, 250, 20);
973+
cbPowerBasedControlEnabled.setForeground(Color.GRAY);
974+
contentPane.add(cbPowerBasedControlEnabled);
975+
967976
cbPwmOff = new JCheckBox("PWM off @coast (experimental)");
968977
cbPwmOff.setSelected(false);
969-
cbPwmOff.setBounds(250, 535, 250, 20);
978+
cbPwmOff.setBounds(250, 615, 250, 20);
970979
cbPwmOff.setForeground(Color.ORANGE);
971980
contentPane.add(cbPwmOff);
972981

973982
cbDcNull = new JCheckBox("DC static zero (testing/experimental)");
974983
cbDcNull.setSelected(false);
975-
cbDcNull.setBounds(250, 555, 250, 20);
984+
cbDcNull.setBounds(250, 635, 250, 20);
976985
cbDcNull.setForeground(Color.ORANGE);
977986
contentPane.add(cbDcNull);
978987

@@ -1321,7 +1330,7 @@ public void actionPerformed(ActionEvent arg0) {
13211330
acaFlags |= (cbBypassLowSpeedRegenPiControl.isSelected() ? 256 : 0);
13221331

13231332
acaFlags |= (cbDynAssist.isSelected() ? 512 : 0);
1324-
1333+
acaFlags |= (cbPowerBasedControlEnabled.isSelected() ? 1024 : 0);
13251334
acaFlags |= (cbTorqueSensor.isSelected() ? 2048 : 0);
13261335
acaFlags |= (cbCorrectionEnabled.isSelected() ? 4096 : 0);
13271336

0 commit comments

Comments
 (0)