Skip to content

Commit 5e59a79

Browse files
committed
Add an option to swap footpad ADCs
Feature: Add an option to swap left/right footpad ADCs
1 parent ace0f31 commit 5e59a79

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
@@ -4257,6 +4257,18 @@ p, li { white-space: pre-wrap; }
42574257
<cDefine>CFG_DFLT_HARDWARE_LEDS_REAR_REVERSE</cDefine>
42584258
<valInt>0</valInt>
42594259
</hardware.leds.rear.reverse>
4260+
<hardware.swap_footpad_adcs>
4261+
<longName>Swap Footpad ADCs</longName>
4262+
<type>5</type>
4263+
<transmittable>1</transmittable>
4264+
<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;
4265+
&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;
4266+
p, li { white-space: pre-wrap; }
4267+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
4268+
&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>
4269+
<cDefine>CFG_DFLT_HARDWARE_SWAP_FOOTPAD_ADCS</cDefine>
4270+
<valInt>0</valInt>
4271+
</hardware.swap_footpad_adcs>
42604272
<is_beeper_enabled>
42614273
<longName>Enable Beeper on Servo/PPM</longName>
42624274
<type>5</type>
@@ -4458,6 +4470,7 @@ p, li { white-space: pre-wrap; }
44584470
<ser>hardware.leds.rear.count</ser>
44594471
<ser>hardware.leds.rear.color_order</ser>
44604472
<ser>hardware.leds.rear.reverse</ser>
4473+
<ser>hardware.swap_footpad_adcs</ser>
44614474
<ser>is_beeper_enabled</ser>
44624475
<ser>disabled</ser>
44634476
<ser>haptic.duty.frequency</ser>
@@ -4728,6 +4741,7 @@ p, li { white-space: pre-wrap; }
47284741
<param>::sep::Foot Sensors</param>
47294742
<param>fault_adc1</param>
47304743
<param>fault_adc2</param>
4744+
<param>hardware.swap_footpad_adcs</param>
47314745
<param>is_footbeep_enabled</param>
47324746
<param>::sep::Miscellaneous</param>
47334747
<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
@@ -1328,8 +1328,8 @@ static void send_realtime_data(Data *d) {
13281328
state |= 0x8;
13291329
}
13301330
buffer[ind++] = (state & 0xF) + (d->beep_reason << 4);
1331-
buffer_append_float32_auto(buffer, d->footpad.adc1, &ind);
1332-
buffer_append_float32_auto(buffer, d->footpad.adc2, &ind);
1331+
buffer_append_float32_auto(buffer, d->footpad.adc_left, &ind);
1332+
buffer_append_float32_auto(buffer, d->footpad.adc_right, &ind);
13331333

13341334
// Setpoints
13351335
buffer_append_float32_auto(buffer, d->setpoint, &ind);
@@ -1386,8 +1386,8 @@ static void cmd_send_all_data(Data *d, unsigned char mode) {
13861386
buffer[ind++] = (state & 0xF) + (d->beep_reason << 4);
13871387
d->beep_reason = BEEP_NONE;
13881388

1389-
buffer[ind++] = d->footpad.adc1 * 50;
1390-
buffer[ind++] = d->footpad.adc2 * 50;
1389+
buffer[ind++] = d->footpad.adc_left * 50;
1390+
buffer[ind++] = d->footpad.adc_right * 50;
13911391

13921392
// Setpoints (can be positive or negative)
13931393
buffer[ind++] = d->setpoint * 5 + 128;
@@ -2043,8 +2043,8 @@ enum {
20432043
RT_MASK1_PITCH = 1 << 17,
20442044
RT_MASK1_BALANCE_PITCH = 1 << 18,
20452045
RT_MASK1_ROLL = 1 << 19,
2046-
RT_MASK1_ADC1 = 1 << 20,
2047-
RT_MASK1_ADC2 = 1 << 21,
2046+
RT_MASK1_ADC_LEFT = 1 << 20,
2047+
RT_MASK1_ADC_RIGHT = 1 << 21,
20482048
RT_MASK1_REMOTE_INPUT = 1 << 22,
20492049
RT_MASK1_SETPOINT = 1 << 23,
20502050
RT_MASK1_ATR_SETPOINT = 1 << 24,
@@ -2128,8 +2128,8 @@ static void cmd_realtime_data(Data *d, uint8_t *buf, int len) {
21282128
add_rt_item(buffer, &ind, mask1, RT_MASK1_PITCH, d->imu.pitch, use_f32);
21292129
add_rt_item(buffer, &ind, mask1, RT_MASK1_BALANCE_PITCH, d->imu.balance_pitch, use_f32);
21302130
add_rt_item(buffer, &ind, mask1, RT_MASK1_ROLL, d->imu.roll, use_f32);
2131-
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC1, d->footpad.adc1, use_f32);
2132-
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC2, d->footpad.adc2, use_f32);
2131+
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC_LEFT, d->footpad.adc_left, use_f32);
2132+
add_rt_item(buffer, &ind, mask1, RT_MASK1_ADC_RIGHT, d->footpad.adc_right, use_f32);
21332133
add_rt_item(buffer, &ind, mask1, RT_MASK1_REMOTE_INPUT, d->remote.input, use_f32);
21342134
add_rt_item(buffer, &ind, mask1, RT_MASK1_SETPOINT, d->setpoint, use_f32);
21352135
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)