From f4bd50425aa924703c550fe962dc77e9e4c0fd60 Mon Sep 17 00:00:00 2001 From: Ryan Medick Date: Mon, 28 Oct 2024 13:13:29 -0700 Subject: [PATCH 1/3] add missing rw enums and bitfields --- oresat_configs/base/reaction_wheel.yaml | 43 ++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/oresat_configs/base/reaction_wheel.yaml b/oresat_configs/base/reaction_wheel.yaml index 889e3c6..957a38d 100644 --- a/oresat_configs/base/reaction_wheel.yaml +++ b/oresat_configs/base/reaction_wheel.yaml @@ -1,6 +1,6 @@ objects: - index: 0x4000 - name: ctrl_stat + name: ctrl_stat description: reaction wheel controller status object_type: record subindexes: @@ -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 @@ -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 From ee303818b48afdb861dd5b1d3ead5a330ba1242a Mon Sep 17 00:00:00 2001 From: Ryan Medick Date: Mon, 28 Oct 2024 13:56:40 -0700 Subject: [PATCH 2/3] fix array generation and rw tpdo event times --- oresat_configs/_yaml_to_od.py | 83 +++++++++++++------------ oresat_configs/base/reaction_wheel.yaml | 42 ++++--------- oresat_configs/card_config.py | 59 ++++++++++++++---- 3 files changed, 103 insertions(+), 81 deletions(-) diff --git a/oresat_configs/_yaml_to_od.py b/oresat_configs/_yaml_to_od.py index 53181dd..7ac970e 100644 --- a/oresat_configs/_yaml_to_od.py +++ b/oresat_configs/_yaml_to_od.py @@ -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 @@ -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 @@ -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) diff --git a/oresat_configs/base/reaction_wheel.yaml b/oresat_configs/base/reaction_wheel.yaml index 957a38d..92723e1 100644 --- a/oresat_configs/base/reaction_wheel.yaml +++ b/oresat_configs/base/reaction_wheel.yaml @@ -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 @@ -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 diff --git a/oresat_configs/card_config.py b/oresat_configs/card_config.py index df0c560..7eda5ab 100644 --- a/oresat_configs/card_config.py +++ b/oresat_configs/card_config.py @@ -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.""" From 5d68259937870ee08deca6eca4e6d12840383ff8 Mon Sep 17 00:00:00 2001 From: Ryan Medick Date: Sun, 17 Nov 2024 16:50:27 -0800 Subject: [PATCH 3/3] add missing name to pre-def error field array --- oresat_configs/standard_objects.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/oresat_configs/standard_objects.yaml b/oresat_configs/standard_objects.yaml index f750290..9cb0d50 100644 --- a/oresat_configs/standard_objects.yaml +++ b/oresat_configs/standard_objects.yaml @@ -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