Register#
For each C++ template class navground::core::HasRegister
, we expose a Python class
with name ending by Register
, which serves as super-classes for their respective T
class.
Python sub-classes of T
by adding name=<name>
to the class, where the <name>
is an arbitrary string that will index the sub-class in the register. For example,
SubClassOfT(T, name="SubClassOfT"):
...
will register type SubClassOfT
under the name "SubClassOfT"
.
A decorator to register a property. It must be used below the
@property
decorator.For example, the following code adds a boolean valued registered property to a registered sub-class
C
of classT
:class C(T, name="C"): def __init__(self): super().__init__() self._my_field = True @property @register(True, "...") def my_property(self) -> bool: return self._my_field; @my_property.setter def my_property(self, value: bool) -> None: self._my_field = value;
Note
The setter of registered properties is wrapped to guarantee that is is called only with arguments of the property type (e.g., py:type:bool in the example above).
In the example above, trying to set the property using
c = C() c.my_property = 'a'
or
c.set('my_property', 'a'')
has no effect.
You can disable this argument coercion by setting the environment variable
NAVGROUND_DISABLE_PY_PROPERTY_COERCION
(before navground is initialized) or by passingtype_safe=True
.- Parameters:
default_value – The default value of the property when the object is initialized
description – The description of the property
schema – A optional schema to add validity constrains to the property
deprecated_names – A list of alternative deprecated names
scalar_type_name – The property scalar type name: one of “int”, “float”, “bool”, “str, “vector”. If not provided it will infer it from the type hints and/or the default value type.
type_safe – Whether the setter is type safe and therefore does not require checking/coercing the argument.
This register holds any behavior registered in
navground::core::HasRegister
as well as registered Python sub-classes ofnavground.Behavior
.The names of all registered behaviors
The dictionary of registered properties with registered names as keys
This register holds any kinematics registered in
navground::core::HasRegister
as well as registered Python sub-classes ofnavground.Kinematics
.The names of all registered kinematics.
The dictionary of registered properties with registered names as keys
This register holds any modulation registered in
navground::core::HasRegister
as well as registered Python sub-classes ofnavground.core.BehaviorModulation
.The names of all registered modulations.
The dictionary of registered properties with registered names as keys