Skip to content

Commit

Permalink
Version 2.1.10
Browse files Browse the repository at this point in the history
- new parametres: FOC Angle multiplicator and Field Weakening Enable/Disable
  • Loading branch information
mspider65 committed May 20, 2021
1 parent 9f7e7e8 commit 6b8f838
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "spider65.ebike.tsdz2_esp32"
minSdkVersion 23
targetSdkVersion 28
versionCode 16
versionName "2.1.9"
versionCode 17
versionName "2.1.10"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

public class ShowDebugInfo extends AppCompatActivity {

private IntentFilter mIntentFilter = new IntentFilter();
private final IntentFilter mIntentFilter = new IntentFilter();

private LinearLayout mainTimeLL, pwmTimeLL, hallErrLL;
private TextView mainLoopTV, pwmTV, hallErrTV;
private TextView rxcTV, rxlTV, ebikeTimeTV, motorTimeTV, pwmDownTV, pwmUpTV, hallStateErrTV, hallSeqErrTV;
private TextView rxcTV, rxlTV, ebikeTimeTV, pwmDownTV, pwmUpTV, hallStateErrTV, hallSeqErrTV;
private View div1, div2, div3;
private final TSDZ_Status status = new TSDZ_Status();
private final TSDZ_Debug debug = new TSDZ_Debug();
Expand All @@ -51,7 +51,6 @@ protected void onCreate(Bundle savedInstanceState) {
mainTimeLL = findViewById(R.id.mainTimeLinearLayout);
mainLoopTV = findViewById(R.id.mainTimeTV);
ebikeTimeTV = findViewById(R.id.mainLoopTimeTV);
motorTimeTV = findViewById(R.id.motorLoopTimeTV);
div1 = findViewById(R.id.dbg_infoDV1);
mainTimeLL.setVisibility(View.GONE);
mainLoopTV.setVisibility(View.GONE);
Expand Down Expand Up @@ -132,7 +131,6 @@ private void refreshDebug() {

if (mainDebug) {
ebikeTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug2));
motorTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug1));
}

