Skip to content

Commit

Permalink
Prepare hall separation
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Oct 30, 2024
1 parent b8b51fd commit 77110e2
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 83 deletions.
11 changes: 0 additions & 11 deletions Firmware/CoverUI/BttnCtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ enum LED_state {
LED_on = 0b111
};

// Used only by Stock-CoverUI
// Same bitmask as in ll_status.emergency_bitmask (LowLevel, datatypes.h)
enum Emergency_state
{
Emergency_latch = 0b00001,
Emergency_stop1 = 0b00010,
Emergency_stop2 = 0b00100,
Emergency_lift1 = 0b01000,
Emergency_lift2 = 0b10000
};

// CoverUI subscription topic_bitmask
enum Topic_state
{
Expand Down
3 changes: 2 additions & 1 deletion Firmware/CoverUI/YardForce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ check section [usage](#usage) about the [LED](#meaning-of-the-leds) and [Button]

| Version [^4] | Changes | Date |
| ------- | ------- | ---- |
| 2.06 | - Add MOD_HALL support to YardForce RM-ECOW-V1.0.0<br>- Fix heap overflow which could happen when an action button got pressed multiple (10-20) times | 2024-09-29
| 2.10 | - Separate hall support. Require OpenMower FW >= ??? | 2024-11-??
| 2.06 | - Add STM32 MCU support to RM-ECOW-V1.1.0<br>- Add MOD_HALL support to YardForce RM-ECOW-V1.0.0<br>- Fix heap overflow which could happen when an action button got pressed multiple (10-20) times | 2024-09-29
| 2.05 | - YardForce RM-ECOW-V1.1.0 support<br>- Backside alive LED is now software driven (hwtimer independent)<br>- Fix emergency-clear LED-countdown for RM-ECOW-V1.0.0| 2024-06-30
| 2.04 | - YardForce RM-ECOW-V1.0.0 support<br>- Dropped separate versioning<br>- Fully refactored | 2023-11-14
| 1.00 | - YardForce SAxPRO (Rev6) Dot-Matrix-Display support | 2023-09-27
Expand Down
16 changes: 8 additions & 8 deletions Firmware/CoverUI/YardForce/include/Emergency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file Emergency.hpp
* @author Apehaenger ([email protected])
* @brief YardForce CoverUI Emergency class for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.4
* @date 2024-10-02
* @version 0.5
* @date 2024-10-30
*
* @copyright Copyright (c) 2023, 2024
*
Expand All @@ -25,7 +25,7 @@ class Emergency {
struct PinStateDef {
uint8_t pin;
uint8_t pin_mode;
Emergency_state state;
EmergencyState state;
};

const PinStateDef *kPinStatesPtr; // Pointer to an array of PinStateDef's (order doesn't matter)
Expand All @@ -43,14 +43,14 @@ class Emergency {
*
*/
void read() {
state_ = 0; // We might have more emergency sensors and switch than OM Emergency_states. So we need to OR them instead of assign them 1:1
state_ = 0;
for (size_t i = 0; i < kNumEmergencies; i++) {
auto pin_state = *(kPinStatesPtr + i);
if (digitalRead(pin_state.pin) == HIGH)
state_ |= pin_state.state;
state_ |= (int)pin_state.state;
}
if (state_)
state_ |= Emergency_state::Emergency_latch;
state_ |= (int)EmergencyState::LATCH;
}

/**
Expand All @@ -73,7 +73,7 @@ class Emergency {
void read_and_send_if_emergency() {
read();

if (state_ & Emergency_state::Emergency_latch && !(state_last_sent_ & Emergency_state::Emergency_latch)) {
if (state_ & (int)EmergencyState::LATCH && !(state_last_sent_ & (int)EmergencyState::LATCH)) {
send();
next_periodic_cycle = millis() + PERIODIC_SEND_CYCLE;
}
Expand All @@ -87,7 +87,7 @@ class Emergency {
*/
void periodic_send() {
// Active emergency
if (state_ & Emergency_state::Emergency_latch) {
if (state_ & (int)EmergencyState::LATCH) {
send();
next_periodic_cycle = millis() + PERIODIC_SEND_CYCLE;
return;
Expand Down
40 changes: 25 additions & 15 deletions Firmware/CoverUI/YardForce/include/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,30 @@ enum HighLevelMode {
MODE_RECORDING = 3 // ROS connected, Manual mode during recording etc
};

#define LL_EMERGENCY_BIT_LATCH 0b00000001
#define LL_EMERGENCY_BIT_HALL1 0b00001000
#define LL_EMERGENCY_BIT_HALL2 0b00010000
#define LL_EMERGENCY_BIT_HALL3 0b00000010
#define LL_EMERGENCY_BIT_HALL4 0b00000100
// clang-format off
#define LL_EMERGENCY_BIT_LATCH (1 << 0) // Any emergency latch
#define LL_EMERGENCY_BIT_STOP (1 << 1) // Stop
#define LL_EMERGENCY_BIT_LIFT (1 << 2) // Lift (or tilt)

#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 LL_EMERGENCY_BIT_CU_LATCH (1 << 0) // Any emergency latch
#define LL_EMERGENCY_BIT_CU_STOP1 (1 << 1) // Stop1
#define LL_EMERGENCY_BIT_CU_STOP2 (1 << 2) // Stop2
#define LL_EMERGENCY_BIT_CU_LIFT (1 << 3) // LIFT
#define LL_EMERGENCY_BIT_CU_LBUMP (1 << 4) // LBUMP
#define LL_EMERGENCY_BIT_CU_LIFTX (1 << 5) // LIFTX
#define LL_EMERGENCY_BIT_CU_RBUMP (1 << 6) // RBUMP
// clang-format on

// Same bitmask as in ll_status.emergency_bitmask (LowLevel, datatypes.h)
enum class EmergencyState {
LATCH = LL_EMERGENCY_BIT_CU_LATCH,
STOP1 = LL_EMERGENCY_BIT_CU_STOP1,
STOP2 = LL_EMERGENCY_BIT_CU_STOP2,
LIFT = LL_EMERGENCY_BIT_CU_LIFT,
LBUMP = LL_EMERGENCY_BIT_CU_LBUMP,
LIFTX = LL_EMERGENCY_BIT_CU_LIFTX,
RBUMP = LL_EMERGENCY_BIT_CU_RBUMP
};

#pragma pack(push, 1)
struct ll_status {
Expand All @@ -63,10 +75,8 @@ struct ll_status {
float uss_ranges_m[5];
// Emergency bitmask:
// Bit 0: Emergency latch
// Bit 1: Emergency 0 active
// Bit 2: Emergency 1 active
// Bit 3: Emergency 2 active
// Bit 4: Emergency 3 active
// Bit 1: Emergency/Stop
// Bit 2: Emergency/Lift (or tilt)
uint8_t emergency_bitmask;
// Charge voltage
float v_charge;
Expand Down
12 changes: 6 additions & 6 deletions Firmware/CoverUI/YardForce/model/C500/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file C500/assembly.cpp
* @author Apehaenger ([email protected])
* @brief YardForce RM-ECOW-V1.0.0 CoverUI Assembly for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2024-10-01
* @version 0.2
* @date 2024-10-30
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -88,9 +88,9 @@ ButtonsC500 buttons(kBtnDefByButtonNumMap);

// ----- Emergency -----
const Emergency::PinStateDef kEmergencyPinStateDefs[] = {
{PIN_HALL_STOP_WHITE, INPUT, Emergency_state::Emergency_stop1},
{PIN_HALL_STOP_YELLOW, INPUT, Emergency_state::Emergency_stop2},
{PIN_HALL_WHEEL_RED, INPUT, Emergency_state::Emergency_lift1},
{PIN_HALL_WHEEL_BLUE, INPUT, Emergency_state::Emergency_lift2}};
{PIN_HALL_STOP_WHITE, INPUT, EmergencyState::STOP1},
{PIN_HALL_STOP_YELLOW, INPUT, EmergencyState::STOP2},
{PIN_HALL_WHEEL_RED, INPUT, EmergencyState::LIFT},
{PIN_HALL_WHEEL_BLUE, INPUT, EmergencyState::LIFTX}};

Emergency emergency(kEmergencyPinStateDefs, sizeof(kEmergencyPinStateDefs) / sizeof(Emergency::PinStateDef));
4 changes: 2 additions & 2 deletions Firmware/CoverUI/YardForce/model/RM-EC3-V11/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void DisplayRMEC3V11::loop_low_prio() {

// Emergencies
static bool last_stop_button = false;
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BITS_STOP) // Stop switch
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BIT_STOP) // Stop switch
{
v_led_emergency_stop->set(LED_blink_fast);
strncpy(status_ticker, EMERGENCY_CLEAR_TEXT, STATUS_TICKER_LENGTH);
Expand All @@ -295,7 +295,7 @@ void DisplayRMEC3V11::loop_low_prio() {
last_stop_button = false;
}

if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BITS_LIFT) // Lifted or tilted
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BIT_LIFT) // Lifted or tilted
{
v_led_emergency_wheel->set(LED_blink_fast);
strncpy(status_ticker, EMERGENCY_CLEAR_TEXT, STATUS_TICKER_LENGTH);
Expand Down
12 changes: 6 additions & 6 deletions Firmware/CoverUI/YardForce/model/RM-EC3-V11/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ ButtonsRMEC3V11 buttons(kBtnDefByButtonNumMap);

const Emergency::PinStateDef kEmergencyPinStateDefs[] = {
#ifdef MOD_HALL
{PIN_HALL1, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL2, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL3, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_HALL4, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_LIFT, INPUT_PULLUP, EmergencyState::LIFT},
{PIN_LIFTX, INPUT_PULLUP, EmergencyState::LIFTX},
{PIN_LBUMP, INPUT_PULLUP, EmergencyState::LBUMP},
{PIN_RBUMP, INPUT_PULLUP, EmergencyState::RBUMP},
#endif
#ifdef MOD_STOP
{PIN_STOP1, INPUT_PULLUP, Emergency_state::Emergency_stop1},
{PIN_STOP2, INPUT_PULLUP, Emergency_state::Emergency_stop2},
{PIN_STOP1, INPUT_PULLUP, EmergencyState::STOP1},
{PIN_STOP2, INPUT_PULLUP, EmergencyState::STOP2},
#endif
};

Expand Down
12 changes: 6 additions & 6 deletions Firmware/CoverUI/YardForce/model/RM-EC3-V11/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file RM-EC3-V11/assembly.hpp
* @author Apehaenger ([email protected])
* @brief YardForce RM-EC3-V1.1 CoverUI Assembly for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2024-10-01
* @version 0.2
* @date 2024-10-30
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -61,10 +61,10 @@ extern LEDcontrolRMEC3V11 leds;
#define PIN_STOP1 PC15
#define PIN_STOP2 PB6

#define PIN_HALL1 PB15
#define PIN_HALL2 PC0
#define PIN_HALL3 PC8
#define PIN_HALL4 PC9
#define PIN_LIFT PC0
#define PIN_LIFTX PC9
#define PIN_LBUMP PC8
#define PIN_RBUMP PB15

class ButtonsRMEC3V11 : public Buttons {
public:
Expand Down
16 changes: 8 additions & 8 deletions Firmware/CoverUI/YardForce/model/RM-ECOW-V100/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file RM-ECOW-V100/assembly.cpp
* @author Apehaenger ([email protected])
* @brief YardForce RM-ECOW-V1.0.0 CoverUI Assembly for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2024-10-01
* @version 0.2
* @date 2024-10-30
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -87,14 +87,14 @@ ButtonsRMECOWV100 buttons(kBtnDefByButtonNumMap);
// ----- Emergency -----
const Emergency::PinStateDef kEmergencyPinStateDefs[] = {
#ifdef MOD_HALL
{PIN_HALL1, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL2, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL3, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_HALL4, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_LIFT, INPUT_PULLUP, EmergencyState::LIFT},
{PIN_LIFTX, INPUT_PULLUP, EmergencyState::LIFTX},
{PIN_LBUMP, INPUT_PULLUP, EmergencyState::LBUMP},
{PIN_RBUMP, INPUT_PULLUP, EmergencyState::RBUMP},
#endif
#ifdef MOD_STOP
{PIN_STOP_JP5, INPUT_PULLUP, Emergency_state::Emergency_stop1},
{PIN_STOP_JP6, INPUT_PULLUP, Emergency_state::Emergency_stop2}
{PIN_STOP_JP5, INPUT_PULLUP, EmergencyState::STOP1},
{PIN_STOP_JP6, INPUT_PULLUP, EmergencyState::STOP2}
#endif
};

Expand Down
12 changes: 6 additions & 6 deletions Firmware/CoverUI/YardForce/model/RM-ECOW-V100/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file RM-ECOW-V100/assembly.hpp
* @author Apehaenger ([email protected])
* @brief YardForce RM-ECOW-V1.0.0 CoverUI Assembly for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2024-10-01
* @version 0.2
* @date 2024-10-30
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -55,10 +55,10 @@
#define PIN_STOP_JP5 PC10
#define PIN_STOP_JP6 PA15

#define PIN_HALL1 PA8 // LIFT
#define PIN_HALL2 PF6 // LIFTX
#define PIN_HALL3 PA12 // LBUMP
#define PIN_HALL4 PA11 // RBUMP
#define PIN_LIFT PA8
#define PIN_LIFTX PF6
#define PIN_LBUMP PA12
#define PIN_RBUMP PA11

extern LEDcontrolRMECOWV1x leds;

Expand Down
16 changes: 8 additions & 8 deletions Firmware/CoverUI/YardForce/model/RM-ECOW-V110/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file RM-ECOW-V100/assembly.cpp
* @author Apehaenger ([email protected])
* @brief YardForce RM-ECOW-V1.0.0 CoverUI Assembly for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2024-10-01
* @version 0.2
* @date 2024-10-30
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -86,14 +86,14 @@ ButtonsRMECOWV110 buttons(kBtnDefByButtonNumMap);
// ----- Emergency -----
const Emergency::PinStateDef kEmergencyPinStateDefs[] = {
#ifdef MOD_HALL
{PIN_HALL1, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL2, INPUT_PULLUP, Emergency_state::Emergency_lift1},
{PIN_HALL3, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_HALL4, INPUT_PULLUP, Emergency_state::Emergency_lift2},
{PIN_LIFT, INPUT_PULLUP, EmergencyState::LIFT},
{PIN_LIFTX, INPUT_PULLUP, EmergencyState::LIFTX},
{PIN_LBUMP, INPUT_PULLUP, EmergencyState::LBUMP},
{PIN_RBUMP, INPUT_PULLUP, EmergencyState::RBUMP},
#endif
#ifdef MOD_STOP
{PIN_STOP_JP6, INPUT_PULLUP, Emergency_state::Emergency_stop1},
{PIN_STOP_JP8, INPUT_PULLUP, Emergency_state::Emergency_stop2},
{PIN_STOP_JP6, INPUT_PULLUP, EmergencyState::STOP1},
{PIN_STOP_JP8, INPUT_PULLUP, EmergencyState::STOP2},
#endif
};

Expand Down
8 changes: 4 additions & 4 deletions Firmware/CoverUI/YardForce/model/RM-ECOW-V110/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
#define PIN_STOP_JP6 PC10
#define PIN_STOP_JP8 PA15

#define PIN_HALL1 PA8 // LIFT
#define PIN_HALL2 PA9 // LIFTX
#define PIN_HALL3 PC8 // LBUMP
#define PIN_HALL4 PC9 // RBUMP
#define PIN_LIFT PA8 // LIFT
#define PIN_LIFTX PA9 // LIFTX
#define PIN_LBUMP PC8 // LBUMP
#define PIN_RBUMP PC9 // RBUMP

extern LEDcontrolRMECOWV1x leds;

Expand Down
4 changes: 2 additions & 2 deletions Firmware/CoverUI/YardForce/model/SAxPRO/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void DisplaySAXPRO::loop_low_prio() {

// Emergencies
static bool last_stop_button = false;
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BITS_STOP) // Stop switch
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BIT_STOP) // Stop switch
{
v_led_emergency_stop->set(LED_blink_fast);
strncpy(status_ticker, EMERGENCY_CLEAR_TEXT, STATUS_TICKER_LENGTH);
Expand All @@ -293,7 +293,7 @@ void DisplaySAXPRO::loop_low_prio() {
last_stop_button = false;
}

if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BITS_LIFT) // Lifted or tilted
if (subscription::recv_ll_status.emergency_bitmask & LL_EMERGENCY_BIT_LIFT) // Lifted or tilted
{
v_led_emergency_wheel->set(LED_blink_fast);
strncpy(status_ticker, EMERGENCY_CLEAR_TEXT, STATUS_TICKER_LENGTH);
Expand Down

0 comments on commit 77110e2

Please sign in to comment.