Skip to content

Commit 5a40f0f

Browse files
committed
Add an option to swap footpad ADCs
Feature: Add an option to swap left/right footpad ADCs
1 parent 97a5d62 commit 5a40f0f

8 files changed

Lines changed: 50 additions & 48 deletions

File tree

doc/commands/REALTIME_DATA.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ The bits in `mask1` and `mask2` control which fields are included in the respons
4949
| 17 | `pitch` | float16/float32 | IMU pitch angle [°]. |
5050
| 18 | `balance_pitch` | float16/float32 | Balance pitch angle [°]. |
5151
| 19 | `roll` | float16/float32 | IMU roll angle [°]. |
52-
| 20 | `adc1` | float16/float32 | Footpad sensor ADC1 value [V]. |
53-
| 21 | `adc2` | float16/float32 | Footpad sensor ADC2 value [V]. |
52+
| 20 | `adc_left` | float16/float32 | Footpad sensor Left ADC value [V]. |
53+
| 21 | `adc_right` | float16/float32 | Footpad sensor Right ADC value [V]. |
5454
| 22 | `remote_input` | float16/float32 | Remote control input value (0.0-1.0). |
5555
| 23 | `setpoint` | float16/float32 | Current balance setpoint [°]. |
5656
| 24 | `atr_setpoint` | float16/float32 | ATR setpoint [°]. |

