main content

create reinforcement learning data specifications for elements of a simulink bus -凯发k8网页登录

create reinforcement learning data specifications for elements of a simulink bus

since r2019a

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

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 .

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 .

input arguments

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

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

网站地图