quanser

base

class QuanserReal(ip: str, rcv_dim: int, snd_dim: int, dt: float = 0.002, max_steps: int = inf, task_args: Optional[dict] = None)[source]

Bases: RealEnv, ABC

Base class of all real-world Quanser environments in Pyrado

Constructor

Parameters:
  • ip – IP address of the platform

  • rcv_dim – number of dimensions of the sensor i.e. measurement signal (received from Simulink server)

  • snd_dim – number of dimensions of the action command (send to Simulink server)

  • dt – sampling time interval

  • max_steps – maximum number of time steps

  • task_args – arguments for the task construction

property act_space: Space

Get the space of the actions.

close()[source]

Sends a zero-step and closes the communication.

property obs_space: Space

Get the space of the observations (agent’s perception of the environment).

render(mode: RenderMode = RenderMode(text=True, video=False, render=False), render_step: int = 1)[source]

Visualize one time step.

Parameters:
  • mode – render mode: console, video, or both

  • render_step – interval for rendering

abstract reset(*args, **kwargs)[source]

Reset the environment. The base version (re-)opens the socket and resets the task.

Parameters:
  • args – just for compatibility with SimEnv. All args can be ignored.

  • kwargs – just for compatibility with SimEnv. All kwargs can be ignored.

property state_space: Space

Get the space of the states (used for describing the environment).

step(act: ndarray) tuple[source]

Perform one time step of the simulation or on the real-world device. When a terminal condition is met, the reset function is called.

Note

This function is responsible for limiting the actions, i.e. has to call limit_act().

Parameters:

act – action to be taken in the step

Return obs:

current observation of the environment

Return reward:

reward depending on the selected reward function

Return done:

indicates whether the episode has ended

Return env_info:

contains diagnostic information about the environment

property task: Task

Get the task describing what the agent should do in the environment.

quanser_ball_balancer

class QBallBalancerReal(dt: float = 0.002, max_steps: int = inf, task_args: [<class 'dict'>, None] = None, ip: str = '192.168.2.5')[source]

Bases: QuanserReal, Serializable

Class for the real Quanser Ball-Balancer

Constructor

Parameters:
  • dt – sampling frequency on the [Hz]

  • max_steps – maximum number of steps executed on the device [-]

  • task_args – arguments for the task construction

  • ip – IP address of the 2 DOF Ball-Balancer platform

name: str = 'qbb'
reset(*args, **kwargs) ndarray[source]

Reset the environment. The base version (re-)opens the socket and resets the task.

Parameters:
  • args – just for compatibility with SimEnv. All args can be ignored.

  • kwargs – just for compatibility with SimEnv. All kwargs can be ignored.

quanser_cartpole

class QCartPoleReal(dt: float, max_steps: int, task_args: Optional[dict] = None, ip: Optional[str] = '192.168.2.38')[source]

Bases: QuanserReal, Serializable

Base class for the real Quanser Cart-Pole

Constructor

Parameters:
  • dt – time step size on the Quanser device [s]

  • max_steps – maximum number of steps executed on the device

  • task_args – arguments for the task construction

  • ip – IP address of the Cart-Pole platform

calibrate()[source]
observe(state) ndarray[source]

Compute the (noise-free) observation from the current state.

Note

This method should be overwritten if the environment has a distinct observation space.

Parameters:

state – current state of the environment

Returns:

observation perceived to the agent

property task

Get the task describing what the agent should do in the environment.

class QCartPoleStabReal(dt: float = 0.002, max_steps: int = inf, task_args: Optional[dict] = None, ip: Optional[str] = '192.168.2.38')[source]

Bases: QCartPoleReal

Stabilization task on the real Quanser Cart-Pole

Constructor

Parameters:
  • dt – time step size on the Quanser device [s]

  • max_steps – maximum number of steps executed on the device

  • task_args – arguments for the task construction

  • ip – IP address of the Cart-pole platform

name: str = 'qcp-st'
reset(*args, **kwargs)[source]

Reset the environment. The base version (re-)opens the socket and resets the task.

Parameters:
  • args – just for compatibility with SimEnv. All args can be ignored.

  • kwargs – just for compatibility with SimEnv. All kwargs can be ignored.

class QCartPoleSwingUpReal(dt: float = 0.002, max_steps: int = inf, task_args: Optional[dict] = None, ip: Optional[str] = '192.168.2.38')[source]

Bases: QCartPoleReal

Swing-up task on the real Quanser Cart-Pole

Constructor

Parameters:
  • dt – time step size on the Quanser device [s]

  • max_steps – maximum number of steps executed on the device

  • task_args – arguments for the task construction

  • ip – IP address of the Cart-pole platform

name: str = 'qcp-su'
reset(*args, **kwargs)[source]

Reset the environment. The base version (re-)opens the socket and resets the task.

Parameters:
  • args – just for compatibility with SimEnv. All args can be ignored.

  • kwargs – just for compatibility with SimEnv. All kwargs can be ignored.

quanser_common

class QSocket(ip: str, x_len: int, u_len: int, port: int = 9095)[source]

Bases: object

Handles the communication with Quarc (TCP/IP connection)

Prepare socket for communication.

Parameters:
  • ip – IP address of the Windows PC

  • x_len – number of measured state variables to receive

  • u_len – number of control variables to send

  • port – port to connect to, see the server block in the Simulink models

close()[source]
is_open() bool[source]

Return True is the socket connection os open and False if not.

open()[source]
snd_rcv(u) ndarray[source]

Send u and receive x.

Parameters:

u – control vector

Returns:

x: vector of measured states

class VelocityFilter(x_len: int, num: tuple = (50, 0), den: tuple = (1, 50), dt: float = 0.002, x_init: Optional[ndarray] = None)[source]

Bases: object

Discrete velocity filter derived from a continuous one

Note

This velocity filter class is currently not used since we now get the velocities from the Simulink model.

Initialize discrete filter coefficients.

Parameters:
  • x_len – number of measured state variables to receive

  • num – continuous-time filter numerator (continuous time)

  • den – continuous-time filter denominator (continuous time)

  • dt – sampling time interval

  • x_init – initial observation of the signal to filter

set_initial_state(x_init: ndarray)[source]

This method can be used to set the initial state of the velocity filter. This is useful when the initial (position) observation has been retrieved and it is non-zero. Otherwise the filter would assume a very high velocity. :param x_init: initial observation

quanser_qube

class QQubeSwingUpReal(dt: float = 0.002, max_steps: int = inf, task_args: Optional[dict] = None, ip: str = '192.168.2.17')[source]

Bases: QuanserReal, Serializable

Class for the real Quanser Qube a.k.a. Furuta pendulum

Constructor

Parameters:
  • dt – sampling frequency on the Quanser device [Hz]

  • max_steps – maximum number of steps executed on the device [-]

  • task_args – arguments for the task construction

  • ip – IP address of the Qube platform

calibrate()[source]

Calibration routine to move to the init position and determine the sensor offset

name: str = 'qq-su'
observe(state) ndarray[source]

Compute the (noise-free) observation from the current state.

Note

This method should be overwritten if the environment has a distinct observation space.

Parameters:

state – current state of the environment

Returns:

observation perceived to the agent

reset(*args, **kwargs) ndarray[source]

Reset the environment. The base version (re-)opens the socket and resets the task.

Parameters:
  • args – just for compatibility with SimEnv. All args can be ignored.

  • kwargs – just for compatibility with SimEnv. All kwargs can be ignored.

property task: Task

Get the task describing what the agent should do in the environment.

Module contents