Main Content

bus2RLSpec

Create reinforcement learning data specifications for elements of a Simulink bus

Description

example

specs = bus2RLSpec(busName) creates a set of reinforcement learning data specifications from the Simulink® bus object specified by busName. One specification element is created for each leaf element in the corresponding Simulink bus. Use these specifications to define an observations containing multiple channels for a Simulink reinforcement learning environment.

example

specs = bus2RLSpec(busName,Name=Value) specifies options for creating specifications using one or more Name=Value arguments.

Examples

collapse all

This example shows how to use the function bus2RLSpec to create an observation specification object from a Simulink® bus object.

Create a bus object.

obsBus = Simulink.Bus();

Create three elements in the bus and specify their names.

obsBus.Elements(1) = Simulink.BusElement;
obsBus.Elements(1).Name = "sin_theta";
obsBus.Elements(2) = Simulink.BusElement;
obsBus.Elements(2).Name = "cos_theta";
obsBus.Elements(3) = Simulink.BusElement;
obsBus.Elements(3).Name = "dtheta";

Create the observation specification objects using the Simulink bus object.

obsInfo = bus2RLSpec("obsBus");

You can then use obsInfo, together with the corresponding Simulink model, to create a reinforcement learning environment. For an example, see Train DDPG Agent to Swing Up and Balance Pendulum with Bus Signal.

This example shows how to call the function bus2RLSpec using name and value pairs to create an action specification object from a Simulink® bus object.

Create a bus object.

actBus = Simulink.Bus();

Create one element in the bus and specify the name.

actBus.Elements(1) = Simulink.BusElement;
actBus.Elements(1).Name = "actuator";

Create the observation specification objects using the Simulink bus object.

actInfo = bus2RLSpec("actBus","DiscreteElements",{"actuator",[-1 1]});

This specifies that the "actuator" bus element can carry two possible values, -1, and 1.

You can then use actInfo, together with the corresponding Simulink model, to create a reinforcement learning environment. Specifically the function that creates the environment uses actInfo to determine the right bus output of the agent block.

For an example, see Train DDPG Agent to Swing Up and Balance Pendulum with Bus Signal.

Input Arguments

collapse all

Name of Simulink bus object, specified as a string or character vector.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: DiscreteElements={'force',[-5 0 5]} sets the 'force' bus element to be a discrete data specification with three possible values, -5, 0, and 5

Name of the Simulink model, specified as the comma-separated pair consisting of 'Model' and a string or character vector. Specify the model name when the bus object is defined in the model global workspace (for example, in a data dictionary) instead of the MATLAB® workspace.

Names of bus leaf elements for which to create specifications, specified as the comma-separated pair consisting of 'BusElementNames' and a string array. To create observation specifications for a subset of the elements in a Simulink bus object, specify BusElementNames. If you do not specify BusElementNames, a data specification is created for each leaf element in the bus.

Note

Do not specify BusElementNames when creating specifications for action signals. The RL Agent block must output the full bus signal.

Finite values for discrete bus elements, specified as the comma-separated pair consisting of 'DiscreteElements' and a cell array of name-value pairs. Each name-value pair consists of a bus leaf element name and an array of discrete values. The specified discrete values must be castable to the data type of the specified action signal.

If you do not specify discrete values for an element specification, the element is continuous.

Example: 'ActionDiscretElements',{'force',[-10 0 10],'torque',[-5 0 5]} specifies discrete values for the 'force' and 'torque' leaf elements of a bus action signal.

Output Arguments

collapse all

Data specifications for reinforcement learning actions or observations, returned as one of the following:

  • rlNumericSpec object for a single continuous bus element

  • rlFiniteSetSpec object for a single discrete bus element

  • Array of data specification objects for multiple bus elements

By default, all data specifications for bus elements are rlNumericSpec objects. To create a discrete specification for one or more bus elements, specify the element names using the DiscreteElements name-value pair.

Version History

Introduced in R2019a