-
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.
Feature: Add Support for BMS Tiltback
- Loading branch information
Showing
6 changed files
with
227 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 <stdbool.h> | ||
#include <stdint.h> | ||
|
||
typedef enum { | ||
BMSF_NONE = 0, | ||
BMSF_CONNECTION = 1, | ||
BMSF_OVER_TEMP = 2, | ||
BMSF_CELL_OVER_VOLTAGE = 3, | ||
BMSF_CELL_UNDER_VOLTAGE = 4, | ||
BMSF_CELL_OVER_TEMP = 5, | ||
BMSF_CELL_UNDER_TEMP = 6, | ||
BMSF_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,75 @@ | ||
(defun bms-loop () { | ||
(var vmin-limit) | ||
(var vmax-limit) | ||
(var tmax-limit) | ||
(var tmin-limit 0) | ||
(var cell-balance 0.5) | ||
(var ic-tmax-limit) | ||
(var config-update-time) | ||
(var fault 0u32) | ||
(var v-cell-support (eq (first (trap (get-bms-val 'bms-v-cell-min))) 'exit-ok)) | ||
(defun update-config { | ||
(setq vmin-limit (conf-get 'bms-vmin-limit-start)) | ||
(setq vmax-limit (conf-get 'bms-vmax-limit-start)) | ||
(setq tmax-limit (- (conf-get 'bms-t-limit-start) 3)) ; Start 3 degrees before Motor CFG -> BMS limiting functionality would happen. | ||
(setq ic-tmax-limit (+ tmax-limit-start 15)) ; Set bms temp limit to +15C past cell limit | ||
(setq config-update-time (systime)) | ||
}) | ||
(var fault-codes '( | ||
(BMSF_NONE . 0) | ||
(BMSF_CONNECTION . 1) | ||
(BMSF_OVER_TEMP . 2) | ||
(BMSF_CELL_OVER_VOLTAGE . 3) | ||
(BMSF_CELL_UNDER_VOLTAGE . 4) | ||
(BMSF_CELL_OVER_TEMP . 5) | ||
(BMSF_CELL_UNDER_TEMP . 6) | ||
(BMSF_CELL_BALANCE . 7) | ||
)) | ||
(defun set-fault (fault-code) { | ||
(if (eq fault-code 'BMSF_NONE) { | ||
(setq fault 0u32) | ||
}{ | ||
(setq fault (bitwise-or fault (shl 1 (- (assoc fault-codes fault-code) 1)))) | ||
}) | ||
}) | ||
(update-config) | ||
(loopwhile t { | ||
(if (> (secs-since config-update-time) 1.0) { | ||
(update-config) | ||
}) | ||
(if (>= (get-bms-val 'bms-msg-age) 2.0) { | ||
(set-fault 'BMSF_CONNECTION) | ||
} { | ||
(set-fault 'BMSF_NONE) | ||
|
||
(var v-cell-min) | ||
(var v-cell-max) | ||
(if v-cell-support { | ||
(setq v-cell-min (get-bms-val 'bms-v-cell-min)) | ||
(setq v-cell-max (get-bms-val 'bms-v-cell-max)) | ||
} { | ||
(var num-cells (get-bms-val 'bms-cell-num)) | ||
(if (> num-cells 1) { | ||
(setq v-cell-max (get-bms-val 'bms-v-cell 0)) | ||
(setq v-cell-min (get-bms-val 'bms-v-cell 0)) | ||
(looprange i 1 num-cells { | ||
(var cell-volt (get-bms-val 'bms-v-cell i)) | ||
(if (> cell-volt v-cell-max) | ||
(setq v-cell-max cell-volt)) | ||
(if (< cell-volt v-cell-min) | ||
(setq v-cell-min cell-volt)) | ||
}) | ||
}) | ||
}) | ||
|
||
(if (>= v-cell-max vmax-limit) (set-fault 'BMSF_CELL_OVER_VOLTAGE)) | ||
(if (<= v-cell-min vmin-limit) (set-fault 'BMSF_CELL_UNDER_VOLTAGE)) | ||
(if (>= (get-bms-val 'bms-temp-cell-max) tmax-limit) (set-fault 'BMSF_CELL_OVER_TEMP)) | ||
(if (<= (get-bms-val 'bms-temp-cell-max) tmin-limit) (set-fault 'BMSF_CELL_UNDER_TEMP)) | ||
(if (>= (abs (- v-cell-max v-cell-min)) cell-balance) (set-fault 'BMSF_CELL_BALANCE)) | ||
(if (>= (get-bms-val 'bms-temp-ic) ic-tmax-limit) (set-fault 'BMSF_OVER_TEMP)) | ||
}) | ||
(apply ext-bms-set-fault fault) | ||
(yield 200000) | ||
}) | ||
}) |
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