uppaal2jetracer.controller package

Submodules

uppaal2jetracer.controller.executor module

Executor

This file provides an executor to execute declarations that follow the UPPAAL syntax.

This file can be imported and contains the following classes:

  • Executor: Executes UPPAAL declarations.

exception ExecutionError(message: str)[source]

Bases: Exception

A class to represent an error when executing hardware calls.

class Executor(frame: Frame)[source]

Bases: NodeVisitor

A NodeVisitor implementation that executes UPPAAL declarations.

constant_type_map
static stop()[source]

Stops the hardware command handler.

type_map
visit_arraydecl(array_decl: ArrayDecl)[source]

Abstract method to visit an ArrayDecl node. Return depends on implementation of this method.

Parameters:

array_decl (ArrayDecl) – The array declaration node.

visit_arrayref(array_ref: ArrayRef)[source]

Abstract method to visit an ArrayRef node. Return depends on implementation of this method.

Parameters:

array_ref (ArrayRef) – The array reference node.

visit_assignment(assignment: Assignment)[source]

Abstract method to visit an Assignment node. Return depends on implementation of this method.

Parameters:

assignment (Assignment) – The assignment node.

visit_binaryop(binaryop: BinaryOp)[source]

Abstract method to visit a BinaryOp node. Return depends on implementation of this method.

Parameters:

binaryop (BinaryOp) – The binary operation node.

visit_compound(compound: Compound)[source]

Abstract method to visit a Compound node. Return depends on implementation of this method.

Parameters:

compound (Compound) – The compound node.

visit_compoundliteral(compound_literal: CompoundLiteral)[source]

Abstract method to visit a CompoundLiteral node. Return depends on implementation of this method.

Parameters:

compound_literal (CompoundLiteral) – The compound literal node.

visit_constant(constant: Constant)[source]

Abstract method to visit a Constant node. Return depends on implementation of this method.

Parameters:

constant (Constant) – The constant node.

visit_decl(decl: Decl)[source]

Abstract method to visit a Decl node. Return depends on implementation of this method.

Parameters:

decl (Decl) – The declaration node.

visit_decllist(decl_list: DeclList)[source]

Abstract method to visit a DeclList node. Return depends on implementation of this method.

Parameters:

decl_list (DeclList) – The declaration list node.

visit_emptystatement()[source]

Abstract method to visit an EmptyStatement node. Return depends on implementation of this method.

visit_exprlist(expr_list: ExprList)[source]

Abstract method to visit an ExprList node. Return depends on implementation of this method.

Parameters:

expr_list (ExprList) – The expression list node.

visit_fileast(fileast: FileAST)[source]

Abstract method to visit a FileAST node. Return depends on implementation of this method.

Parameters:

fileast (FileASt) – The fileast node.

visit_funccall(funccall: FuncCall)[source]

Abstract method to visit a FuncCall node. Return depends on implementation of this method.

Parameters:

funccall (FuncCall) – The function call node.

visit_funcdecl(funcdecl: FuncDecl)[source]

Abstract method to visit a FuncDecl node. Return depends on implementation of this method.

Parameters:

funcdecl (FuncDecl) – The function declaration node.

visit_funcdef(funcdef: FuncDef)[source]

Abstract method to visit a FuncDef node. Return depends on implementation of this method.

Parameters:

funcdef (FuncDef) – The function definition node.

visit_id(identifier: ID)[source]

Abstract method to visit an ID node. Return depends on implementation of this method.

Parameters:

identifier (ID) – The identifier node.

visit_identifiertype(identifier_type: IdentifierType)[source]

Abstract method to visit an IdentifierType node. Return depends on implementation of this method.

Parameters:

identifier_type (IdentifierType) – The identifier type node.

visit_initlist(init_list: InitList)[source]

Abstract method to visit an InitList node. Return depends on implementation of this method.

Parameters:

init_list (InitList) – The initialization list node.

visit_namedinitializer(named_initializer: NamedInitializer)[source]

Abstract method to visit a NamedInitializer node. Return depends on implementation of this method.

Parameters:

named_initializer (NamedInitializer) – The named initializer node.

visit_paramlist(param_list: ParamList)[source]

Abstract method to visit a ParamList node. Return depends on implementation of this method.

Parameters:

param_list (ParamList) – The parameter list node.

visit_rangedecl(range_decl: RangeDecl)[source]

Abstract method to visit a RangeDecl node. Return depends on implementation of this method.

