aeroshield.aeroshield
Submodules
Package Contents
Classes
- class aeroshield.aeroshield.AeroShield(baudrate: int | None = 115200, port: str | None = None)[source]
- RUN = 1
- STOP = 2
- TIMEOUT = 3
- find_arduino() str[source]
Get the name of the port that is connected to Arduino. Raises exception if no port was found.
- Raises:
AeroShieldException – Raised if no Arduino was found.
- Returns:
COM port of the Arduino.
- Return type:
str
- static raw_angle_to_deg(raw: int) float[source]
Convert raw angle to degrees.
- Parameters:
raw (int) – 12-bit value of angle sensor.
- Returns:
Angle value scaled to degrees.
- Return type:
float
- static raw_angle_to_rad(raw: int) float[source]
Convert raw angle to radians.
- Parameters:
raw (int) – 12-bit value of angle sensor.
- Returns:
Angle value scaled to radians.
- Return type:
float
- calibrated_angle_deg(raw_angle: int) float[source]
Convert angle to degrees and calibrate with zero angle.
- Parameters:
raw_angle (int) – Raw 12-bit angle value.
- Returns:
Calibrated angle in degrees.
- Return type:
float
- static raw_pot_to_percent(raw: int) float[source]
Convert 10-bit potentiometer reading to percentage value.
- Parameters:
raw (int) – 10-bit potentiometer value.
- Returns:
Potentiometer value as percentage [0, 1).
- Return type:
float
- read() tuple[float][source]
Read data from Arduino. Convert potentiometer and angle readings. Calibrate angle to zero reference.
- Raises:
AeroShieldException – Raised if no data was received. This can happen if there was no write command preceding a call to read.
- Returns:
Converted and calibrated potentiometer and angle readings, in that order.
- Return type:
tuple[float]
- static saturate(value: float, bits: int) int[source]
Saturate value between 0 and 2**bits - 1.
- Parameters:
value (float) – Raw value.
bits (int) – Number of bits.
- Returns:
Saturated value.
- Return type:
int
- write(flag: int, motor: float) int[source]
Write run/stop flag and motor value to Arduino. Saturate the motor value.
- Parameters:
flag (int) – AeroShield.RUN or AeroShield.STOP. The former signals normal running mode, the latter tells the Arduino to stop the motor.
motor (float) – Motor value.
- Returns:
Saturated 8-bit motor value.
- Return type:
int
- calibrate()[source]
Read out a zero reference. Pendulum should be at rest when calling this method.
- class aeroshield.aeroshield.DummyShield[source]
Bases:
aeroshield.aeroshield.aeroshield.AeroShield- read() tuple[float][source]
Read data from Arduino. Convert potentiometer and angle readings. Calibrate angle to zero reference.
- Raises:
AeroShieldException – Raised if no data was received. This can happen if there was no write command preceding a call to read.
- Returns:
Converted and calibrated potentiometer and angle readings, in that order.
- Return type:
tuple[float]
- write(flag: int, motor: float)[source]
Write run/stop flag and motor value to Arduino. Saturate the motor value.
- Parameters:
flag (int) – AeroShield.RUN or AeroShield.STOP. The former signals normal running mode, the latter tells the Arduino to stop the motor.
motor (float) – Motor value.
- Returns:
Saturated 8-bit motor value.
- Return type:
int