RTBase#

class RTBase(do_mpc_object, clientOpts, namespace=None)[source]#

Bases: object

Real Time Base. The RTBase class extends do-mpc with an OPC UA interface.

Note

The do_mpc.estimator.MHE class is currently not supported.

Use this class to configure an OPC UA client for a previously initiated do-mpc class e.g.. do_mpc.controller.MPC or do_mpc.simulator.Simulator.

Configuration and setup:

Configuring and setting up the RTBase class involves the following steps:

  1. Use do_mpc.opcua.ClientOpts dataclass to specify client name as well as IP adress and port number of the target server.

  2. Initiate the RTBase class with a do-mpc object and the dataclass do_mpc.opcua.ClientOpts.

  3. Use set_write_tags() and set_read_tags() to take over the namespace tags (node IDs) from another instance of RTBase (optional).

Note

Use set_write_tags() and set_read_tags() only after registering all clients with the do_mpc.opcua.RTServer.namespace_from_client() method.

  1. Use connect() to connect the client to the OPC UA server.

  1. Use write_to_tags() to write initial values to the OPC UA server.

  2. Use async_step_start() to run the do-mpc method do_mpc.controller.MPC.make_step().

Parameters:
  • do_mpc_object – An instance of a do-mpc class.

  • clientOpts (ClientOpts) – Client Options

  • namespace (Namespace) – Namespace containing OPC UA node IDs

Methods#

async_run#

async_run(self)#

This method is called inside of async_step_start(). It calls make_step() and async_step_start().

Return type:

None

async_step_start#

async_step_start(self)#

This method calls the async_run() method in a frequency given by the do-mpc classes t_step value.

Return type:

None

async_step_stop#

async_step_stop(self)#

Stops async_step_start() from running.

Return type:

None

connect#

connect(self)#

Connects client to the server.

Return type:

None

disconnect#

disconnect(self)#

Disconnects client from the server.

Return type:

None

get_default_namespace#

get_default_namespace(self, namespace_name)#

Sets default namespace using namespace_from_model().

Parameters:

namespace_name (str) – Name given to the generated namespace

Return type:

None

make_step#

make_step(self)#

Calls the do-mpc make_step method e.g.. do_mpc.controller.MPC.make_step(). The input for make_step is taken from node IDs specified in read_from_tags(). The output of make_step is written to the node IDs specified in write_to_tags().

Return type:

None

namespace_from_model#

namespace_from_model(self, model, model_name)#

Create a OPC UA namespace from the provided model.

Parameters:
  • model (Model) – A do-mpc model.

  • model_name (str) – Name given to the generated namespace.

Returns:

Namespace – Namespace generated from the OPC UA model.

read_from_tags#

read_from_tags(self)#

Read from the node IDs specified in read_from_tags().

Returns:

ndarray – Values stored on the OPC UA server.

set_read_tags#

set_read_tags(self, tagin)#

Set tags (node IDs) to read from. The provided tags must match the node IDs registered on the taget server.

Parameters:

tagin (List[str]) – A list of node IDs from which the client reads.

Return type:

None

set_write_tags#

set_write_tags(self, tagout)#

Set tags (node IDs) to write to. The provided tags must match the node IDs registered on the taget server.

Parameters:

tagout (List[str]) – A list of node IDs to which the client writes.

Return type:

None

write_to_tags#

write_to_tags(self, data)#

Write to the node IDs specified in write_to_tags()

Parameters:

data (ndarray) – data which is written to server.

Return type:

None