-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
197 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 Syler Clayton | ||
// | ||
// This file is part of the Refloat VESC package. | ||
// | ||
// Refloat VESC package is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by the | ||
// Free Software Foundation, either version 3 of the License, or (at your | ||
// option) any later version. | ||
// | ||
// Refloat VESC package is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include "bms.h" | ||
|
||
bool bms_is_fault_set(uint32_t fault_mask, BMSFaultCode fault_code) { | ||
if (fault_code < 1 || fault_code > 32) { | ||
return false; | ||
} | ||
return (fault_mask & (1U << (fault_code - 1))) != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 Syler Clayton | ||
// | ||
// This file is part of the Refloat VESC package. | ||
// | ||
// Refloat VESC package is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by the | ||
// Free Software Foundation, either version 3 of the License, or (at your | ||
// option) any later version. | ||
// | ||
// Refloat VESC package is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
typedef enum { | ||
NONE = 0, | ||
BMS_CONNECTION = 1, | ||
BMS_OVER_TEMP = 2, | ||
BMS_CELL_OVER_VOLTAGE = 3, | ||
BMS_CELL_UNDER_VOLTAGE = 4, | ||
BMS_CELL_OVER_TEMP = 5, | ||
BMS_CELL_UNDER_TEMP = 6, | ||
BMS_CELL_BALANCE = 7 | ||
} BMSFaultCode; | ||
|
||
bool bms_is_fault_set(uint32_t fault_mask, BMSFaultCode fault_code); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(defun bms-loop () { | ||
(var bms-vmin-limit-start (conf-get 'bms-vmin-limit-start)) | ||
(var bms-vmax-limit-start (conf-get 'bms-vmax-limit-start)) | ||
(var bms-tmax-limit-start (- (conf-get 'bms-t-limit-start) 3)) ; Start 3 degrees before Motor CFG -> BMS limiting functionality would happen. | ||
(var bms-tmin-limit-start 0) | ||
(var bms-cell-balance-start 0.5) | ||
(var bms-ic-tmax-limit-start (+ bms-tmax-limit-start 15)) ; Set bms temp limit to +15C past cell limit | ||
(var bms-config-update-time (systime)) | ||
(var bms-fault 0u32) | ||
(var bms-fault-codes '( | ||
(NONE . 0) | ||
(BMS_CONNECTION . 1) | ||
(BMS_OVER_TEMP . 2) | ||
(BMS_CELL_OVER_VOLTAGE . 3) | ||
(BMS_CELL_UNDER_VOLTAGE . 4) | ||
(BMS_CELL_OVER_TEMP . 5) | ||
(BMS_CELL_UNDER_TEMP . 6) | ||
(BMS_CELL_BALANCE . 7) | ||
)) | ||
(defun bms-set-fault (fault-code) { | ||
(if (eq fault-code 'NONE) { | ||
(setq bms-fault 0u32) | ||
}{ | ||
(setq bms-fault (bitwise-or bms-fault (shl 1 (- (assoc bms-fault-codes fault-code) 1)))) | ||
}) | ||
}) | ||
(loopwhile t { | ||
(if (and (<= (get-duty) 0.05) (> (secs-since bms-config-update-time) 1.0)) { ; Only bother updating config values while board is idle | ||
(setq bms-vmin-limit-start (conf-get 'bms-vmin-limit-start)) | ||
(setq bms-vmax-limit-start (conf-get 'bms-vmax-limit-start)) | ||
(setq bms-tmax-limit-start (- (conf-get 'bms-t-limit-start) 3)) | ||
(setq bms-ic-tmax-limit-start (+ bms-tmax-limit-start 15)) | ||
(setq bms-config-update-time (systime)) | ||
}) | ||
(if (>= (get-bms-val 'bms-msg-age) 2.0) { | ||
(bms-set-fault 'BMS_CONNECTION) | ||
} { | ||
(bms-set-fault 'NONE) | ||
(if (>= (get-bms-val 'bms-v-cell-max) bms-vmax-limit-start) (bms-set-fault 'BMS_CELL_OVER_VOLTAGE)) | ||
(if (<= (get-bms-val 'bms-v-cell-min) bms-vmin-limit-start) (bms-set-fault 'BMS_CELL_UNDER_VOLTAGE)) | ||
(if (>= (get-bms-val 'bms-temp-cell-max) bms-tmax-limit-start) (bms-set-fault 'BMS_CELL_OVER_TEMP)) | ||
(if (<= (get-bms-val 'bms-temp-cell-max) bms-tmin-limit-start) (bms-set-fault 'BMS_CELL_UNDER_TEMP)) | ||
(if (>= (abs (- v-cell-max v-cell-min)) bms-cell-balance-start) (bms-set-fault 'BMS_CELL_BALANCE)) | ||
(if (>= (get-bms-val 'bms-temp-ic) bms-ic-tmax-limit-start) (bms-set-fault 'BMS_OVER_TEMP)) | ||
}) | ||
(apply ext-bms-set-fault bms-fault) | ||
(yield 10000) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters