Skip to content

Commit

Permalink
Feature: Add Support for BMS Tiltback
Browse files Browse the repository at this point in the history
  • Loading branch information
Relys committed Mar 10, 2025
1 parent a53f92e commit 2ee12a4
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 10 deletions.
19 changes: 19 additions & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@

; Set firmware version:
(apply ext-set-fw-version (sysinfo 'fw-ver))
(def version_major (first (sysinfo 'fw-ver)))
(def version_minor (second (sysinfo 'fw-ver)))

; Setup thread for BMS Tiltback
(if (or (and (= version_major 6) (>= version_minor 6)) (>= version_major 7)) {
(loopwhile-thd 50 t {
(if (and (>= (get-bms-val 'bms-can-id) 0) (ext-bms)) {
(var bms-temp-cell-max (get-bms-val 'bms-temp-cell-max))
(var bms-temp-cell-min bms-temp-cell-max)
(var bms-temp-mosfet -281)
(if (= (get-bms-val 'bms-data-version) 1) {
(setq bms-temp-cell-min (get-bms-val 'bms-temps-adc 1))
(setq bms-temp-mosfet (get-bms-val 'bms-temps-adc 3))
})
(ext-bms (get-bms-val 'bms-v-cell-min) (get-bms-val 'bms-v-cell-max) bms-temp-cell-min bms-temp-cell-max bms-temp-mosfet (get-bms-val 'bms-msg-age))
})
(sleep 0.2)
})
})

; Set to 1 to monitor debug variables
(define debug 1)
Expand Down
31 changes: 31 additions & 0 deletions src/bms.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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_get_fault(uint32_t fault_mask, BMSFaultCode fault_code) {
return (fault_mask & (1U << (fault_code - 1))) != 0;
}

void bms_set_fault(uint32_t *fault_mask, BMSFaultCode fault_code) {
if (fault_code == BMSF_NONE) {
*fault_mask = BMSF_NONE;
return;
}

*fault_mask |= (1U << (fault_code - 1));
}
36 changes: 36 additions & 0 deletions src/bms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_get_fault(uint32_t fault_mask, BMSFaultCode fault_code);

void bms_set_fault(uint32_t *fault_mask, BMSFaultCode fault_code);
8 changes: 8 additions & 0 deletions src/conf/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ typedef struct {
float tiltback_variable;
float tiltback_variable_max;
uint16_t tiltback_variable_erpm;
bool tiltback_bms_enabled;
float tiltback_cell_lv;
float tiltback_cell_hv;
int8_t tiltback_cell_lt;
int8_t tiltback_cell_ht;
int8_t tiltback_bms_ht;
float tiltback_bms_msg;
float tiltback_cell_bal;
FLOAT_INPUTTILT_REMOTE_TYPE inputtilt_remote_type;
float inputtilt_speed;
float inputtilt_angle_limit;
Expand Down
189 changes: 189 additions & 0 deletions src/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,178 @@ p, li { white-space: pre-wrap; }
<suffix> ERPM</suffix>
<vTx>3</vTx>
</tiltback_variable_erpm>
<tiltback_bms_enabled>
<longName>Enable BMS Tiltback</longName>
<type>5</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_BMS_ENABLED</cDefine>
<valInt>0</valInt>
</tiltback_bms_enabled>
<tiltback_cell_lv>
<longName>Cell Low Voltage Threshold</longName>
<type>1</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Low Voltage threshold per cell to trigger a safety pushback.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 3.0V&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_CELL_LV</cDefine>
<editorDecimalsDouble>2</editorDecimalsDouble>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>4.3</maxDouble>
<minDouble>2.5</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>0.01</stepDouble>
<valDouble>3</valDouble>
<vTxDoubleScale>1000</vTxDoubleScale>
<suffix> V</suffix>
<vTx>7</vTx>
</tiltback_cell_lv>
<tiltback_cell_hv>
<longName>Cell High Voltage Threshold</longName>
<type>1</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;High Voltage threshold per cell to trigger a safety pushback.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 4.2V&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_CELL_HV</cDefine>
<editorDecimalsDouble>2</editorDecimalsDouble>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>4.3</maxDouble>
<minDouble>2.5</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>0.01</stepDouble>
<valDouble>4.2</valDouble>
<vTxDoubleScale>1000</vTxDoubleScale>
<suffix> V</suffix>
<vTx>7</vTx>
</tiltback_cell_hv>
<tiltback_cell_lt>
<longName>Cell Low Temp Threshold</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Low Temp threshold per cell to trigger a safety pushback.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: -10 C&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_CELL_LT</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>60</maxInt>
<minInt>-10</minInt>
<showDisplay>0</showDisplay>
<stepInt>1</stepInt>
<valInt>-10</valInt>
<suffix> C</suffix>
<vTx>2</vTx>
</tiltback_cell_lt>
<tiltback_cell_ht>
<longName>Cell High Temp Threshold</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;High Temp threshold per cell to trigger a safety pushback.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 45 C&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_CELL_HT</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>60</maxInt>
<minInt>-10</minInt>
<showDisplay>0</showDisplay>
<stepInt>1</stepInt>
<valInt>45</valInt>
<suffix> C</suffix>
<vTx>2</vTx>
</tiltback_cell_ht>
<tiltback_bms_ht>
<longName>BMS MOSFET High Temp Threshold</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;High Temp threshold for BMS MOSFET to trigger a safety pushback (if bms-data-version = 1).&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 60 C&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_BMS_HT</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>70</maxInt>
<minInt>-10</minInt>
<showDisplay>0</showDisplay>
<stepInt>1</stepInt>
<valInt>60</valInt>
<suffix> C</suffix>
<vTx>2</vTx>
</tiltback_bms_ht>
<tiltback_bms_msg>
<longName>BMS Communication Threshold</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;BMS Communication threshold to trigger a safety pushback.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 1 sec&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_BMS_MSG</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>5</maxInt>
<minInt>0</minInt>
<showDisplay>0</showDisplay>
<stepInt>1</stepInt>
<valInt>1</valInt>
<suffix> sec</suffix>
<vTx>1</vTx>
</tiltback_bms_msg>
<tiltback_cell_bal>
<longName>Cell Balance Threshold</longName>
<type>1</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Cell Balance threshold to trigger a warning beep while idle.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Recommended Value: 0.5 V&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_TILTBACK_CELL_BAL</cDefine>
<editorDecimalsDouble>2</editorDecimalsDouble>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>2</maxDouble>
<minDouble>0</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>0.01</stepDouble>
<valDouble>0.5</valDouble>
<vTxDoubleScale>100</vTxDoubleScale>
<suffix> v</suffix>
<vTx>7</vTx>
</tiltback_cell_bal>
<noseangling_speed>
<longName>Nose Angling Speed</longName>
<type>1</type>
Expand Down Expand Up @@ -3420,6 +3592,14 @@ p, li { white-space: pre-wrap; }
<ser>hardware.leds.rear.reverse</ser>
<ser>is_beeper_enabled</ser>
<ser>disabled</ser>
<ser>tiltback_bms_enabled</ser>
<ser>tiltback_cell_lv</ser>
<ser>tiltback_cell_hv</ser>
<ser>tiltback_cell_lt</ser>
<ser>tiltback_cell_ht</ser>
<ser>tiltback_bms_msg</ser>
<ser>tiltback_cell_bal</ser>
<ser>tiltback_bms_ht</ser>
</SerOrder>
<Grouping>
<group>
Expand Down Expand Up @@ -3553,6 +3733,15 @@ p, li { white-space: pre-wrap; }
<param>::sep::Low Voltage Alert Pushback</param>
<param>tiltback_lv_angle</param>
<param>tiltback_lv_speed</param>
<param>::sep::BMS Pushback (6.06+)</param>
<param>tiltback_bms_enabled</param>
<param>tiltback_cell_lv</param>
<param>tiltback_cell_hv</param>
<param>tiltback_cell_lt</param>
<param>tiltback_cell_ht</param>
<param>tiltback_bms_ht</param>
<param>tiltback_bms_msg</param>
<param>tiltback_cell_bal</param>
</subgroupParams>
</subgroup>
<subgroup>
Expand Down
2 changes: 2 additions & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ typedef struct {
float rc_current_target;
float rc_current;

uint32_t bms_fault;

Konami flywheel_konami;
Konami headlights_on_konami;
Konami headlights_off_konami;
Expand Down
Loading

0 comments on commit 2ee12a4

Please sign in to comment.