load predefined control system environments -凯发k8网页登录

main content

load predefined control system environments

reinforcement learning toolbox™ software provides several predefined environments representing dynamical systems that are often used as benchmarks cases for control systems design.

in these environments, the state and observation (which are predefined) belong to nonfinite numerical vector spaces, while the action (also predefined) can still belong to a finite set. the (deterministic) state transitions laws are derived by discretizing the dynamics of an underlying physical system.

environments that rely on an underlying simulink® model for the calculation of the state transition, reward and observation, are referred to as simulink environments. some of the predefined control system environments belong to this category.

multiagent environments are environments in which you can train and simulate multiple agents together. some of the predefined matlab® and simulink control system environments are multiagent environments.

you can use predefined control system environments to learn how to apply reinforcement learning to the control of physical systems, gain familiarity with reinforcement learning toolbox software features, or test your own agents.

to load the following predefined matlab control system environments, use the rlpredefinedenv function. each of these predefined environment is available in two versions, one with a discrete action space, the other with a continuous action space.

environmentagent task
double integratorcontrol a second-order dynamic system using either a discrete or continuous action space.
cart-polebalance a pole on a moving cart by applying forces to the cart using either a discrete or continuous action space.
simple pendulum with image observationswing up and balance a simple pendulum using either a discrete or continuous action space.

you can also load the following predefined simulink environments using the rlpredefinedenv function. for these environments, rlpredefinedenv creates a simulinkenvwithagent object. each of these predefined environment is also available in two versions, one with a discrete action space, the other with a continuous action space.

environmentagent task
simple pendulum simulink modelswing up and balance a simple pendulum using either a discrete or continuous action space.
cart-pole simscape™ modelbalance a pole on a moving cart by applying forces to the cart using either a discrete or continuous action space.

you can also load predefined grid world environments. for more information, see load predefined grid world environments.

to learn how to create your own custom environment, see create custom environment using step and reset functions, create custom simulink environments and create custom environment from class template.

double integrator environments

the goal of the agent in the predefined double integrator environments is to control the position of a mass in a frictionless mono-dimensional space by applying a force input. the system has a second-order dynamics that can be represented by a double integrator (that is two integrators in series).

in this environment, a training episode ends when either of the following events occurs:

  • the mass moves beyond a given threshold from the origin.

  • the norm of the state vector is less than a given threshold.

there are two double integrator environment variants, which differ by the agent action space.

  • discrete — agent can apply a force of either fmax or -fmax to the cart, where fmax is the maxforce property of the environment.

  • continuous — agent can apply any force within the range [-fmax,fmax].

to create a double integrator environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('doubleintegrator-discrete');
  • continuous action space

    env = rlpredefinedenv('doubleintegrator-continuous');

you can visualize the double integrator environment using the plot function. the plot displays the mass as a red rectangle.

plot(env)

basic visualization of a double integrator environment, with a red square positioned at the origin.

to visualize the environment during training, call plot before training and keep the visualization figure open.

for examples showing how to train agents in double integrator environments, see the following:

environment properties

propertydescriptiondefault
gaingain for the double integrator1
tssample time in seconds0.1
maxdistancedistance magnitude threshold in meters5
goalthresholdstate norm threshold0.01
qweight matrix for observation component of reward signal[10 0; 0 1]
rweight matrix for action component of reward signal0.01
maxforcemaximum input force in newtons

discrete: 2

continuous: inf

state

environment state, specified as a column vector with the following state variables:

  • mass position

  • derivative of mass position

[0 0]'

actions

in the double integrator environments, the agent interacts with the environment using a single action signal, the force applied to the mass. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the double integrator system, the agent can observe both of the environment state variables in env.state. for each state variable, the environment contains an rlnumericspec observation specification. both states are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment is the discrete-time equivalent of the following continuous-time reward, which is analogous to the cost function of an lqr controller.

reward=(x'qx u'ru)dt

here:

  • q and r are environment properties.

  • x is the environment state vector.

  • u is the input force.

cart-pole environments

