Skip to content

Commit

Permalink
add unit and scaling fields to objs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Nov 13, 2023
1 parent 4e808fe commit b1dd665
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 143 deletions.
28 changes: 23 additions & 5 deletions oresat_configs/_yaml_to_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def _add_objects(od: canopen.ObjectDictionary, objects: list):
var.add_bit_definition(name, bits)
for value, descr in obj.get("values", {}).items():
var.add_value_description(value, descr)
var.unit = obj.get("unit", "")
var.factor = obj.get("scaling", 1)
var.data_type = OD_DATA_TYPES[obj["data_type"]]
_set_var_default(obj, var)
if var.data_type not in dynamic_len_data_types:
Expand All @@ -119,10 +121,12 @@ def _add_objects(od: canopen.ObjectDictionary, objects: list):
var.access_type = sub_obj["access_type"]
var.description = sub_obj["description"]
var.data_type = OD_DATA_TYPES[sub_obj["data_type"]]
for name, bits in obj.get("bitfield", {}).items():
for name, bits in sub_obj.get("bitfield", {}).items():
var.add_bit_definition(name, bits)
for value, descr in obj.get("values", {}).items():
for value, descr in sub_obj.get("values", {}).items():
var.add_value_description(value, descr)
var.unit = sub_obj.get("unit", "")
var.factor = sub_obj.get("scaling", 1)
_set_var_default(sub_obj, var)
if var.data_type not in dynamic_len_data_types:
var.pdo_mappable = True
Expand All @@ -145,10 +149,12 @@ def _add_objects(od: canopen.ObjectDictionary, objects: list):
var = canopen.objectdictionary.Variable(sub_name, index, subindex)
var.access_type = obj["access_type"]
var.data_type = OD_DATA_TYPES[obj["data_type"]]
for name, bits in obj.get("bitfield", {}).items():
for name, bits in sub_obj.get("bitfield", {}).items():
var.add_bit_definition(name, bits)
for value, descr in obj.get("values", {}).items():
for value, descr in sub_obj.get("values", {}).items():
var.add_value_description(value, descr)
var.unit = sub_obj.get("unit", "")
var.factor = sub_obj.get("scaling", 1)
_set_var_default(sub_obj, var)
if var.data_type not in dynamic_len_data_types:
var.pdo_mappable = True
Expand Down Expand Up @@ -348,6 +354,10 @@ def _add_rpdo_data(
var.access_type = "rw"
var.data_type = tpdo_mapped_obj.data_type
var.default = tpdo_mapped_obj.default
var.unit = tpdo_mapped_obj.unit
var.factor = tpdo_mapped_obj.factor
var.bit_definitions = deepcopy(tpdo_mapped_obj.bit_definitions)
var.value_descriptions = deepcopy(tpdo_mapped_obj.value_descriptions)
var.pdo_mappable = True
rpdo_mapped_rec.add_member(var)

Expand Down Expand Up @@ -423,7 +433,11 @@ def read_yaml_od_config(file_path: str) -> dict:
if "values" not in obj:
obj["values"] = {}
if "bitfield" not in obj:
obj["bitfie"] = {}
obj["bitfield"] = {}
if "unit" not in obj:
obj["unit"] = ""
if "scaling" not in obj:
obj["scaling"] = 1
elif "subindexes" not in obj:
config["subindexes"] = []
else:
Expand All @@ -440,6 +454,10 @@ def read_yaml_od_config(file_path: str) -> dict:
sub_obj["values"] = {}
if "bitfield" not in sub_obj:
sub_obj["bitfield"] = {}
if "unit" not in sub_obj:
sub_obj["unit"] = ""
if "scaling" not in sub_obj:
sub_obj["scaling"] = 1

if "tpdos" not in config:
config["tpdos"] = []
Expand Down
116 changes: 78 additions & 38 deletions oresat_configs/base/battery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,92 +7,107 @@ objects:
- subindex: 0x1
name: vbatt
data_type: uint16
description: pack voltage in millivolts
description: pack voltage
access_type: ro
unit: mV

- subindex: 0x2
name: vcell_max
data_type: uint16
description: max voltage for a cell in millivolts
description: max voltage for a cell
access_type: ro
unit: mV

- subindex: 0x3
name: vcell_min
data_type: uint16
description: min voltage for a cell in millivolts
description: min voltage for a cell
access_type: ro
unit: mV

- subindex: 0x4
name: vcell
data_type: uint16
description: lowest cell voltage in millivolts
description: lowest cell voltage
access_type: ro
unit: mV

- subindex: 0x5
name: vcell_1
data_type: uint16
description: cell 1 voltage in millivolts
description: cell 1 voltage
access_type: ro
unit: mV

- subindex: 0x6
name: vcell_2
data_type: uint16
description: cell 2 voltage in millivolts
description: cell 2 voltage
access_type: ro
unit: mV

- subindex: 0x7
name: vcell_avg
data_type: uint16
description: average voltage of both cells in millivolts
description: average voltage of both cells
access_type: ro
unit: mV

- subindex: 0x8
name: current
data_type: int16
description: pack current in milliamps
description: pack current
access_type: ro
unit: mA

- subindex: 0x9
name: current_avg
data_type: int16
description: pack average current in milliamps
description: pack average current
access_type: ro
unit: mA

- subindex: 0xa
name: current_max
data_type: int16
description: pack max current in milliamps
description: pack max current
access_type: ro
unit: mA

- subindex: 0xb
name: current_min
data_type: int16
description: pack min current in milliamps
description: pack min current
access_type: ro
unit: mA

- subindex: 0xc
name: full_capacity
data_type: uint16
description: capacity of battery pack in milliamp-hours
description: capacity of battery pack
access_type: ro
unit: mAh

- subindex: 0xd
name: reported_capacity
data_type: uint16
description: reported capacity of battery pack in milliamp-hours
description: reported capacity of battery pack
access_type: ro
unit: mAh

- subindex: 0xe
name: time_to_empty
data_type: uint16
description: estimate of time until battery pack is empty in seconds
description: estimate of time until battery pack is empty
access_type: ro
unit: s

- subindex: 0xf
name: time_to_full
data_type: uint16
description: estimate of time until battery pack is full in seconds
description: estimate of time until battery pack is full
access_type: ro
unit: s

- subindex: 0x10
name: cycles
Expand All @@ -107,30 +122,35 @@ objects:
description: reported charge percent
access_type: ro
high_limit: 100
unit: "%"

- subindex: 0x12
name: temperature
data_type: int8
description: temperature of battery pack in celsius
description: temperature of battery pack
access_type: ro
unit: C

- subindex: 0x13
name: temperature_avg
data_type: int8
description: average temperature of battery pack in celsius
description: average temperature of battery pack
access_type: ro
unit: C

- subindex: 0x14
name: temperature_max
data_type: int8
description: max temperature of battery pack in celsius
description: max temperature of battery pack
access_type: ro
unit: C

- subindex: 0x15
name: temperature_min
data_type: int8
description: min temperature of battery pack in celsius
description: min temperature of battery pack
access_type: ro
unit: C

- subindex: 0x16
name: status
Expand All @@ -151,92 +171,107 @@ objects:
- subindex: 0x1
name: vbatt
data_type: uint16
description: pack voltage in millivolts
description: pack voltage
access_type: ro
unit: mV

- subindex: 0x2
name: vcell_max
data_type: uint16
description: max voltage for a cell in millivolts
description: max voltage for a cell
access_type: ro
unit: mV

- subindex: 0x3
name: vcell_min
data_type: uint16
description: min voltage for a cell in millivolts
description: min voltage for a cell
access_type: ro
unit: mV

- subindex: 0x4
name: vcell
data_type: uint16
description: lowest cell voltage in millivolts
description: lowest cell voltage
access_type: ro
unit: mV

- subindex: 0x5
name: vcell_1
data_type: uint16
description: cell 1 voltage in millivolts
description: cell 1 voltage
access_type: ro
unit: mV

- subindex: 0x6
name: vcell_2
data_type: uint16
description: cell 2 voltage in millivolts
description: cell 2 voltage
access_type: ro
unit: mV

- subindex: 0x7
name: vcell_avg
data_type: uint16
description: average voltage of both cells in millivolts
description: average voltage of both cells
access_type: ro
unit: mV

- subindex: 0x8
name: current
data_type: int16
description: pack current in milliamps
description: pack current
access_type: ro
unit: mA

- subindex: 0x9
name: current_avg
data_type: int16
description: average current in milliamps
description: pack average current
access_type: ro
unit: mA

- subindex: 0xa
name: current_max
data_type: int16
description: max current in milliamps
description: pack max current
access_type: ro
unit: mA

- subindex: 0xb
name: current_min
data_type: int16
description: min current in milliamps
description: pack min current
access_type: ro
unit: mA

- subindex: 0xc
name: full_capacity
data_type: uint16
description: capacity of battery pack in milliamp-hours
description: capacity of battery pack
access_type: ro
unit: mAh

- subindex: 0xd
name: reported_capacity
data_type: uint16
description: reported capacity of battery pack in milliamp-hours
description: reported capacity of battery pack
access_type: ro
unit: mAh

- subindex: 0xe
name: time_to_empty
data_type: uint16
description: estimate of time until battery pack is empty in seconds
description: estimate of time until battery pack is empty
access_type: ro
unit: s

- subindex: 0xf
name: time_to_full
data_type: uint16
description: estimate of time until battery pack is full in seconds
description: estimate of time until battery pack is full
access_type: ro
unit: s

- subindex: 0x10
name: cycles
Expand All @@ -251,30 +286,35 @@ objects:
description: reported charge percent
access_type: ro
high_limit: 100
unit: "%"

- subindex: 0x12
name: temperature
data_type: int8
description: temperature of battery pack in celsius
description: temperature of battery pack
access_type: ro
unit: C

- subindex: 0x13
name: temperature_avg
data_type: int8
description: average temperature of battery pack in celsius
description: average temperature of battery pack
access_type: ro
unit: C

- subindex: 0x14
name: temperature_max
data_type: int8
description: max temperature of battery pack in celsius
description: max temperature of battery pack
access_type: ro
unit: C

- subindex: 0x15
name: temperature_min
data_type: int8
description: min temperature of battery pack in celsius
description: min temperature of battery pack
access_type: ro
unit: C

- subindex: 0x16
name: status
Expand Down
Loading

0 comments on commit b1dd665

Please sign in to comment.