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

Esc shutdown #1

Open
wants to merge 2 commits into
base: esc_shutdown
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Firmware/LowLevel/src/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum HighLevelMode {
#define LL_EMERGENCY_BIT_STOP2 LL_EMERGENCY_BIT_HALL4
#define LL_EMERGENCY_BITS_STOP (LL_EMERGENCY_BIT_STOP1 | LL_EMERGENCY_BIT_STOP2)

#define LL_STATUS_BIT_UI_AVAIL 0b10000000
#define LL_STATUS_BIT_ESC_POWER 0b1 << 3
#define LL_STATUS_BIT_UI_AVAIL 0b1 << 7

#pragma pack(push, 1)
struct ll_status {
Expand Down
20 changes: 13 additions & 7 deletions Firmware/LowLevel/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define LIFT_EMERGENCY_MILLIS 100 // Time for both wheels to be lifted in order to count as emergency (0 disable). This is to filter uneven ground.
#define BUTTON_EMERGENCY_MILLIS 20 // Time for button emergency to activate. This is to debounce the button.

#define SHUTDOWN_ESC_MAX_PITCH 15.0 // Do not shutdown ESCs if absolute pitch angle is greater than this
#define SHUTDOWN_ESC_MAX_TILT 15.0f // Shutdown ESCs if tilt angle is greater than this
// Define to stream debugging messages via USB
// #define USB_DEBUG

Expand Down Expand Up @@ -699,17 +699,17 @@ void loop() {
#endif

#ifdef SHUTDOWN_ESC_WHEN_IDLE
// ESC power saving when mower is IDLE
if(!ROS_running || last_high_level_state.current_mode != HighLevelMode::MODE_IDLE || fabs(pitch_angle) > SHUTDOWN_ESC_MAX_PITCH) {
// Enable escs if not idle, or if ROS is not running, or on a slope
// ESC power saving and safety shutdown
if ((!ROS_running || last_high_level_state.current_mode != HighLevelMode::MODE_IDLE) && tilt_angle <= SHUTDOWN_ESC_MAX_TILT) {
// Enable ESCs if ROS is not running, or not idle, but in any case only if not tilted
digitalWrite(PIN_ESC_SHUTDOWN, LOW);
status_message.status_bitmask |= 0b1000;
status_message.status_bitmask |= LL_STATUS_BIT_ESC_POWER;
} else {
digitalWrite(PIN_ESC_SHUTDOWN, HIGH);
status_message.status_bitmask &= 0b11110111;
status_message.status_bitmask &= ~LL_STATUS_BIT_ESC_POWER;
}
#else
status_message.status_bitmask |= 0b1000;
status_message.status_bitmask |= LL_STATUS_BIT_ESC_POWER;
#endif

status_message.status_bitmask = (status_message.status_bitmask & 0b11111011) | ((charging_allowed & 0b1) << 2);
Expand Down Expand Up @@ -743,6 +743,12 @@ void loop() {
DEBUG_SERIAL.print(" A\t");
DEBUG_SERIAL.print("emergency: 0b");
DEBUG_SERIAL.print(status_message.emergency_bitmask, BIN);
DEBUG_SERIAL.print("\troll: ");
DEBUG_SERIAL.print(roll_angle, 3);
DEBUG_SERIAL.print("\tpitch: ");
DEBUG_SERIAL.print(pitch_angle, 3);
DEBUG_SERIAL.print("\ttilt: ");
DEBUG_SERIAL.print(tilt_angle, 3);
DEBUG_SERIAL.println();
#endif
}
Expand Down