the goal of the agent in the predefined cart-pole environments is to balance a pole on a moving cart by applying horizontal forces to the cart. the pole is considered successfully balanced if both of the following conditions are satisfied:

  • the pole angle remains within a given threshold of the vertical position, where the vertical position is zero radians.

  • the magnitude of the cart position remains below a given threshold.

there are two cart-pole environment variants, which differ by the agent action space.

  • discrete — agent can apply a force of either fmax or -fmax to the cart, where fmax is the maxforce property of the environment.

  • continuous — agent can apply any force within the range [-fmax,fmax].

to create a cart-pole environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('cartpole-discrete');
  • continuous action space

    env = rlpredefinedenv('cartpole-continuous');

you can visualize the cart-pole environment using the plot function. the plot displays the cart as a blue square and the pole as a red rectangle.

plot(env)

basic visualization of a cart pole environment, with cart (indicated by a blue square) positioned at the origin, an erected pole (indicated by a pink rectangle) attached on top of the cart, and green lines indicating limits for the cart position and the pole angle.

to visualize the environment during training, call plot before training and keep the visualization figure open.

for examples showing how to train agents in cart-pole environments, see the following:

environment properties

propertydescriptiondefault
gravityacceleration due to gravity in meters per second squared9.8
masscartmass of the cart in kilograms1
masspolemass of the pole in kilograms0.1
lengthhalf the length of the pole in meters0.5
maxforcemaximum horizontal force magnitude in newtons10
tssample time in seconds0.02
thetathresholdradianspole angle threshold in radians0.2094
xthresholdcart position threshold in meters2.4
rewardfornotfallingreward for each time step the pole is balanced1
penaltyforfallingreward penalty for failing to balance the pole

discrete — -5

continuous — -50

state

environment state, specified as a column vector with the following state variables:

  • cart position

  • derivative of cart position

  • pole angle

  • derivative of pole angle

[0 0 0 0]'

actions

in the cart-pole environments, the agent interacts with the environment using a single scalar action signal, the horizontal force applied to the cart. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the cart-pole system, the agent can observe all the environment state variables in env.state. for each state variable, the environment contains an rlnumericspec observation specification. all the states are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment consists of two components.

  • a positive reward for each time step that the pole is balanced, that is, the cart and pole both remain within their specified threshold ranges. this reward accumulates over the entire training episode. to control the size of this reward, use the rewardfornotfalling property of the environment.

  • a one-time negative penalty if either the pole or cart moves outside of their threshold range. at this point, the training episode stops. to control the size of this penalty, use the penaltyforfalling property of the environment.

simple pendulum environments with image observation

this environment is a simple frictionless pendulum that is initially hangs in a downward position. the training goal is to make the pendulum stand upright without falling over using minimal control effort.

there are two simple pendulum environment variants, which differ by the agent action space.

  • discrete — agent can apply a torque of -2, -1, 0, 1, or 2 to the pendulum.

  • continuous — agent can apply any torque within the range [-2,2].

to create a simple pendulum environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('simplependulumwithimage-discrete');
  • continuous action space

    env = rlpredefinedenv('simplependulumwithimage-continuous');

for examples showing how to train an agent in this environment, see the following:

environment properties

propertydescriptiondefault
masspendulum mass1
rodlengthpendulum length1
rodinertiapendulum moment of inertia0
gravityacceleration due to gravity in meters per second squared9.81
dampingratiodamping on pendulum motion0
maximumtorquemaximum input torque in newtons2
tssample time in seconds0.05
state

environment state, specified as a column vector with the following state variables:

  • pendulum angle

  • pendulum angular velocity

[0 0 ]'
qweight matrix for observation component of reward signal[1 0;0 0.1]
rweight matrix for action component of reward signal1e-3

actions

in the simple pendulum environments, the agent interacts with the environment using a single action signal, the torque applied at the base of the pendulum. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the simple pendulum environment, the agent receives the following observation signals:

  • 50-by-50 grayscale image of the pendulum position

  • derivative of the pendulum angle

