[docs]@register_api_implementation(core_class=ControllerCommand)classControllerCommandSetup(LoadSetup):""" The API handler for controller commands The following example shows how to create a controller command using the API, it is assumed that these steps were performed in each of the examples for other methods in this class. .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> lcc_setup = simulation_setup.create_load_case_container_setup().set_name(name='Example LCC') >>> lc_setup = lcc_setup.create_load_case_setup(lc_type='Mechanical load case').set_name(name='Example LC') >>> controller_command_setup = lc_setup.create_load_setup(load_type='Controller command') .. >>> isinstance(controller_command_setup, ControllerCommandSetup) True >>> isinstance(controller_command_setup._load, ControllerCommand) True The next example shows how to get an API object for an already existing load. .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> lcc_setup = simulation_setup.create_load_case_container_setup().set_name(name='Example LCC') >>> lc_setup = lcc_setup.create_load_case_setup(lc_type='Mechanical load case').set_name(name='Example LC') .. >>> controller_command_setup = lc_setup.create_load_setup(load_type='Controller command') >>> controller_command_setup = lc_setup.get_load_setup(index=0) # The load under this index must already exist .. >>> isinstance(controller_command_setup, ControllerCommandSetup) True >>> isinstance(controller_command_setup._load, ControllerCommand) True """
[docs]defset_controller_by_name(self,controller_name:str)->'ControllerCommandSetup':""" Sets the controller for the associated controller command See example at the top for how to create a controller command setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> controller_command_setup = _controller_command_api_setup(api) >>> proj.comp.add_controller() >>> controller = proj.comp.controller[0] >>> controller.name = 'example controller' >>> controller_command_setup = controller_command_setup.set_controller_by_name(controller_name='example controller') # The controller with this name must already exist .. >>> controller_command_setup._load.controller_selector.selected_entity == controller True >>> controller_command_setup = controller_command_setup.set_controller_by_name(controller_name='nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: ControllerCommandSetup Raises ------ NameNotFoundError Raised if a key in the name is not a viable controller """self._load.controller_selector.select_entity_by_name(name=controller_name)returnself
[docs]defset_command_value_by_name(self,command_value_name)->'ControllerCommandSetup':""" Sets the command value for the associated controller command See example at the top for how to create a controller command setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> controller_command_setup = _controller_command_api_setup(api) >>> proj.comp.add_controller() >>> controller = proj.comp.controller[0] >>> controller.name = 'example controller' >>> controller_command_setup = controller_command_setup.set_controller_by_name(controller_name='example controller') # The controller with this name must already exist >>> controller_command_setup = controller_command_setup.set_command_value_by_name(command_value_name='Position command value') .. >>> controller_command_setup._load.command_value.name == 'Position command value' True >>> controller_command_setup = controller_command_setup.set_command_value_by_name('nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: ControllerCommandSetup Raises ------ NameNotFoundError Raised if a key in there is no command value with the given name """try:self._load.command_value=self._available_command_values_dict[command_value_name]exceptKeyError:raiseNameNotFoundError('Command value with name: {} not found, available command values are: {}'.format(command_value_name,self._available_command_values_dict.keys()))returnself
@propertydefavailable_command_value_names(self)->typing.List[str]:""" Returns the list of available command value names See example at the top for how to create a controller command setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> controller_command_setup = _controller_command_api_setup(api) >>> proj.comp.add_controller() >>> controller = proj.comp.controller[0] >>> controller.name = 'example controller' >>> controller_command_setup.available_command_value_names ['Position command value', 'Velocity command value', 'Position command value with setpoint scaling'] Returns ------- list of strings The list of available command values """returnlist(self._available_command_values_dict.keys())@propertydefavailable_command_values_dict(self):""" Deprecated method .. admonition:: Deprecated :class: warning `available_command_values_dict` will be removed in a future MORe release, it is replaced by :meth:`~.available_command_value_names` """logger.warning('Deprecation: \"available_command_values_dict\" will be removed in a future MORe release, it is replaced by \"available_command_value_names\"')returnself._available_command_values_dict@propertydef_available_command_values_dict(self):return{cv.name:cvforcvinself._load._available_command_values}
[docs]defset_controller(self,controller):""" Deprecated method .. admonition:: Deprecated :class: warning `set_controller` will be removed in a future MORe release, it is replaced by :meth:`~.set_controller_by_name` """logger.warning('Deprecation: \"set_controller\" will be removed in a future MORe release, it is replaced by \"set_controller_by_name\"')returnself.set_controller_by_name(controller_name=controller.name)
[docs]defset_command_value(self,command_value):""" Deprecated method .. admonition:: Deprecated :class: warning `set_command_value` will be removed in a future MORe release, it is replaced by :meth:`~.set_command_value_by_name` """logger.warning('Deprecation: \"set_command_value\" will be removed in a future MORe release, it is replaced by \"set_command_value_by_name\"')returnself.set_command_value_by_name(command_value_name=command_value.name)