Skip to content

Commit

Permalink
fix array generation and rw tpdo event times
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Oct 28, 2024
1 parent f4bd504 commit ee30381
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 81 deletions.
83 changes: 43 additions & 40 deletions oresat_configs/_yaml_to_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ def _make_rec(obj: IndexObject) -> Record:

for sub_obj in obj.subindexes:
if sub_obj.subindex in rec.subindices:
raise ValueError(
f"subindex 0x{sub_obj.subindex:X} aleady in record at record 0x{index:X}"
)
raise ValueError(f"subindex 0x{sub_obj.subindex:X} already in record")
var = _make_var(sub_obj, index, sub_obj.subindex)
rec.add_member(var)
var0.default = sub_obj.subindex
Expand All @@ -160,42 +158,47 @@ def _make_arr(obj: IndexObject, node_ids: dict[str, int]) -> Array:
subindexes = []
names = []
gen_sub = obj.generate_subindexes
if gen_sub is None:
raise ValueError("IndexObject for array missing generate_subindexes: {obj}")

if gen_sub.subindexes == "fixed_length":
subindexes = list(range(1, gen_sub.length + 1))
names = [obj.name + f"_{subindex}" for subindex in subindexes]
elif gen_sub.subindexes == "node_ids":
for name, sub in node_ids.items():
if sub == 0:
continue # a node_id of 0 is flag for not on can bus
names.append(name)
subindexes.append(sub)

for subindex, name in zip(subindexes, names):
if subindex in arr.subindices:
raise ValueError(f"subindex 0x{subindex:X} aleady in record at array 0x{index:X}")
var = canopen.objectdictionary.Variable(name, index, subindex)
var.access_type = gen_sub.access_type
var.data_type = STR_2_OD_DATA_TYPE[gen_sub.data_type]
for name, bits in gen_sub.bit_definitions.items():
var.add_bit_definition(name, bits)
for name, value in gen_sub.value_descriptions.items():
var.add_value_description(value, name)
var.unit = gen_sub.unit
var.factor = gen_sub.scale_factor
if obj.value_descriptions:
var.max = gen_sub.high_limit or max(gen_sub.value_descriptions.values())
var.min = gen_sub.low_limit or min(gen_sub.value_descriptions.values())
else:
var.max = gen_sub.high_limit or OD_DATA_TYPES[var.data_type].high_limit
var.min = gen_sub.low_limit or OD_DATA_TYPES[var.data_type].low_limit
_set_var_default(gen_sub, var)
if var.data_type not in DYNAMIC_LEN_DATA_TYPES:
var.pdo_mappable = True
arr.add_member(var)
var0.default = subindex
if gen_sub is not None:
if gen_sub.subindexes == "fixed_length":
subindexes = list(range(1, gen_sub.length + 1))
names = [f"{gen_sub.name}_{subindex}" for subindex in subindexes]
elif gen_sub.subindexes == "node_ids":
for name, sub in node_ids.items():
if sub == 0:
continue # a node_id of 0 is flag for not on can bus
names.append(name)
subindexes.append(sub)

for subindex, name in zip(subindexes, names):
if subindex in arr.subindices:
raise ValueError(f"subindex 0x{subindex:X} already in array")
var = canopen.objectdictionary.Variable(name, index, subindex)
var.access_type = gen_sub.access_type
var.data_type = STR_2_OD_DATA_TYPE[gen_sub.data_type]
for name, bits in gen_sub.bit_definitions.items():
var.add_bit_definition(name, bits)
for name, value in gen_sub.value_descriptions.items():
var.add_value_description(value, name)
var.unit = gen_sub.unit
var.factor = gen_sub.scale_factor
if obj.value_descriptions:
var.max = gen_sub.high_limit or max(gen_sub.value_descriptions.values())
var.min = gen_sub.low_limit or min(gen_sub.value_descriptions.values())
else:
var.max = gen_sub.high_limit or OD_DATA_TYPES[var.data_type].high_limit
var.min = gen_sub.low_limit or OD_DATA_TYPES[var.data_type].low_limit
_set_var_default(gen_sub, var)
if var.data_type not in DYNAMIC_LEN_DATA_TYPES:
var.pdo_mappable = True
arr.add_member(var)
var0.default = subindex
else:
for sub_obj in obj.subindexes:
if sub_obj.subindex in arr.subindices:
raise ValueError(f"subindex 0x{sub_obj.subindex:X} already in array")
var = _make_var(sub_obj, index, sub_obj.subindex)
arr.add_member(var)
var0.default = sub_obj.subindex