src/conf/datatypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ typedef struct {
173173

174174
typedef struct {
175175
CfgHwLeds leds;
176+
bool swap_footpad_adcs;
176177
} CfgHardware;
177178

178179
typedef struct {

src/conf/settings.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,6 +4252,18 @@ p, li { white-space: pre-wrap; }
42524252
<cDefine>CFG_DFLT_HARDWARE_LEDS_REAR_REVERSE</cDefine>
42534253
<valInt>0</valInt>
42544254
</hardware.leds.rear.reverse>
4255+
<hardware.swap_footpad_adcs>
4256+
<longName>Swap Footpad ADCs</longName>
4257+
<type>5</type>
4258+
<transmittable>1</transmittable>
4259+
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
4260+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
4261+
p, li { white-space: pre-wrap; }
4262+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
4263+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Swaps the ADCs of the footpad sensor. If enabled, left footpad sensor is read from ADC2 and right sensor from ADC1. Otherwise, left footpad sensor is read from ADC1 and right sensor from ADC2.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
4264+
<cDefine>CFG_DFLT_HARDWARE_SWAP_FOOTPAD_ADCS</cDefine>
4265+
<valInt>0</valInt>
4266+
</hardware.swap_footpad_adcs>
42554267
<is_beeper_enabled>
42564268
<longName>Enable Beeper on Servo/PPM</longName>
42574269
<type>5</type>
@@ -4453,6 +4465,7 @@ p, li { white-space: pre-wrap; }
44534465
<ser>hardware.leds.rear.count</ser>
44544466
<ser>hardware.leds.rear.color_order</ser>
44554467
<ser>hardware.leds.rear.reverse</ser>
4468+
<ser>hardware.swap_footpad_adcs</ser>
44564469
<ser>is_beeper_enabled</ser>
44574470
<ser>disabled</ser>
44584471
<ser>haptic.duty.frequency</ser>
@@ -4723,6 +4736,7 @@ p, li { white-space: pre-wrap; }
47234736
<param>::sep::Foot Sensors</param>
47244737
<param>fault_adc1</param>
47254738
<param>fault_adc2</param>
4739+
<param>hardware.swap_footpad_adcs</param>
47264740
<param>is_footbeep_enabled</param>
47274741
<param>::sep::Miscellaneous</param>
47284742
<param>is_beeper_enabled</param>

src/footpad_sensor.c

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,29 @@
2020
#include "vesc_c_if.h"
2121

2222
void footpad_sensor_init(FootpadSensor *fs) {
23-
fs->adc1 = 0.0f;
24-
fs->adc2 = 0.0f;
23+
fs->adc_left = 0.0f;
24+
fs->adc_right = 0.0f;
2525
fs->state = FS_NONE;
2626
}
2727

2828
void footpad_sensor_update(FootpadSensor *fs, const RefloatConfig *config) {
29-
fs->adc1 = VESC_IF->io_read_analog(VESC_PIN_ADC1);
30-
// Returns -1.0 if the pin is missing on the hardware
31-
fs->adc2 = VESC_IF->io_read_analog(VESC_PIN_ADC2);
32-
if (fs->adc2 < 0.0) {
33-
fs->adc2 = 0.0;
34-
}
29+
// io_read_analog() returns -1.0 if the pin is missing on the hardware
30+
float adc1 = VESC_IF->io_read_analog(VESC_PIN_ADC1);
31+
float adc2 = VESC_IF->io_read_analog(VESC_PIN_ADC2);
3532

36-
fs->state = FS_NONE;
33+
bool adc1_on = config->fault_adc1 == 0.0f || adc1 > config->fault_adc1;
34+
bool adc2_on = config->fault_adc2 == 0.0f || adc2 > config->fault_adc2;
3735

38-
if (config->fault_adc1 == 0 && config->fault_adc2 == 0) { // No sensors
39-
fs->state = FS_BOTH;
40-
} else if (config->fault_adc2 == 0) { // Single sensor on ADC1
41-
if (fs->adc1 > config->fault_adc1) {
42-
fs->state = FS_BOTH;
43-
}
44-
} else if (config->fault_adc1 == 0) { // Single sensor on ADC2
45-
if (fs->adc2 > config->fault_adc2) {
46-
fs->state = FS_BOTH;
47-
}
48-
} else { // Double sensor
49-
if (fs->adc1 > config->fault_adc1) {
50-
if (fs->adc2 > config->fault_adc2) {
51-
fs->state = FS_BOTH;
52-
} else {
53-
fs->state = FS_LEFT;
54-
}
55-
} else {
56-
if (fs->adc2 > config->fault_adc2) {
57-
fs->state = FS_RIGHT;
58-
}
59-
}
36+
if (config->hardware.swap_footpad_adcs) {
37+
fs->adc_left = adc2;
38+
fs->adc_right = adc1;
39+
fs->state = adc1_on ? FS_RIGHT : FS_NONE;
40+
fs->state |= adc2_on ? FS_LEFT : FS_NONE;
41+
} else {
42+
fs->adc_left = adc1;
43+
fs->adc_right = adc2;
44+
fs->state = adc1_on ? FS_LEFT : FS_NONE;
45+
fs->state |= adc2_on ? FS_RIGHT : FS_NONE;
6046
}
6147
}
6248

src/footpad_sensor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ typedef enum {
2727
} FootpadSensorState;
2828

2929
typedef struct {
30-
float adc1, adc2;
30+
float adc_left;
31+
float adc_right;
3132
FootpadSensorState state;
3233
} FootpadSensor;
3334

src/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,8 @@ static void send_realtime_data(Data *d) {
13201320
state |= 0x8;
13211321
}
13221322
buffer[ind++] = (state & 0xF) + (d->beep_reason << 4);
1323-
buffer_append_float32_auto(buffer, d->footpad.adc1, &ind);
1324-
buffer_append_float32_auto(buffer, d->footpad.adc2, &ind);
1323+
buffer_append_float32_auto(buffer, d->footpad.adc_left, &ind);
1324+
buffer_append_float32_auto(buffer, d->footpad.adc_right, &ind);
13251325

13261326
// Setpoints
13271327
buffer_append_float32_auto(buffer, d->setpoint, &ind);
@@ -1377,8 +1377,8 @@ static void cmd_send_all_data(Data *d, unsigned char mode) {
13771377
}
13781378
buffer[ind++] = (state & 0xF) + (d->beep_reason << 4);
13791379

1380-
buffer[ind++] = d->footpad.adc1 * 50;
1381-
buffer[ind++] = d->footpad.adc2 * 50;
1380+
buffer[ind++] = d->footpad.adc_left * 50;
1381+
buffer[ind++] = d->footpad.adc_right * 50;
13821382

13831383
// Setpoints (can be positive or negative)
13841384
buffer[ind++] = d->setpoint * 5 + 128;
@@ -2034,8 +2034,8 @@ enum {
20342034
RT_MASK1_PITCH = 1 << 17,
20352035
RT_MASK1_BALANCE_PITCH = 1 << 18,
20362036
RT_MASK1_ROLL = 1 << 19,
2037-
RT_MASK1_ADC1 = 1 << 20,
2038-
RT_MASK1_ADC2 = 1 << 21,
2037+
RT_MASK1_ADC_LEFT = 1 << 20,
2038+
RT_MASK1_ADC_RIGHT = 1 << 21,
20392039
RT_MASK1_REMOTE_INPUT = 1 << 22,
20402040
RT_MASK1_SETPOINT = 1 << 23,
20412041
RT_MASK1_ATR_SETPOINT = 1 << 24,
@@ -2119,8 +2119,8 @@ static void cmd_realtime_data(Data *d, uint8_t *buf, int len) {
21192119
add_rt_item(buffer, &ind, mask1, RT_MASK1_PITCH, d->imu.pitch, use_f32);
21202120
add_rt_item(buffer, &ind, mask1, RT_MASK1_BALANCE_PITCH, d->imu.balance_pitch, use_f32);
21212121
add_rt_item(buffer, &ind, mask1, RT_MASK1_ROLL, d->imu.roll, use_f32);
2122-
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC1, d->footpad.adc1, use_f32);
2123-
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC2, d->footpad.adc2, use_f32);
2122+
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC_LEFT, d->footpad.adc_left, use_f32);
2123+
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC_RIGHT, d->footpad.adc_right, use_f32);
21242124
add_rt_item(buffer, &ind, mask1, RT_MASK1_REMOTE_INPUT, d->remote.input, use_f32);
21252125
add_rt_item(buffer, &ind, mask1, RT_MASK1_SETPOINT, d->setpoint, use_f32);
21262126
add_rt_item(buffer, &ind, mask1, RT_MASK1_ATR_SETPOINT, d->atr.setpoint.value, use_f32);

src/rt_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
R(imu.pitch, "pitch") \
5757
R(imu.balance_pitch, "balance_pitch") \
5858
S(imu.roll, "roll") \
59-
S(footpad.adc1, "adc1") \
60-
S(footpad.adc2, "adc2") \
59+
S(footpad.adc_left, "adc_left") \
60+
S(footpad.adc_right, "adc_right") \
6161
S(remote.input, "remote.input")
6262

6363
#define RT_DATA_RUNTIME_ITEMS(S, R) \

ui.qml.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,8 @@ Item {
21332133
["mosfet_temp", {"name": "Controller Temp", "color": "#ddae68", "visible": false}],
21342134
["motor_temp", {"name": "Motor Temp", "color": "#88bb93", "visible": false}],
21352135
["roll", {"name": "Roll", "color": "#c68f7e", "visible": false}],
2136-
["adc1", {"name": "ADC1 Voltage", "color": "#69aad7", "visible": false}],
2137-
["adc2", {"name": "ADC2 Voltage", "color": "#4a8772", "visible": false}],
2136+
["adc_left", {"name": "Left ADC Voltage", "color": "#69aad7", "visible": false}],
2137+
["adc_right", {"name": "Right ADC Voltage", "color": "#4a8772", "visible": false}],
21382138
["balance_current", {"name": "Balance Current", "color": "#36738b", "visible": false}],
21392139
["booster.torque", {"name": "Booster Torque", "color": "#8f2f26", "visible": false}],
21402140
["atr.accel_diff", {"name": "ATR Accel Diff", "color": "#4f5984", "visible": false}],
@@ -6366,8 +6366,8 @@ Item {
63666366
width: parent.height
63676367
height: width
63686368

6369-
property real leftVoltage: state.rtData["adc1"]
6370-
property real rightVoltage: state.rtData["adc2"]
6369+
property real leftVoltage: state.rtData["adc_left"]
6370+
property real rightVoltage: state.rtData["adc_right"]
63716371

63726372
property real canvasWidth: width * 0.85
63736373
property real scale: canvasWidth / footpadPath.width

0 commit comments

Comments
 (0)