if (hallDebug) {
Expand All @@ -148,7 +146,7 @@ private void refreshStatus() {


private byte[] lastStatusData, lastDebugData;
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class SystemSetupActivity extends AppCompatActivity {

private static final String TAG = "MotorSetupActivity";

private static final int DEFAULT_36V_INDUCTANCE = 80;
private static final int DEFAULT_48V_INDUCTANCE = 142;
private static final int DEFAULT_36V_FOC_MULTI = 24;
private static final int DEFAULT_48V_FOC_MULTI = 32;

private TSDZ_Config cfg = new TSDZ_Config();
private IntentFilter mIntentFilter = new IntentFilter();
Expand Down Expand Up @@ -77,11 +77,11 @@ public void onOkCancelClick(View view) {

public void onClickInductance(View view) {
switch (view.getId()) {
case R.id.inductance36BT:
binding.inductanceET.setText(String.valueOf(DEFAULT_36V_INDUCTANCE));
case R.id.focMultip36BT:
binding.focMultipET.setText(String.valueOf(DEFAULT_36V_FOC_MULTI));
break;
case R.id.inductance48BT:
binding.inductanceET.setText(String.valueOf(DEFAULT_48V_INDUCTANCE));
case R.id.focMultip48BT:
binding.focMultipET.setText(String.valueOf(DEFAULT_48V_FOC_MULTI));
break;
}
}
Expand All @@ -104,11 +104,14 @@ public void onCheckedChanged(View view, boolean checked) {
private void saveCfg() {
Integer val;
boolean checked;
if ((val = checkRange(binding.inductanceET, 0, 150)) == null) {
showDialog(getString(R.string.motor_inductance), getString(R.string.range_error, 0, 150));
if ((val = checkRange(binding.focMultipET, 0, 50)) == null) {
showDialog(getString(R.string.foc_multiplicator), getString(R.string.range_error, 0, 50));
return;
}
cfg.ui8_motor_inductance_x1048576 = val;
cfg.ui8_foc_angle_multiplicator = val;

checked = binding.fieldWeakeningCB.isChecked();
cfg.fieldWeakeningEnabled = checked;

if ((val = checkRange(binding.accelerationET, 0, 100)) == null) {
showDialog(getString(R.string.acceleration), getString(R.string.range_error, 0, 100));
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int getValue() {
}
}

public int ui8_motor_inductance_x1048576;
public int ui8_foc_angle_multiplicator;
public int ui8_motor_temperature_min_value_to_limit;
public int ui8_motor_temperature_max_value_to_limit;
public int ui8_motor_acceleration;
Expand Down Expand Up @@ -74,6 +74,8 @@ public int getValue() {
public int ui16_torque_offset_ADC;
public int[] ui8_hall_ref_angles = new int[6];
public int[] ui8_hall_counter_offset = new int[6];
public boolean fieldWeakeningEnabled;


/*
#pragma pack(1)
Expand Down Expand Up @@ -112,7 +114,7 @@ public int getValue() {
volatile uint8_t ui8_torque_assist_level[4];
volatile uint8_t ui8_eMTB_assist_sensitivity[4];
volatile uint8_t ui8_walk_assist_level[4];
volatile uint8_t ui8_torque_offset_fix;
volatile uint8_t ui8_flags;
volatile uint16_t ui16_torque_offset_value;
volatile uint8_t ui8_hall_ref_angles[6];
volatile uint8_t ui8_hall_offsets[6];
Expand All @@ -124,7 +126,7 @@ public boolean setData(byte[] data) {
Log.e(TAG, "setData: wrong data size" + data.length);
return false;
}
ui8_motor_inductance_x1048576 = (data[0] & 255);
ui8_foc_angle_multiplicator = (data[0] & 255);
ui8_motor_temperature_min_value_to_limit = (data[1] & 255);
ui8_motor_temperature_max_value_to_limit = (data[2] & 255);
ui8_motor_acceleration = (data[3] & 255);
Expand Down Expand Up @@ -169,7 +171,8 @@ public boolean setData(byte[] data) {
ui8_eMTB_assist_level[i] = (data[45+i] & 255);
for (int i=0;i<4;i++)
ui8_walk_assist_level[i] = (data[49+i] & 255);
torque_offset_fix = (data[53] & 255 ) != 0; // ui8_torque_offset_fix
torque_offset_fix = (data[53] & 0x01 ) != 0;
fieldWeakeningEnabled = (data[53] & 0x02) != 0;
ui16_torque_offset_ADC = (data[54] & 255) + ((data[55] & 255) << 8);
for (int i=0;i<6;i++)
ui8_hall_ref_angles[i] = (data[56+i] & 255);
Expand All @@ -180,7 +183,7 @@ public boolean setData(byte[] data) {

public byte[] toByteArray() {
byte[] data = new byte[CFG_SIZE];
data[0] = (byte)(ui8_motor_inductance_x1048576 & 0xff);
data[0] = (byte)(ui8_foc_angle_multiplicator & 0xff);
data[1] = (byte)ui8_motor_temperature_min_value_to_limit;
data[2] = (byte)ui8_motor_temperature_max_value_to_limit;
data[3] = (byte)ui8_motor_acceleration;
Expand Down Expand Up @@ -224,7 +227,9 @@ public byte[] toByteArray() {
data[45+i] = (byte)ui8_eMTB_assist_level[i];
for (int i=0;i<4;i++)
data[49+i] = (byte)ui8_walk_assist_level[i];
data[53] = (byte)(torque_offset_fix? 1:0);
data[53] = 0;
data[53] |= (byte)(torque_offset_fix? 1:0);
data[53] |= (byte)(fieldWeakeningEnabled? 2:0);
data[54] = (byte)ui16_torque_offset_ADC;
data[55] = (byte)(ui16_torque_offset_ADC >>> 8);
for (int i=0;i<6;i++)
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/res/layout/activity_show_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,6 @@
android:layout_marginStart="5sp"
android:text="@string/dash" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textEnd"
android:layout_marginEnd="5sp"
android:text="@string/motor_loop" />

<TextView
android:id="@+id/motorLoopTimeTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textStart"
android:layout_marginStart="5sp"
android:text="@string/dash" />
</LinearLayout>

<View
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/res/layout/activity_system_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,30 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/motor_inductance"
android:text="@string/foc_multiplicator"
android:layout_gravity="center_vertical" />

<EditText
android:id="@+id/inductanceET"
android:id="@+id/focMultipET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:layout_weight="2"
android:ems="2"
android:inputType="number"
android:text="@{String.valueOf(cfg.ui8_motor_inductance_x1048576)}" />
android:text="@{String.valueOf(cfg.ui8_foc_angle_multiplicator)}" />

<Button
android:id="@+id/inductance36BT"
android:id="@+id/focMultip36BT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="@{clickHandler::onClickInductance}"
android:text="36V" />

<Button
android:id="@+id/inductance48BT"
android:id="@+id/focMultip48BT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
Expand All @@ -95,6 +95,15 @@

</LinearLayout>

<CheckBox
android:id="@+id/fieldWeakeningCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:checked="@{cfg.fieldWeakeningEnabled}"
android:text="@string/field_weakening" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,19 @@
<string name="hall_calib">Hall calibration</string>
<string name="title_activity_system_setup">System Setup</string>
<string name="motor">Motor</string>
<string name="motor_inductance">Motor Inductance</string>
<string name="foc_multiplicator">FOC angle multipl.</string>
<string name="field_weakening">Field Weakening</string>
<string name="acceleration">Acceleration</string>
<string name="max_current">Max current (A)</string>
<string name="max_power">Max Power (W)</string>
<string name="sensors">Sensors</string>
<string name="wheel_cruise">Wheel / Cruise</string>
<string name="light">Light</string>
<string name="ligth_config">Lights Configuration</string>
<string name="assit_wpr">Assist without\npedal rotation</string>
<string name="assit_wpr">Assist without\npedal rot.</string>
<string name="torque_adc_step">Torque sensor ADC step</string>
<string name="torque_offset_fix">Torque Offset Fix</string>
<string name="torque_adc_offset">Torque ADC offset</string>
<string name="torque_adc_offset">Torque offset</string>
<string name="threshold">Threshold</string>
<string name="street_mode">Street Mode</string>
<string name="cruise_mode_enabled">Cruise mode enabled</string>
Expand Down

0 comments on commit 6b8f838

Please sign in to comment.