Skip to content

Commit

Permalink
Bring up complete motor controller yamcan definition
Browse files Browse the repository at this point in the history
Added support for signal ID offset
  • Loading branch information
freeman803 committed Feb 6, 2025
1 parent 6e9308d commit 7adac13
Show file tree
Hide file tree
Showing 11 changed files with 1,393 additions and 28 deletions.
6 changes: 4 additions & 2 deletions components/bms_boss/include/CANIO_componentSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ CAN_prechargeContactorState_E CANIO_tx_getContactorState(void);
#define set_elconMaxChargeCurrent(m,b,n,s) set(m,b,n,s, BMS.pack_charge_limit)
#define set_elconControlByte(m,b,n,s) set(m,b,n,s, CANIO_tx_getElconControlByte())
#define transmit_BMSB_elconChargeCommand (SYS_SFT_checkElconChargerTimeout() == false)

#include "TemporaryStubbing.h"
#define transmit_BMSB_currentLimit (SYS_SFT_checkMCTimeout() == false)
#define set_maxCharge(m,b,n,s) set(m,b,n,s, BMS.pack_charge_limit);
#define set_maxDischarge(m,b,n,s) set(m,b,n,s, BMS.pack_discharge_limit);
#include "TemporaryStubbing.h"
33 changes: 15 additions & 18 deletions network/NetworkGen/NetworkGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"description": str,
"onBuses": Or(str, list[str]),
Optional("duplicateNode"): int,
Optional("baseId"): int,
})

SIGNAL_SCHEMA = Schema({
Expand All @@ -58,6 +59,7 @@
Optional("description"): str,
Optional("cycleTimeMs"): int,
Optional("id"): int,
Optional("idOffset"): int,
Optional("lengthBytes"): int,
Optional("sourceBuses"): Or(str, list[str]),
Optional("signals"): dict,
Expand Down Expand Up @@ -357,30 +359,25 @@ def process_node(node: CanNode):
MESSAGE_SCHEMA.validate(definition)
if "lengthBytes" in definition and (definition["lengthBytes"] < 1 or definition["lengthBytes"] > 8):
raise Exception("Message length must be greater than 0 and less than or equal to 8")
if "id" not in definition:
raise Exception("Message must have a specified 'id'")
if "id" not in definition and "idOffset" not in definition:
raise Exception("Message must have a specified 'id' or 'idOffset'")
elif "id" in definition and "idOffset" in definition:
raise Exception("Message cannot have an 'id' and 'idOffset' at the same time")
except Exception as e:
print(f"CAN message definition for '{name}' in node '{node.name}' is invalid.")
print(f"Message Schema Error: {e}")
error = True
continue

definition["id"] = definition["id"] + node.offset;
if "sourceBuses" in definition:
ls = []
if type(definition["sourceBuses"]) is str:
ls.append(definition["sourceBuses"])
else:
ls = definition["sourceBuses"]
for bus in ls:
if bus not in can_bus_defs:
print(f"Message '{msg_name}' has an undefined bus '{bus}'.")
ERROR = True
break
if bus not in node.on_buses:
print(f"Message '{msg_name}' is on bus '{bus}' but node '{node.name}' is not on that bus.")
ERROR = True
break
if "idOffset" in definition:
if node.baseId is None:
print(f"Message '{name}' has a 'idOffset' specified and {node.name} does not have a 'baseId' specified")
ERROR = True
break
else:
definition["id"] = definition["idOffset"] + node.baseId + node.offset
else:
definition["id"] = definition["id"] + node.offset

for existing_node in can_nodes:
for msg in can_nodes[existing_node].messages:
Expand Down
3 changes: 1 addition & 2 deletions network/NetworkGen/classes/Can.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ def validate_msg(self):
signal.start_bit + signal.native_representation.bit_width
)
except Exception as e:
breakpoint()
raise Exception(e)

# validate validationRoles of signals
Expand Down Expand Up @@ -507,7 +506,7 @@ def __init__(self, name, node_def):
self.duplicateNode = True
self.alias = self.name + str(self.offset)
self.total_duplicates = get_if_exists(node_def, "duplicateNode", int, 1)

self.baseId = get_if_exists(node_def, "baseId", int, None)
self.def_files = node_def["def_files"]
self.description: str = get_if_exists(node_def, "description", str, "")
self.messages: Dict[str, CanMessage] = {}
Expand Down
5 changes: 5 additions & 0 deletions network/NetworkGen/classes/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class Units(Enum):
amps = "A"
rpm = "RPM"
pct = "%"
Nm = "Nm"
deg = "deg"
Hz = "Hz"
Wb = "Wb"



class ValidationRole(Enum):
Expand Down
9 changes: 9 additions & 0 deletions network/definition/data/components/bmsb/bmsb-message.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ messages:
elconMaxChargeVoltage:
elconMaxChargeCurrent:
elconControlByte:

currentLimit:
description: BMS Torque limit
id: 0x202
cycleTimeMs: 100
sourceBuses: veh
signals:
maxDischarge:
maxCharge:
26 changes: 26 additions & 0 deletions network/definition/data/components/bmsb/bmsb-signals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,29 @@ signals:
min: 0
max: 25
continuous: true

maxDischarge:
unit: 'A'
description: BMS Limit Discharge Current
nativeRepresentation:
endianness: little
bitWidth: 16
resolution: 0.1
range:
min: 0
max: 1000
signedness: unsigned
continuous: true

maxCharge:
unit: 'A'
description: BMS Limit Charge Current
nativeRepresentation:
endianness: little
bitWidth: 16
resolution: 0.1
range:
min: 0
max: 75
signedness: unsigned
continuous: true
Loading

0 comments on commit 7adac13

Please sign in to comment.