Parameters:

range_decl (RangeDecl) – The range declaration node.

visit_return(ret: Return)[source]

Abstract method to visit a Return node. Return depends on implementation of this method.

Parameters:

ret (Return) – The return node.

visit_struct(struct: Struct)[source]

Abstract method to visit a Struct node. Return depends on implementation of this method.

Parameters:

struct (Struct) – The struct node.

visit_structref(structref: StructRef)[source]

Abstract method to visit a StructRef node. Return depends on implementation of this method.

Parameters:

structref (StructRef) – The struct reference node.

visit_typedecl(typedecl: TypeDecl)[source]

Abstract method to visit a TypeDecl node. Return depends on implementation of this method.

Parameters:

typedecl (TypeDecl) – The type declaration node.

visit_typedef(typedef: Typedef)[source]

Abstract method to visit a Typedef node. Return depends on implementation of this method.

Parameters:

typedef (Typedef) – The type definition node.

visit_typename(typename: Typename)[source]

Abstract method to visit a Typename node. Return depends on implementation of this method.

Parameters:

typename (Typename) – The type name node.

visit_unaryop(unaryop: UnaryOp)[source]

Abstract method to visit a UnaryOp node. Return depends on implementation of this method.

Parameters:

unaryop (UnaryOp) – The unary operation node.

exception HardwareCallError(message: str)[source]

Bases: Exception

A class to represent an error when executing hardware calls.

uppaal2jetracer.controller.hardware_command_system module

Hardware command system

This module provides a system for handling hardware commands and their execution.

This file can be imported and contains the following classes:

  • HardwareCommandHandler: Handles HardwareCommand calls.

  • HardwareCommand: Capsules functionality of a command for any hardware.

  • JRHardwareCommand: HardwareCommand for a NVIDIA JetRacer ROS AI Kit.

  • TurnCommand: Turns a JetRacer.

  • SetSpeedCommand: Sets a JetRacers speed.

  • PotentialCollisionCommand: Checks if a JetRacer is about to run into something.

  • FreeAheadCommand: Checks if there is something ahead of a JetRacer.

  • HardwareCommandResult: Result of a HardwareCommand.

class FreeAheadCommand(jr_hardware_controller: JRHardwareController)[source]

Bases: JRHardwareCommand[bool]

A class to represent a hardware command for checking if the path ahead is free.

Parameters: - collision_threshold (optional): The distance threshold for a potential collision in meters. Default: 0.8 meters.

