Controller Package

controller.controls module

Module for controlling a tank system via serial communication and updating a GUI based on gamepad input.

This module provides functionality for controlling a tank system through serial communication with an Arduino board. It interfaces with a gamepad controller to receive input from the user and updates a graphical user interface (GUI) accordingly. Represent the controller in the MVC. Uses Singleton.

Typical usage example:

controls = Controls() controls.window.show()

class controller.controls.Controls[source]

Bases: QObject

Handles the control flow between the gamepad input and the application window.

This class manages the connection between a gamepad and the application, including serial communication setup, signal-slot connections, and user interface interactions.

window

The main application window.

comms

An instance of SerialMessenger for serial communication.

gamepad

An instance of XboxController for handling gamepad inputs.

send

A threading.Thread for handling background serial communication.

b_clicked(val: int)[source]
check_previous_ports() str[source]

Check if a port was previously selected within a time frame of 5 minutes.

Returns:

The previously selected port if it was selected within the

specified time frame and is available; otherwise, an empty string.

Return type:

str

l2_pressed(r: float)[source]
left_joystick_move_slot(x: float, y: float)[source]
classmethod load_ports_from_json() dict[source]

Load previously saved port data from JSON file.

Returns:

A dictionary containing port data loaded from the JSON file.

If the file doesn’t exist, an empty dictionary is returned.

Return type:

dict

r2_pressed(r: float)[source]
right_joystick_move_slot(x: float, y: float)[source]
classmethod save_ports_to_json(port: str) None[source]

Save the selected port to a JSON file with timestamp.

Parameters:

port (str) – The selected port to be saved to the JSON file.

staticMetaObject = PySide6.QtCore.QMetaObject("Controls" inherits "QObject": Methods:   #4 type=Slot, signature=l2_pressed(double), parameters=double   #5 type=Slot, signature=r2_pressed(double), parameters=double   #6 type=Slot, signature=left_joystick_move_slot(double,double), parameters=double, double   #7 type=Slot, signature=right_joystick_move_slot(double,double), parameters=double, double   #8 type=Slot, signature=b_clicked(int), parameters=int   #9 type=Slot, signature=x_clicked(int), parameters=int )
x_clicked(val: int)[source]

controller.gamepad module

A module for interfacing with an Xbox controller and emitting signals based on input events.

class controller.gamepad.XboxController[source]

Bases: QObject

Handles Xbox controller inputs and emits signals for various actions.

This class monitors the Xbox controller inputs and emits signals for joystick movements, trigger presses, and button clicks. It also handles toggling variables for specific buttons.

leftJoystickPos

A signal emitted with two floats for the left joystick position.

rightJoystickPos

A signal emitted with two floats for the right joystick position.

l2_pressed

A signal emitted with a float for the left trigger pressure.

r2_pressed

A signal emitted with a float for the right trigger pressure.

buttonAClicked

A signal emitted when the A button is clicked.

buttonYClicked

A signal emitted when the Y button is clicked.

xChanged

A signal emitted with an integer when the X button toggles variable changes.

bChanged

A signal emitted with an integer when the B button toggles variable changes.

MAX_TRIG_VAL

The maximum value for trigger inputs.

MAX_JOY_VAL

The maximum value for joystick inputs.

MAX_JOY_VAL = 32768.0
MAX_TRIG_VAL = 256.0
bChanged
buttonAClicked
buttonYClicked
l2_pressed
leftJoystickPos
r2_pressed
rightJoystickPos
staticMetaObject = PySide6.QtCore.QMetaObject("XboxController" inherits "QObject": Methods:   #4 type=Signal, signature=leftJoystickPos(double,double), parameters=double, double   #5 type=Signal, signature=rightJoystickPos(double,double), parameters=double, double   #6 type=Signal, signature=l2_pressed(double), parameters=double   #7 type=Signal, signature=r2_pressed(double), parameters=double   #8 type=Signal, signature=buttonAClicked()   #9 type=Signal, signature=buttonYClicked()   #10 type=Signal, signature=xChanged(int), parameters=int   #11 type=Signal, signature=bChanged(int), parameters=int )
toggle_variable_b_handler()[source]

Toggles handler for button B.

This method toggles the B variable between zero and one and emits a signal if it changes.

toggle_variable_x_handler()[source]

Toggles handler for button X.

This method toggles the X variable between zero and one and emits a signal if it changes.

xChanged