Skip to content

Commit

Permalink
Merge pull request #45 from oresat/rw-dev
Browse files Browse the repository at this point in the history
Fix array and corrected rw configs
  • Loading branch information
ryanpdx authored Nov 24, 2024
2 parents c0c0ec2 + 5d68259 commit f7f57e1
Show file tree
Hide file tree
Showing 4 changed files with 145 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 @@ -137,9 +137,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 @@ -159,42 +157,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 @@ -206,7 +209,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
83 changes: 54 additions & 29 deletions oresat_configs/base/reaction_wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ objects:
data_type: uint8
description: controller state
access_type: ro
value_descriptions:
none: 0
idle: 1
system_error: 2
controller_error: 3
torque_control: 4
vel_control: 5
pos_control: 6
motor_resistance_cal: 7
motor_inductance_cal: 8
encoder_dir_cal: 9
encoder_offset_cal: 10
encoder_test: 11
open_loop_control: 12
clear_errors: 13
encoder_validation: 14
shitty_offset_cal: 15
vel_ramp_control: 16

- subindex: 0x2
name: procedure_result
Expand All @@ -21,6 +39,29 @@ objects:
data_type: uint32
description: system error bitmask
access_type: ro
bit_definitions:
inverter_calibration_invalid: 0
phase_currents_invalid: 1
phase_currents_measurement_missing: 2
pwm_timing_invalid: 3
pwm_timing_update_missing: 4
vbus_overvoltage: 5
vbus_undervoltage: 6
ibus_overcurrent: 7
motor_overcurrent: 8
motor_phase_leakage: 9
motor_resistance_out_of_range: 10
motor_inductance_out_of_range: 11
encoder_reading_missing: 12
encoder_estimate_missing: 13
encoder_reading_invalid: 14
encoder_failure: 15
phase_current_usage_missing: 16
pwm_timing_usage_missing: 17
phase_current_leakage: 18
encoder_reading_usage_missing: 19
motor_unbalanced_phases: 20
modulation: 21

- index: 0x4001
name: motor
Expand Down Expand Up @@ -63,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 @@ -151,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
1 change: 1 addition & 0 deletions oresat_configs/standard_objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
object_type: array
description: emcy history for device
generate_subindexes:
name: error
subindexes: fixed_length
length: 8 # can be up to 127
data_type: uint32
Expand Down

0 comments on commit f7f57e1

Please sign in to comment.