execute(params: List[object]) HardwareCommandResult[bool][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

class HardwareCommand(hardware_controller: HardwareController)[source]

Bases: ABC, Generic

A class to represent a hardware command.

Variables:

_hardware_controller (HardwareController) – The hardware controller used by the command.

abstract execute(params: List[object]) HardwareCommandResult[T][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

property hardware_controller: HardwareController

Get the hardware controller used by the command.

Returns:

The hardware controller.

Return type:

HardwareController

exception HardwareCommandError(message: str)[source]

Bases: Exception

A class to represent an error in a HardwareCommand.

class HardwareCommandHandler[source]

Bases: object

A class for handling hardware commands and their execution.

Variables:
  • _hardware_commands (Dict[str, HardwareCommand]) – The existing hardware commands.

  • _hardware_controller (List[HardwareController]) – The hardware controller used by the commands.

FREE_AHEAD_COMMAND_NAME = 'free_ahead'
POTENTIAL_COLLISION_COMMAND_NAME = 'potential_collision'
SET_SPEED_COMMAND_NAME = 'set_speed'
TURN_COMMAND_NAME = 'turn'
get_command(name: str) HardwareCommand[Any][source]

Get a hardware command by name.

Parameters:

name (str) – The name of the command.

Returns:

The hardware command. None if the command does not exist.

Return type:

HardwareCommand[Any]

has_command(name: str) bool[source]

Check if a hardware command exists.

Parameters:

name (str) – The name of the command.

Returns:

True if the command exists. False otherwise.

Return type:

bool

run_command(command: HardwareCommand, params: List[object]) HardwareCommandResult[Any][source]

Run a hardware command. If the hardware state is ERROR, all hardware controller will be shut down.

Parameters:
  • command (HardwareCommand) – The hardware command to run.

  • params (List[object]) – The parameters for the command.

Returns:

The result of the hardware command.

Return type:

HardwareCommandResult[Any]

stop()[source]

Stops all hardware controllers.

class HardwareCommandResult(result_type: ~uppaal2jetracer.controller.hardware_command_system.HardwareCommandResultType, hardware_result: ~uppaal2jetracer.controller.hardware_controller.HardwareResult = <uppaal2jetracer.controller.hardware_controller.HardwareResult object>)[source]

Bases: Generic

A class to represent the result of a HardwareCommand.

Variables:
  • _result (T) – The result of the command. May be None on failure.

  • _result_type (HardwareCommandResultType) – The type of the result. Automatically set to HARDWARE_FAILURE if the hardware state is ERROR.

property result: T

Get the result of the command.

Returns:

The result of the command.

Return type:

T

property result_type: HardwareCommandResultType

Get the type of the result. :return: The type of the result. :rtype: HardwareCommandResultType

property return_type: type

Get the return type of the command. :return: The return type of the command. :rtype: type

class HardwareCommandResultType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

A enum class to represent the result type of a HardwareCommand.

HARDWARE_FAILURE = -1
PARTIAL_SUCCESS = 1
SUCCESS = 0
exception HardwareError(command_name: str)[source]

Bases: HardwareCommandError

A class to represent an error in a HardwareCommand due to a hardware error.

exception InvalidParamTypeError(command_name: str, param_index: int, actual_type: type, expected_type: type)[source]

Bases: HardwareCommandError

A class to represent an error in a HardwareCommand due to an invalid parameter type.

exception InvalidParamValueError(command_name: str, param_index: int, value: Any, message: str)[source]

Bases: HardwareCommandError

A class to represent an error in a HardwareCommand due to an invalid parameter value.

exception InvalidParamsAmountError(command_name: str, actual_amount: int, expected_amount: int)[source]

Bases: HardwareCommandError

A class to represent an error in a HardwareCommand due to an invalid amount of parameters.

class JRHardwareCommand(jr_hardware_controller: JRHardwareController)[source]

Bases: HardwareCommand, Generic

A class to represent a hardware command for the JetRacer.

execute(params: List[object]) HardwareCommandResult[T][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

class PotentialCollisionCommand(jr_hardware_controller: JRHardwareController)[source]

Bases: JRHardwareCommand[bool]

A class to represent a hardware command for checking if a potential collision is detected.

Parameters: - collision_threshold (optional): The distance threshold for a potential collision in meters. Default: 0.8 meters.

execute(params: List[object]) HardwareCommandResult[bool][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

class SetSpeedCommand(jr_hardware_controller: JRHardwareController)[source]

Bases: JRHardwareCommand[None]

A class to represent a hardware command for setting the speed of the JetRacer.

Parameters: - speed: The speed of the JetRacer in m/s. Range: [-1.2, 1.2]

execute(params: List[object]) HardwareCommandResult[None][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

class TurnCommand(jr_hardware_controller: JRHardwareController)[source]

Bases: JRHardwareCommand[None]

A class to represent a hardware command for turning the JetRacer.

Parameters: - theta: The angle to turn the JetRacer in radians.

execute(params: List[object]) HardwareCommandResult[None][source]

Execute the hardware command.

Parameters:

params (List[object]) – The parameters for the command.

Returns:

The result of the command.

Return type:

HardwareCommandResult[T]

uppaal2jetracer.controller.hardware_controller module

Hardware controller

This module contains the hardware controller class for the JetRacer.

This file can be imported and contains the following classes:

  • HardwareController: Controls a specific hardware.

  • HardwareResult: Contains result of hardware accesses.

  • HardwareState: State of the hardware.

  • JRHardwareController: Controls a NVIDIA JetRacer ROS AI Kit.

class HardwareController[source]

Bases: ABC

A class to represent a hardware controller. Each method should return a HardwareResult with a correct HardwareState. This allows the hardware command system to savely handle hardware errors.

abstract shutdown()[source]

Shut down the hardware controller and associated hardware.

abstract stop()[source]

Stops running hardware.

class HardwareResult(hardware_state: HardwareState, result: T)[source]

Bases: Generic

A class to represent a hardware result.

Variables:
  • _hardware_state (HardwareState) – The state of the hardware.

  • _result (T) – The result of the hardware operation.

property hardware_state: HardwareState

Get the state of the hardware.

Returns:

The state of the hardware.

Return type:

HardwareState

property result: T

Get the result of the hardware operation.

Returns:

The result of the hardware operation.

Return type:

T

class HardwareState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

This enum represents the state of underlying hardware.

ERROR = 1
OK = 0
class JRHardwareController[source]

Bases: HardwareController

A class to represent a hardware controller for the JetRacer.

free_ahead(collision_threshold: float = None) HardwareResult[bool][source]

Check if there is enough free space ahead. :return: True if there is enough free space ahead, False otherwise. :rtype: HardwareResult[bool

potential_collision(collision_threshold: float = None) HardwareResult[bool][source]

Check if there is a potential collision ahead.

Returns:

True if there is a potential collision ahead, False otherwise.

Return type:

HardwareResult[bool]

set_speed(speed: float) HardwareResult[None][source]

Set the speed of the JetRacer.

Parameters:

speed (float) – The speed to set the JetRacer to in m/s. Range: [-1.2, 1.2]

Returns:

The result of the set speed operation.

Return type:

HardwareResult[None]

shutdown()[source]

Shut down ROS 2 and rclpy.

stop()[source]

Stop the JetRacer.

turn(theta: float) HardwareResult[None][source]

Turn the JetRacer by a given angle. :param theta: The angle to turn the JetRacer in radians. :type theta: float :return: The result of the turn operation. :rtype: HardwareResult[None]

uppaal2jetracer.controller.uppaal_controller module

UPPAAL controller

This file provides controllers to run parsed UPPAAL automata.

This file can be imported and contains the following classes:

  • SystemController: Controls the execution of a parsed UPPAAL system.

  • AutomatonController: Controls the execution of a single parsed UPPAAL automaton.

class AutomatonController(automaton: Automaton)[source]

Bases: object

The automaton controller manages all processes that involve one automaton while runtime.

property automaton

Returns the automaton of the controller.

Returns:

The automaton of the controller.

Return type:

Automaton

can_step(transition: Transition, frame: Frame = None) bool[source]

Checks if a transition has a valid guard and if the next invariant is valid for a given frame. Default frame is the frame of the automaton.

Parameters:
  • transition (Transition) – The transition to check.

  • frame (Frame) – The variables to compare with.

Returns:

True if the transition is valid, else False.

Return type:

bool

clean_up_channels()[source]

Function to remove all transitions from the channels that originate of the current location.

property current_location

Returns the current location inside the automaton.

Returns:

The current_location

Return type:

Location

execute(update: Update, executor: Executor = None)[source]

Evaluates and updates the update assignments of a Transition.

Parameters:
  • update (Update) – The update to execute

  • executor (Executor) – The executor to use

execute_step(transition: Transition)[source]

Takes a transition and changes current location and executes the update.

Parameters:

transition (Transition) – The transition to take.

execute_sync(sync: Synchronization, executor: Executor = None) Channel | None[source]

Evaluates a Synchronization to it’s corresponding channel.

Parameters:
Returns:

The channel of the synchronization.

Return type:

Channel

is_valid(node: Node, executor: Executor = None) bool[source]

Checks if an expression is evaluated as true or false. Default executor is automaton executor.

Parameters:
  • node (Node) – The root node of the expression.

  • executor (Executor) – The executor to use to execute the expression.

Returns:

True when expression is true, False when expression is false.

Return type:

bool

step() Tuple[Transition | None, Channel | None][source]

Checks if the automaton has a valid transition, and returns it together with the channel.

Returns:

A tuple of optional transition, channel.

Return type:

Tuple[Optional[Transition], Optional[Channel]]

exception InvalidGuardError(transition: Transition)[source]

Bases: TypeError

Error that is raised when a guard has an invalid syntax.

exception InvalidInvariantError(transition: Transition)[source]

Bases: TypeError

Error that is raised when an invariant has an invalid syntax.

class SystemController(system: System)[source]

Bases: object

The system controller is simulating the system and managing automaton controller.

property automata_controller

Returns the list of automata controller managed by the controller.

Returns:

The list of automata controller

Return type:

List[AutomatonController]

property is_running: bool

Returns whether the controller is running or not.

Returns:

Whether the controller is running.

Return type:

bool

run_system()[source]

The main loop of the system, call to start execution.

property system

Returns the uppaal model system entity of the controller.

Returns:

The system object.

Return type:

System

exception UnexpectedTypeError(expected_type: type, gotten_type: type)[source]

Bases: TypeError

Error that is raised when an unexpected argument is returned by the executor.

Module contents