return arr

Expand All @@ -207,7 +210,7 @@ def _add_objects(

for obj in objects:
if obj.index in od.indices:
raise ValueError(f"index 0x{obj.index:X} aleady in OD")
raise ValueError(f"index 0x{obj.index:X} already in OD")

if obj.object_type == "variable":
var = _make_var(obj, obj.index)
Expand Down
42 changes: 13 additions & 29 deletions oresat_configs/base/reaction_wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,15 @@ objects:
- index: 0x4003
name: temperature
description: reaction wheel controller temperatures
object_type: record
subindexes:
- subindex: 0x1
name: sensor_1
data_type: int16
description: temperature sensor 1 temp
access_type: ro
unit: C
scale_factor: 0.01

- subindex: 0x2
name: sensor_2
data_type: int16
description: temperature sensor 2 temp
access_type: ro
unit: C
scale_factor: 0.01

- subindex: 0x3
name: sensor_3
data_type: int16
description: temperature sensor 3 temp
access_type: ro
unit: C
scale_factor: 0.01
object_type: array
generate_subindexes:
subindexes: fixed_length
length: 3
name: sensor
data_type: int16
access_type: ro
unit: C
scale_factor: 0.01

- index: 0x4004
name: requested
Expand Down Expand Up @@ -192,23 +176,23 @@ tpdos:
- [ctrl_stat, current_state]
- [ctrl_stat, procedure_result]
- [ctrl_stat, errors]
event_timer_ms: 100
event_timer_ms: 5000

- num: 2
fields:
- [motor, velocity]
- [motor, current]
event_timer_ms: 100
event_timer_ms: 5000

- num: 3
fields:
- [bus, voltage]
- [bus, current]
event_timer_ms: 100
event_timer_ms: 5000

- num: 4
fields:
- [temperature, sensor_1]
- [temperature, sensor_2]
- [temperature, sensor_3]
event_timer_ms: 100
event_timer_ms: 5000
59 changes: 47 additions & 12 deletions oresat_configs/card_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,55 @@ class GenerateSubindex(ConfigObject):
.. code-block:: yaml
subindexes: node_ids
names: node_ids
data_type: uint8
access_type: ro
value_descriptions:
0: "OFF"
1: "BOOT"
2: "ON"
3: "ERROR"
4: "NOT_FOUND"
0xFF: "DEAD"
- index: 0x4000
name: my_array
object_type: array
generate_subindexes:
subindexes: fixed_length
name: item
length: 10
data_type: uint16
access_type: ro
unit: C
scale_factor: 0.001
will generate the equivalent of
.. code-block:: yaml
- index: 0x4000
name: my_array
object_type: array
subindexes:
generate_subindexes:
- subindex: 1
name: item_1
data_type: uint16
access_type: ro
unit: C
scale_factor: 0.001
- subindex: 2
name: item_2
data_type: uint16
access_type: ro
unit: C
scale_factor: 0.001
...
- subindex: 9
name: item_9
data_type: uint16
access_type: ro
unit: C
scale_factor: 0.001
- subindex: 10
name: item_10
data_type: uint16
access_type: ro
unit: C
scale_factor: 0.001
"""

names: str = ""
name: str = ""
"""Names of objects to generate."""
subindexes: Union[str, int] = 0
"""Subindexes of objects to generate."""
Expand Down

0 comments on commit ee30381

Please sign in to comment.