Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enlargeable Config Packet #110

Merged
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6d00ee3
Initial proposal
Apehaenger Oct 7, 2024
e19c952
Add missing files
Apehaenger Oct 7, 2024
f3936e6
Abort one large config struct consideration
Apehaenger Oct 9, 2024
d90b6ca
Finish flexible length config packet
Apehaenger Oct 10, 2024
9a50a05
Cleanup, add and rename config struct member
Apehaenger Oct 11, 2024
13aff7f
refactor: create applyConfig()
rovo89 Oct 11, 2024
1c0cfac
PoC for LittleFS
rovo89 Oct 11, 2024
68ed301
Implement review hints of rovo89
Apehaenger Oct 11, 2024
1ff7d31
Don't write config to flash if it hasn't changed
rovo89 Oct 11, 2024
bca5826
Implement review hints of rovo89
Apehaenger Oct 11, 2024
7899164
Merge pull request #1 from rovo89/config_flash
Apehaenger Oct 12, 2024
4f11010
Minor LittleFS implementation changes
Apehaenger Oct 12, 2024
0075f68
Intermediate result after protocol implementation with ROS
Apehaenger Oct 14, 2024
37f2ac6
Missing commit
Apehaenger Oct 14, 2024
9e24b05
Intermediate commit #2
Apehaenger Oct 18, 2024
7eaa6fd
Adjust v_charge_cutoff to MAX20405
Apehaenger Oct 18, 2024
5f5d5b8
Change config_bitmask to option bitfield
Apehaenger Oct 20, 2024
a1a6492
Make IGNORE_CHARGING_CURRENT configurable via LL/HL config `options.i…
Apehaenger Oct 20, 2024
5b18e4a
Finalize LittleFS
Apehaenger Oct 20, 2024
859de1b
Finish new flexible hall implementation
Apehaenger Oct 22, 2024
4135fa5
Remove IGNORE_CHARGING_CURRENT builds from artifacts
Apehaenger Oct 22, 2024
fe8e829
Make halls const
Apehaenger Oct 22, 2024
32d6576
Apply received packet on default-config (instead of live-config)
Apehaenger Oct 24, 2024
2328792
Add configurable (Stock-CoverUI) rain threshold
Apehaenger Oct 24, 2024
21e5baf
Change config packet IDs
Apehaenger Oct 26, 2024
12874d2
Cleanup
Apehaenger Oct 26, 2024
485e0a8
Cosmetic changes
Apehaenger Oct 28, 2024
7ba963d
Store config packet instead of effective config
Apehaenger Oct 28, 2024
4d43638
Optimize hall handling with etl::vector
Apehaenger Oct 29, 2024
e55bc19
Change ConfigOptions from boolean to tree-state enums
Apehaenger Oct 29, 2024
480cadf
Change shutdown_esc_max_pitch to uint8_t
Apehaenger Oct 29, 2024
d185090
Add new/missing config values to applyConfig()
Apehaenger Oct 29, 2024
542419f
Fix hall handling
Apehaenger Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,6 @@ jobs:
cp Firmware/LowLevel/.pio/build/0_9_X_WT901_INSTEAD_OF_SOUND/firmware.elf ./artifacts/0_9_X_WT901_INSTEAD_OF_SOUND
cp Firmware/LowLevel/.pio/build/0_9_X_WT901_INSTEAD_OF_SOUND/firmware.uf2 ./artifacts/0_9_X_WT901_INSTEAD_OF_SOUND

mkdir ./artifacts/0_13_X_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_13_X_IGNORE_CHARGING_CURRENT/firmware.elf ./artifacts/0_13_X_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_13_X_IGNORE_CHARGING_CURRENT/firmware.uf2 ./artifacts/0_13_X_IGNORE_CHARGING_CURRENT

mkdir ./artifacts/0_12_X_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_12_X_IGNORE_CHARGING_CURRENT/firmware.elf ./artifacts/0_12_X_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_12_X_IGNORE_CHARGING_CURRENT/firmware.uf2 ./artifacts/0_12_X_IGNORE_CHARGING_CURRENT

mkdir ./artifacts/0_11_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_11_X_WT901_IGNORE_CHARGING_CURRENT/firmware.elf ./artifacts/0_11_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_11_X_WT901_IGNORE_CHARGING_CURRENT/firmware.uf2 ./artifacts/0_11_X_WT901_IGNORE_CHARGING_CURRENT

mkdir ./artifacts/0_10_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_10_X_WT901_IGNORE_CHARGING_CURRENT/firmware.elf ./artifacts/0_10_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_10_X_WT901_IGNORE_CHARGING_CURRENT/firmware.uf2 ./artifacts/0_10_X_WT901_IGNORE_CHARGING_CURRENT

mkdir ./artifacts/0_9_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_9_X_WT901_IGNORE_CHARGING_CURRENT/firmware.elf ./artifacts/0_9_X_WT901_IGNORE_CHARGING_CURRENT
cp Firmware/LowLevel/.pio/build/0_9_X_WT901_IGNORE_CHARGING_CURRENT/firmware.uf2 ./artifacts/0_9_X_WT901_IGNORE_CHARGING_CURRENT


- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
43 changes: 2 additions & 41 deletions Firmware/LowLevel/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 64k

lib_deps =
Wire
SPI
FastCRC
LittleFS
bakercp/PacketSerial@^1.4.0
powerbroker2/FireTimer@^1.0.5
https://github.com/ClemensElflein/NeoPixelConnect.git
Expand Down Expand Up @@ -50,14 +52,6 @@ lib_deps = ${env.lib_deps}
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/>
build_flags = ${env.build_flags} -DHW_0_13_X

[env:0_13_X_IGNORE_CHARGING_CURRENT]
lib_ignore = JY901_SERIAL,JY901_I2C
lib_deps = ${env.lib_deps}
stm32duino/STM32duino LSM6DSO@^2.0.3
powerbroker2/DFPlayerMini_Fast@^1.2.4
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/>
build_flags = ${env.build_flags} -DHW_0_13_X -DIGNORE_CHARGING_CURRENT

[env:0_12_X]
lib_ignore = JY901_SERIAL,JY901_I2C
lib_deps = ${env.lib_deps}
Expand All @@ -67,15 +61,6 @@ lib_deps = ${env.lib_deps}
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/> +<soundsystem.cpp>
build_flags = ${env.build_flags} -DHW_0_12_X -DENABLE_SOUND_MODULE

[env:0_12_X_IGNORE_CHARGING_CURRENT]
lib_ignore = JY901_SERIAL,JY901_I2C
lib_deps = ${env.lib_deps}
stm32duino/STM32duino LSM6DSO@^2.0.3
jpiat/PioSPI@^0.0.1
powerbroker2/DFPlayerMini_Fast@^1.2.4
build_src_filter = ${env.build_src_filter} +<imu/LSM6DSO/> +<soundsystem.cpp>
build_flags = ${env.build_flags} -DHW_0_12_X -DENABLE_SOUND_MODULE -DIGNORE_CHARGING_CURRENT


[env:0_11_X_MPU9250]
lib_ignore = JY901_SERIAL,JY901_I2C
Expand All @@ -93,14 +78,6 @@ lib_deps = ${env.lib_deps}
JY901_I2C
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_11_X -DENABLE_SOUND_MODULE

[env:0_11_X_WT901_IGNORE_CHARGING_CURRENT]
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/> +<soundsystem.cpp>
lib_ignore = JY901_SERIAL
lib_deps = ${env.lib_deps}
powerbroker2/DFPlayerMini_Fast@^1.2.4
JY901_I2C
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_11_X -DENABLE_SOUND_MODULE -DIGNORE_CHARGING_CURRENT


[env:0_10_X_MPU9250]
lib_ignore = JY901_SERIAL,JY901_I2C
Expand All @@ -118,13 +95,6 @@ lib_deps = ${env.lib_deps}
JY901_I2C
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_10_X -DENABLE_SOUND_MODULE

[env:0_10_X_WT901_IGNORE_CHARGING_CURRENT]
build_src_filter = ${env.build_src_filter} +<imu/WT901_I2C/> +<soundsystem.cpp>
lib_ignore = JY901_SERIAL
lib_deps = ${env.lib_deps}
powerbroker2/DFPlayerMini_Fast@^1.2.4
JY901_I2C
build_flags = ${env.build_flags} -DWT901_I2C -DHW_0_10_X -DENABLE_SOUND_MODULE -DIGNORE_CHARGING_CURRENT

[env:0_9_X_MPU9250]
lib_ignore = JY901_SERIAL,JY901_I2C
Expand All @@ -141,15 +111,6 @@ lib_deps = ${env.lib_deps}
JY901_SERIAL
build_flags = ${env.build_flags} -DWT901_INSTEAD_OF_SOUND -DHW_0_9_X


[env:0_9_X_WT901_IGNORE_CHARGING_CURRENT]
lib_ignore = JY901_I2C
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/> +<soundsystem.cpp>
lib_deps = ${env.lib_deps}
JY901_SERIAL
powerbroker2/DFPlayerMini_Fast@^1.2.4
build_flags = ${env.build_flags} -DWT901 -DHW_0_9_X -DENABLE_SOUND_MODULE -DIGNORE_CHARGING_CURRENT

[env:0_9_X_WT901]
lib_ignore = JY901_I2C
build_src_filter = ${env.build_src_filter} +<imu/WT901_SERIAL/> +<soundsystem.cpp>
Expand Down
103 changes: 71 additions & 32 deletions Firmware/LowLevel/src/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#define PACKET_ID_LL_STATUS 1
#define PACKET_ID_LL_IMU 2
#define PACKET_ID_LL_UI_EVENT 3
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ 0x21 // ll_high_level_config and request config from receiver
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP 0x22 // ll_high_level_config response
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ 0x11 // ll_high_level_config and request config from receiver
#define PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP 0x12 // ll_high_level_config response
#define PACKET_ID_LL_HEARTBEAT 0x42
#define PACKET_ID_LL_HIGH_LEVEL_STATE 0x43

Expand All @@ -34,21 +34,17 @@ enum HighLevelMode {
MODE_RECORDING = 3 // ROS connected, Manual mode during recording etc
};

#define LL_EMERGENCY_BIT_LATCH 0b00000001
#define LL_EMERGENCY_BIT_HALL1 0b00001000 // Lift1
#define LL_EMERGENCY_BIT_HALL2 0b00010000 // Lift2
#define LL_EMERGENCY_BIT_HALL3 0b00000010 // Stop1
#define LL_EMERGENCY_BIT_HALL4 0b00000100 // Stop2
#define LL_EMERGENCY_BIT_LATCH (1 << 0)
#define LL_EMERGENCY_BIT_LIFT (1 << 1) // Lift (or tilt)
#define LL_EMERGENCY_BIT_STOP (1 << 2) // Stop
Apehaenger marked this conversation as resolved.
Show resolved Hide resolved

#define LL_EMERGENCY_BIT_LIFT1 LL_EMERGENCY_BIT_HALL1
#define LL_EMERGENCY_BIT_LIFT2 LL_EMERGENCY_BIT_HALL2
#define LL_EMERGENCY_BITS_LIFT (LL_EMERGENCY_BIT_LIFT1 | LL_EMERGENCY_BIT_LIFT2)
#define LL_EMERGENCY_BIT_STOP1 LL_EMERGENCY_BIT_HALL3
#define LL_EMERGENCY_BIT_STOP2 LL_EMERGENCY_BIT_HALL4
#define LL_EMERGENCY_BITS_STOP (LL_EMERGENCY_BIT_STOP1 | LL_EMERGENCY_BIT_STOP2)

#define LIFT1_IS_INVERTED 0
#define LIFT2_IS_INVERTED 0
// Need the old emergency_bitmask definition because CoverUI send it
#define LL_EMERGENCY_BIT_CU_LIFT 0b00001000 // LIFT | LIFTX (up to CoverUI FW 2.0x)
#define LL_EMERGENCY_BIT_CU_BUMP 0b00010000 // LBUMP | RBUMP (up to CoverUI FW 2.0x)
#define LL_EMERGENCY_BIT_CU_STOP1 0b00000010 // Stop1
#define LL_EMERGENCY_BIT_CU_STOP2 0b00000100 // Stop2
#define LL_EMERGENCY_BIT_CU_LIFTX 0b00100000 // CoverUI-LIFTX (as of CoverUI FW 2.1x)
#define LL_EMERGENCY_BIT_CU_RBUMP 0b01000000 // CoverUI-RBUMP (as of CoverUI FW 2.1x)

#define LL_STATUS_BIT_UI_AVAIL 0b10000000
Apehaenger marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -60,7 +56,7 @@ struct ll_status {
// Bit 0: Initialized (i.e. setup() was a success). If this is 0, all other bits are meaningless.
// Bit 1: Raspberry Power
// Bit 2: Charging enabled
// Bit 3: don't care
// Bit 3: don't care (reserved for ESC shutdown PR)
// Bit 4: Rain detected
// Bit 5: Sound available
// Bit 6: Sound busy
Expand All @@ -70,10 +66,8 @@ struct ll_status {
float uss_ranges_m[5];
// Emergency bitmask:
// Bit 0: Emergency latch
// Bit 1: Emergency/Hall 3 (Stop1) active
// Bit 2: Emergency/Hall 4 (Stop2) active
// Bit 3: Emergency/Hall 1 (Lift1) active
// Bit 4: Emergency/Hall 2 (Lift2) active
// Bit 1: Emergency/Lift (or tilt)
// Bit 2: Emergency/Stop
uint8_t emergency_bitmask;
// Charge voltage
float v_charge;
Expand Down Expand Up @@ -135,22 +129,67 @@ struct ll_ui_event {
} __attribute__((packed));
#pragma pack(pop)

#define LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION 1 // Max. comms packet version supported by this open_mower LL FW
#define LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V 1 << 0 // Enable full sound via mower_config env var "OM_DFP_IS_5V"
#define LL_HIGH_LEVEL_CONFIG_BIT_EMERGENCY_INVERSE 1 << 1 // Sample, for possible future usage, i.e. for SA-Type emergency
#pragma pack(push, 1)
struct ConfigOptions {
bool dfp_is_5v : 1;
bool background_sounds : 1;
bool ignore_charging_current : 1;
} __attribute__((packed));
#pragma pack(pop)

typedef char iso639_1[2]; // Two char ISO 639-1 language code

enum class HallMode : unsigned int {
OFF = 0,
LIFT_TILT, // Wheel lifted and/or wheels tilted functionality
STOP, // Stop mower
UNDEFINED // This is used by foreign side to inform that it doesn't has a configuration for this sensor
};

#pragma pack(push, 1)
struct HallConfig {
HallMode mode : 3; // 1 bit reserved
bool active_low : 1;
} __attribute__((packed));
#pragma pack(pop)

#define MAX_HALL_INPUTS 10 // How much Hall-inputs we support. 4 * OM + 6 * Stock-CoverUI + 0 spare (because not yet required to make it fixed)

// LL/HL config packet, bi-directional, flexible-length, with defaults for YF-C500.
#pragma pack(push, 1)
struct ll_high_level_config {
uint8_t type;
uint8_t comms_version = LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION; // Increasing comms packet-version number for packet compatibility (n > 0)
uint8_t config_bitmask = 0; // See LL_HIGH_LEVEL_CONFIG_BIT_*
int8_t volume; // Volume (0-100%) feedback (if directly changed via CoverUI)
iso639_1 language; // ISO 639-1 (2-char) language code (en, de, ...)
uint16_t spare1 = 0; // Spare for future use
uint16_t spare2 = 0; // Spare for future use
uint16_t crc;
// ATTENTION: This is a flexible length struct. It is allowed to grow independently to HL without loosing compatibility,
// but never change or restructure already published member, except you really know their consequences.

// uint8_t type; Just for illustration. Get set in wire buffer with type PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ or PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP

ConfigOptions options = {0, 0, 0};
uint16_t rain_threshold = 700; // If (stock CoverUI) rain value < rain_threshold then it rains. Expected to differ between C500, SA and SC types (0xFFFF = unknown)
float v_charge_cutoff = 30.0f; // Protective max. charging voltage before charging get switched off (-1 = unknown)
float i_charge_cutoff = 1.5f; // Protective max. charging current before charging get switched off (-1 = unknown)
float v_battery_cutoff = 29.0f; // Protective max. battery voltage before charging get switched off (-1 = unknown)
float v_battery_empty = 21.7f + 0.3f; // Empty battery voltage used for % calc of capacity (-1 = unknown)
float v_battery_full = 28.7f - 0.3f; // Full battery voltage used for % calc of capacity (-1 = unknown)
uint16_t lift_period = 100; // Period (ms) for >=2 wheels to be lifted in order to count as emergency (0 = disable, 0xFFFF = unknown). This is to filter uneven ground
uint16_t tilt_period = 2500; // Period (ms) for a single wheel to be lifted in order to count as emergency (0 = disable, 0xFFFF = unknown). This is to filter uneven ground
float shutdown_esc_max_pitch = 0.0f; // Do not shutdown ESCs if absolute pitch angle is greater than this (0 = disable, 0xffff = unknown) (to be implemented)
Apehaenger marked this conversation as resolved.
Show resolved Hide resolved
iso639_1 language = {'e', 'n'}; // ISO 639-1 (2-char) language code (en, de, ...)
uint8_t volume = 80; // Volume (0-100%) feedback (if directly changed i.e. via CoverUI or WebApp) (0xff = do not change)
HallConfig hall_configs[MAX_HALL_INPUTS] = {
{HallMode::LIFT_TILT, true}, // [0] OM Hall-1 input (Lift1) = YF-C500 default
{HallMode::LIFT_TILT, true}, // [1] OM Hall-2 input (Lift2) = YF-C500 default
{HallMode::STOP, true}, // [2] OM Hall-3 input (Stop1) = YF-C500 default
{HallMode::STOP, true}, // [3] OM Hall-4 input (Stop2) = YF-C500 default
//{HallMode::LIFT_TILT, false}, // [4] CoverUI-LIFT | LIFTX (up to CoverUI FW 2.0x)
//{HallMode::LIFT_TILT, false}, // [5] CoverUI-LIFTX (as of CoverUI FW 2.1x)
//{HallMode::LIFT_TILT, false}, // [6] CoverUI-LBUMP | RBUMP (up to CoverUI FW 2.0x)
//{HallMode::LIFT_TILT, false}, // [7] CoverUI-RBUMP (as of CoverUI FW 2.1x)
//{HallMode::STOP, false}, // [8] CoverUI-Stop1
//{HallMode::STOP, false}, // [9] CoverUI-Stop2
};
// INFO: Before adding a new member here: Decide if and how much hall_configs spares do we like to have

// uint16_t crc; Just for illustration, that it get appended, but only within the wire buffer
} __attribute__((packed));
#pragma pack(pop)

Expand Down
Loading
Loading