Model Package¶
model.communication module¶
A module for converting program data to the required format and communicating it via serial.
Represent the part of the model in the MVC. Receives the data from the controller, converts it to the required byte format and sends it to a connected microcontroller via pyserial.
Typical usage:
communication = SerialMessenger(port, baud_rate=9600)
- class model.communication.SerialMessenger(port: str, baud_rate: int = 9600)[source]¶
Bases:
object
Communication point between program and physical tank.
Used by the controller to send its data (user input) to an antenna that later communicates it to a physical instance of the tank.
- port¶
A string representing the serial port to which the device is connected.
- baud_rate¶
An integer representing the speed of data transmission in bits per second.
- ser¶
A serial.Serial instance representing the serial connection.
- tank¶
instance of tank class representing the values needed to be sent
- model.communication.float_to_byte(value: float) int [source]¶
Convert a floating-point value to a byte representation.
This function takes a floating-point value within the range [-1, 1], normalizes it to the range [0, 1], and then scales it to the range [0, 255].
- Parameters:
value (float) – The value to convert to a byte representation.
- Returns:
An integer representing the byte value.
- Return type:
int
- Raises:
ValueError – If the input value is not within the range [-1, 1].
model.tank module¶
A module for saving the current values of the tank.
Represent the part of the model in the MVC. Contains the current values needed for the tank to operate.
Typical usage:
tank = Tank() tank.get_values()
- class model.tank.Tank[source]¶
Bases:
object
Values of the tank that are needed to operate it.
All the values that are going to be communicated to the tank are stored here.
- get_values() List[int] [source]¶
Get the current values of the tank.
- Returns:
A list of integers representing the current values of the tank.
- property light: int¶
Whether the light are turned on or off.
- property sound: int¶
Whether the sound signal is on or off.
- property speed1: int¶
X coordinate of the joystick representing speed and direction.
- property speed2: int¶
Y coordinate of the joystick representing speed and direction.
- property sth: int¶
Additional functionality that can be added later.
- property tower_x: int¶
X coordinate of the joystick representing the position of the tank tower.
- property tower_y: int¶
Y coordinate of the joystick representing the position of the tank tower.
- property water: int¶
Whether the water is being shot or not.