for each observation signal, the environment contains an rlnumericspec observation specification. all the observations are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment is

rt=(θt2 0.1θ˙t2 0.001ut12)

here:

  • θt is the pendulum angle of displacement from the upright position.

  • θ˙t is the derivative of the pendulum angle.

  • ut-1 is the control effort from the previous time step.

simple pendulum simulink model

this environment is a simple frictionless pendulum that initially hangs in a downward position. the training goal is to make the pendulum stand upright without falling over using minimal control effort. the model for this environment is defined in the rlsimplependulummodel simulink model.

open_system('rlsimplependulummodel')

simulink model of a pendulum system in a feedback loop with an agent block.

there are two simple pendulum environment variants, which differ by the agent action space.

  • discrete — agent can apply a torque of either tmax, 0, or -tmax to the pendulum, where tmax is the max_tau variable in the model workspace.

  • continuous — agent can apply any torque within the range [-tmax,tmax].

to create a simple pendulum environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('simplependulummodel-discrete');
  • continuous action space

    env = rlpredefinedenv('simplependulummodel-continuous');

for examples that train agents in the simple pendulum environment, see:

actions

in the simple pendulum environments, the agent interacts with the environment using a single action signal, the torque applied at the base of the pendulum. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the simple pendulum environment, the agent receives the following three observation signals, which are constructed within the create observations subsystem.

  • sine of the pendulum angle

  • cosine of the pendulum angle

  • derivative of the pendulum angle

for each observation signal, the environment contains an rlnumericspec observation specification. all the observations are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment, which is constructed in the calculate reward subsystem, is

rt=(θt2 0.1θ˙t2 0.001ut12)

here:

  • θt is the pendulum angle of displacement from the upright position.

  • θ˙t is the derivative of the pendulum angle.

  • ut-1 is the control effort from the previous time step.

cart-pole simscape model

the goal of the agent in the predefined cart-pole environments is to balance a pole on a moving cart by applying horizontal forces to the cart. the pole is considered successfully balanced if both of the following conditions are satisfied:

  • the pole angle remains within a given threshold of the vertical position, where the vertical position is zero radians.

  • the magnitude of the cart position remains below a given threshold.

the model for this environment is defined in the rlcartpolesimscapemodel simulink model. the dynamics of this model are defined using simscape multibody™.

open_system('rlcartpolesimscapemodel')

simulink model of an environment in a feedback loop with an agent block.

in the environment subsystem, the model dynamics are defined using simscape components and the reward and observation are constructed using simulink blocks.

open_system('rlcartpolesimscapemodel/environment')

simulink model of a cart-pole system.

there are two cart-pole environment variants, which differ by the agent action space.

  • discrete — agent can apply a force of 15, 0, or -15 to the cart.

  • continuous — agent can apply any force within the range [-15,15].

to create a cart-pole environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('cartpolesimscapemodel-discrete');
  • continuous action space

    env = rlpredefinedenv('cartpolesimscapemodel-continuous');

for an example that trains an agent in this cart-pole environment, see .

actions

in the cart-pole environments, the agent interacts with the environment using a single action signal, the force applied to the cart. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the cart-pole environment, the agent receives the following five observation signals.

  • sine of the pole angle

  • cosine of the pole angle

  • derivative of the pendulum angle

  • cart position

  • derivative of cart position

for each observation signal, the environment contains an rlnumericspec observation specification. all the observations are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment is the sum of two components (r = rqr rn rp):

  • a quadratic regulator control reward, constructed in the environment/qr reward subsystem.

    rqr=(0.1x2 0.5θ2 0.005ut12)

  • a cart limit penalty, constructed in the environment/x limit penalty subsystem. this subsystem generates a negative reward when the magnitude of the cart position exceeds a given threshold.

    rp=100(|x|3.5)

here:

  • x is the cart position.

  • θ is the pole angle of displacement from the upright position.

  • ut-1 is the control effort from the previous time step.

see also

functions

objects

blocks

related examples

more about

网站地图