Skip to content

Commit

Permalink
fix default values for octet string in subindexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Oct 21, 2023
1 parent 65d19ed commit 4557880
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
39 changes: 18 additions & 21 deletions oresat_od_db/_yaml_to_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
}


def _set_var_default(obj: dict, var: canopen.objectdictionary.Variable):
"""Set the variables default value based off of configs."""

if obj["data_type"] == "octet_str" and "length" in obj:
var.default = b"\x00" * obj["length"]
elif obj["default"] is None:
var.default = OD_DEFAULTS[var.data_type]
elif var.data_type in canopen.objectdictionary.INTEGER_TYPES and isinstance(
obj["default"], str
):
var.default = int(obj["default"], 16) # fix hex values data types
else:
var.default = obj["default"]


def _add_objects(
od: canopen.ObjectDictionary, objects: list, base_index: int
) -> canopen.objectdictionary.Record:
Expand All @@ -75,7 +90,6 @@ def _add_objects(
canopen.objectdictionary.OCTET_STRING,
canopen.objectdictionary.DOMAIN,
]
int_types = canopen.objectdictionary.INTEGER_TYPES

index = base_index
for obj in objects:
Expand All @@ -85,14 +99,7 @@ def _add_objects(
var.access_type = obj["access_type"]
var.description = obj["description"]
var.data_type = OD_DATA_TYPES[obj["data_type"]]
if obj["data_type"] == "octet_str" and "length" in obj:
var.default = b"\x00" * obj["length"]
elif obj["default"] is None:
var.default = OD_DEFAULTS[var.data_type]
elif var.data_type in int_types and isinstance(obj["default"], str):
var.default = int(obj["default"], 16) # fix hex values data types
else:
var.default = obj["default"]
_set_var_default(obj, var)
if var.data_type not in dynamic_len_data_types:
var.pdo_mappable = True
od.add_object(var)
Expand All @@ -110,12 +117,7 @@ def _add_objects(
var.access_type = sub_obj["access_type"]
var.description = sub_obj["description"]
var.data_type = OD_DATA_TYPES[sub_obj["data_type"]]
if sub_obj["default"] is None:
var.default = OD_DEFAULTS[var.data_type]
elif var.data_type in int_types and isinstance(sub_obj["default"], str):
var.default = int(sub_obj["default"], 16) # fix hex values data types
else:
var.default = sub_obj["default"]
_set_var_default(sub_obj, var)
if var.data_type not in dynamic_len_data_types:
var.pdo_mappable = True
rec.add_member(var)
Expand All @@ -136,12 +138,7 @@ def _add_objects(
var = canopen.objectdictionary.Variable(sub_name, index, subindex)
var.access_type = obj["access_type"]
var.data_type = OD_DATA_TYPES[obj["data_type"]]
if sub_obj["default"] is None:
var.default = OD_DEFAULTS[var.data_type]
elif var.data_type in int_types and isinstance(sub_obj["default"], str):
var.default = int(sub_obj["default"], 16) # fix hex values data types
else:
var.default = sub_obj["default"]
_set_var_default(sub_obj, var)
if var.data_type not in dynamic_len_data_types:
var.pdo_mappable = True
arr.add_member(var)
Expand Down
14 changes: 7 additions & 7 deletions oresat_od_db/base/cfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,43 @@ objects:
data_type: float32
description: the PID proportional constant
access_type: const
value: 0.5
default: 0.5

- name: pid_ki
data_type: float32
description: the PID intergral constant
access_type: const
value: 0.0
default: 0.0

- name: pid_kd
data_type: float32
description: the PID derivative constant
access_type: const
value: 0.1
default: 0.1

- name: pid_delay
data_type: uint32
description: the delay between PID loops in milliseconds
access_type: rw
value: 250
default: 250

- name: moving_avg_samples
data_type: uint8
description: the number of reading used to calcuate the moving average to determine if saturated
access_type: rw
value: 4
default: 4

- name: saturation_diff
data_type: uint8
description: the difference between the lowest and current temperature (in celsius) to flag as saturated
access_type: rw
value: 3
default: 3

- name: cooldown_temperature
data_type: int8
description: once saturated the TEC controller cannot be enable until the camera temperature (in celsius) is greater this value
access_type: rw
value: 40
default: 40

tpdos:
- num: 3
Expand Down

0 comments on commit 4557880

Please sign in to comment.