Lib Folder
bno08x
BNO08XError
Bases: Exception
Custom exception class for BNO08X errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
__init__(message)
Initializes the BNO08XError with a custom message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
16 17 18 19 20 21 |
|
__str__()
Returns a string representation of the BNO08XError.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
23 24 25 26 27 |
|
BNO08XHandler
A class to handle BNO08X sensor operations.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
accumulated_90_deg_turns
property
Returns the accumulated 90-degree turns since the last reset.
accumulated_yaw_deg
property
Returns the accumulated yaw degrees value since the last reset.
gyro
property
Returns the current gyroscope data in radians from the BNO08X sensor.
gyro_x
property
Returns the current gyroscope X value in degrees from the BNO08X sensor.
gyro_y
property
Returns the current gyroscope Y value in degrees from the BNO08X sensor.
gyro_z
property
Returns the current gyroscope Z value in degrees from the BNO08X sensor.
initial_pitch
property
Returns the initial pitch value in degrees.
initial_roll
property
Returns the initial roll value in degrees.
initial_yaw
property
Returns the initial yaw value in degrees.
pitch
property
Returns the current pitch value in degrees from the BNO08X sensor.
quaternion
property
Returns the current quaternion data from the BNO08X sensor.
roll
property
Returns the current roll value in degrees from the BNO08X sensor.
turns
property
Returns the number of 90-degree turns made since the last reset.
yaw
property
Returns the current yaw value in degrees from the BNO08X sensor.
__init__(i2c, address=I2C_ADDRESS, serial_communication=None, is_upside_down=False)
Initializes the BNO08X handler with the specified I2C bus and address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i2c
|
I2C
|
The I2C bus to use for communication with the BNO08X sensor. |
required |
address
|
int
|
The I2C address of the BNO08X sensor. |
I2C_ADDRESS
|
serial_communication
|
SerialCommunication | None
|
Optional serial communication handler. |
None
|
is_upside_down
|
bool
|
If True, the sensor is mounted upside down. |
False
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
__read_gyro()
async
Reads the gyroscope data.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
254 255 256 257 258 259 260 261 |
|
__read_quaternion()
async
Reads the quaternion data from the BNO08X sensor.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
275 276 277 278 279 280 281 282 |
|
calibrate()
async
Calibrates the BNO08X sensor by taking initial readings to set the initial orientation.
Raises:
Type | Description |
---|---|
BNO08XError
|
If the sensor is already calibrated. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
gyro_to_degrees(x_rad, y_rad, z_rad)
staticmethod
Converts gyroscope readings from radians to degrees.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
136 137 138 139 140 141 142 143 144 145 |
|
quaternion_to_euler_degrees(x, y, z, w)
staticmethod
This function receives the 4 components of the quaternion and calculates the orientation
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
update_gyro()
async
Reads the gyroscope data from the BNO08X sensor and updates the gyroscope values in degrees.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
263 264 265 266 267 268 269 270 271 272 273 |
|
update_quaternion()
async
Reads the quaternion data from the BNO08X sensor and updates the roll, pitch, and yaw values.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\bno08x.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
enums
Challenge
Class to represent the enum challenge messages sent and received from the Raspberry Pi Pico.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
from_string(challenge_str)
classmethod
Convert a string to a Challenge enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
challenge_str
|
str
|
The string representation of the challenge. |
required |
Returns:
str: The corresponding Challenge enum value.
Raises:
ValueError: If the challenge string does not match any known challenge.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
IncomingCategory
Class to represent the enum categories of incoming messages from the Raspberry Pi 5.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
from_string(category_str)
classmethod
Convert a string to a IncomingCategory enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category_str
|
str
|
The string representation of the category. |
required |
Returns:
str: The corresponding IncomingCategory enum value.
Raises:
ValueError: If the category string does not match any known category.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
OutgoingCategory
Class to represent the enum categories of outgoing messages to the Raspberry Pi 5.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
from_string(category_str)
classmethod
Convert a string to a OutgoingCategory enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category_str
|
str
|
The string representation of the category. |
required |
Returns:
str: The corresponding OutgoingCategory enum value.
Raises:
ValueError: If the category string does not match any known category.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
Status
Class to represent the enum status messages sent and received to the Raspberry Pi 5.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
from_string(status_str)
classmethod
Convert a string to a Status enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_str
|
str
|
The string representation of the status. |
required |
Returns:
str: The corresponding Status enum value.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\enums.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
env
Env
Environment variables manager class.
This class provides methods to access environment variables related to debug mode and challenge type.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\env.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_challenge()
staticmethod
Get the challenge type from the environment variable.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The challenge type. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\env.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_debug_mode()
staticmethod
Get the debug mode from the environment variable.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if debug mode is enabled, otherwise False. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\env.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
get_movement_mode()
staticmethod
Get the movement mode from the environment variable.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if movement mode is enabled, otherwise False. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\env.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
esc_motor
ESCMotorError
Bases: Exception
Custom exception class for ESC motor errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
__init__(message)
Initializes the ESCMotorError with a custom message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
16 17 18 19 20 21 |
|
__str__()
Returns a string representation of the ESCMotorError.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
23 24 25 26 27 |
|
ESCMotorHandler
A class to handle ESC (Electronic Speed Controller) motor operations.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
speed
property
Returns the current speed of the ESC motor.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Current speed value between -1.0 (full reverse) and 1.0 (full forward). |
__init__(motor_pin, frequency=PWM_FREQUENCY, min_pulse=MIN_PULSE, max_pulse=MAX_PULSE, movement=True, debug=False, serial_communication=None)
Initializes the ESC motor handler with the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motor_pin
|
int
|
The GPIO pin connected to the ESC motor. |
required |
frequency
|
int
|
The PWM frequency for the ESC motor. |
PWM_FREQUENCY
|
min_pulse
|
int
|
Minimum pulse width for the ESC motor. |
MIN_PULSE
|
max_pulse
|
int
|
Maximum pulse width for the ESC motor. |
MAX_PULSE
|
movement
|
bool
|
If True, the motor will be controlled for movement; if False, it will not. |
True
|
debug
|
bool
|
If True, debug messages will be sent. |
False
|
serial_communication
|
SerialCommunication
|
An instance of SerialCommunication for sending debug messages. |
None
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
backward(speed)
async
Sets the speed of the ESC motor backward.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed
|
float
|
Speed value between 0 and 1.0 (full backward). |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
178 179 180 181 182 183 184 185 186 |
|
forward(speed)
async
Sets the speed of the ESC motor forward.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed
|
float
|
Speed value between 0 and 1.0 (full forward). |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
168 169 170 171 172 173 174 175 176 |
|
set_speed(speed)
async
Sets the speed of the ESC motor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed
|
float
|
Speed value between -1.0 (full reverse) and 1.0 (full forward). |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
stop()
async
Sets the speed of the ESC motor to 0.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\esc_motor.py
162 163 164 165 166 |
|
led
LEDHandler
A class to manage the onboard LED of the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
__init__(led_pin)
Initializes the LED on the specified GPIO pin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
led_pin
|
int
|
The GPIO number where the LED is connected. Default is 25. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
11 12 13 14 15 16 17 18 19 |
|
blink(times=1, delay=0.5)
async
Blinks the LED a specified number of times with a delay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
times
|
int
|
The number of times to blink the LED. Default is 1. |
1
|
delay
|
float
|
The delay in seconds between on and off states. Default is 0.5 seconds. |
0.5
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
is_off()
Checks if the LED is currently off.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the LED is off, False otherwise. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
38 39 40 41 42 43 44 45 |
|
is_on()
Checks if the LED is currently on.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the LED is on, False otherwise. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
25 26 27 28 29 30 31 32 |
|
off()
Turns the LED off.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
34 35 36 |
|
on()
Turns the LED on.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
21 22 23 |
|
toggle()
Toggles the LED state.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\led.py
47 48 49 |
|
message
IncomingMessage
Class to handle the messages received from the Raspberry Pi 5.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
category
property
writable
Property to get the message category.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The category of the message. |
content
property
writable
Get the message content.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The content of the message. |
__eq__(other)
Check if two messages are equal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
IncomingMessage
|
The other message to compare with. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the messages are equal, False otherwise. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
__init__(category, content)
Initialize the message class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
The category of the message. |
required |
content
|
str
|
The content of the message. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
15 16 17 18 19 20 21 22 23 24 |
|
__str__()
String representation of the message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
26 27 28 29 30 |
|
format_to_send_with_error_message()
Format the message to send with an error message.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The formatted message string. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
111 112 113 114 115 116 117 118 |
|
from_string(msg_str)
staticmethod
Create a IncomingMessage object from a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg_str
|
str
|
The string representation of the message. |
required |
Returns:
Name | Type | Description |
---|---|---|
IncomingMessage |
IncomingMessage
|
The IncomingMessage object created from the string. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
OutgoingMessage
Class to handle the messages sent to the Raspberry Pi 5.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
category
property
writable
Property to get the message category.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The category of the message. |
content
property
writable
Get the message content.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The content of the message. |
__eq__(other)
Check if two messages are equal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
OutgoingMessage
|
The other message to compare with. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the messages are equal, False otherwise. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
143 144 145 146 147 148 149 150 151 152 153 154 |
|
__init__(category, content)
Initialize the message class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
The category of the message. |
required |
content
|
str
|
The content of the message. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
126 127 128 129 130 131 132 133 134 135 |
|
__str__()
String representation of the message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
137 138 139 140 141 |
|
format_to_send_with_error_message()
Format the message to send with an error message.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The formatted message string. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
222 223 224 225 226 227 228 229 |
|
from_string(msg_str)
staticmethod
Create a OutgoingMessage object from a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg_str
|
str
|
The string representation of the message. |
required |
Returns:
Name | Type | Description |
---|---|---|
OutgoingMessage |
OutgoingMessage
|
The OutgoingMessage object created from the string. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\message.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
serial_communication
SerialCommunication
A class to handle serial communication over USB CDC in CircuitPython.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__init__(challenge, console_port_enabled=CONSOLE_PORT_ENABLED, data_port_enabled=DATA_PORT_ENABLED, led=None)
Initialize the SerialCommunication instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
challenge
|
str
|
The challenge type for the robot. |
required |
console_port_enabled
|
bool
|
Whether to enable the console port for sending messages. |
CONSOLE_PORT_ENABLED
|
data_port_enabled
|
bool
|
Whether to enable the data port for receiving messages. |
DATA_PORT_ENABLED
|
led
|
LEDHandler | None
|
Optional LED handler for toggling the LED on message receive. |
None
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
receive_messages()
async
Receive messages from the USB CDC data stream.
Returns:
Type | Description |
---|---|
list[IncomingMessage]
|
list[IncomingMessage]: A list of received messages or None if no messages are waiting. |
Raises:
SerialCommunicationError: If the data port is not enabled or if there is an error in reading messages.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
send_bno08x_turns_message(turns)
Send a BNO08x turns message to the console port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
turns
|
int
|
The number of turns to send. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
270 271 272 273 274 275 276 277 278 279 280 281 |
|
send_bno08x_yaw_deg_message(yaw_deg)
Send a BNO08x yaw degrees message to the console port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaw_deg
|
float
|
The yaw value to send. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
257 258 259 260 261 262 263 264 265 266 267 268 |
|
send_buffer_message(category, msg)
Send a message in chunks to the USB CDC console stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
The category of the message. |
required |
msg
|
StringIO
|
The message to send as a StringIO object. |
required |
Raises:
SerialCommunicationError: If the console port is not enabled or if there is an error in sending the message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
send_challenge_message()
async
Send a challenge message to the console port.
Raises:
Type | Description |
---|---|
SerialCommunicationError
|
If the console port is not enabled or if confirmation is not received. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
send_confirmation_message()
Sends a confirmation message through the data port.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
197 198 199 200 201 |
|
send_error_message(error)
Send an error message to the console port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The error to send. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
283 284 285 286 287 288 289 290 291 |
|
send_initialization_message()
Send an END_CHAR message to the console port to indicate initialization.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
send_message(msg)
Send a message to the USB CDC console stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg
|
OutgoingMessage
|
The message to send. |
required |
Raises:
SerialCommunicationError: If the console port is not enabled or if there is an error in sending the message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
start()
async
Send the start message to the console port and wait for confirmation.
Raises:
Type | Description |
---|---|
SerialCommunicationError
|
If the console port is not enabled or if confirmation is not received. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
stop()
async
Close the serial communication.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
wait_for_confirmation_message(msg_to_confirm, timeout=CONFIRMATION_TIMEOUT)
async
Wait for a confirmation message from the console port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
float
|
The maximum time to wait for a confirmation message. |
CONFIRMATION_TIMEOUT
|
msg_to_confirm
|
OutgoingMessage
|
The message to confirm. |
required |
Raises:
SerialCommunicationError: If the confirmation message is not received within the timeout period.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
SerialCommunicationError
Bases: Exception
Custom exception class for serial communication errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\serial_communication.py
18 19 20 21 22 23 24 25 26 27 28 |
|
servo
ServoError
Bases: Exception
Custom exception class for servo motor errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
__init__(message)
Initializes the ServoError with a custom message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
17 18 19 20 21 22 |
|
__str__()
Returns a string representation of the ServoError.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
24 25 26 27 28 |
|
ServoHandler
A class to handle servo motor operations.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
angle
property
Returns the current angle of the servo motor.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The current angle of the servo motor. |
__init__(servo_pin, frequency=PWM_FREQUENCY, min_pulse=MIN_PULSE, max_pulse=MAX_PULSE, actuation_range=ACTUATION_RANGE, movement=True, debug=False, serial_communication=None)
Initializes the servo handler with the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
servo_pin
|
int
|
The GPIO pin for the servo motor. |
required |
frequency
|
int
|
The PWM frequency for the servo motor. |
PWM_FREQUENCY
|
min_pulse
|
int
|
The minimum pulse width in microseconds. |
MIN_PULSE
|
max_pulse
|
int
|
The maximum pulse width in microseconds. |
MAX_PULSE
|
actuation_range
|
int
|
The range of motion of the servo in degrees. |
ACTUATION_RANGE
|
movement
|
bool
|
If True, the servo will be controlled for movement; if False, it will not. |
True
|
debug
|
bool
|
If True, debug messages will be sent. |
False
|
serial_communication
|
SerialCommunication
|
An instance of SerialCommunication for sending debug messages. |
None
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
center()
async
Centers the servo motor to the middle position.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
165 166 167 168 169 |
|
is_turning()
Checks if the servo motor is currently turning.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the servo is not centered, False otherwise. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
205 206 207 208 209 210 211 212 |
|
left(angle)
async
Sets the servo motor to the left by a specified angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
int
|
Angle value to move the servo to the left, must be between 0 and left limit. |
required |
Raises:
Type | Description |
---|---|
ServoError
|
If the angle is not within the left limit. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
right(angle)
async
Sets the servo motor to the right by a specified angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
int
|
Angle value to move the servo to the right, must be between 0 and right limit. |
required |
Raises:
Type | Description |
---|---|
ServoError
|
If the angle is not within the right limit. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
set_angle(angle)
async
Sets the angle of the servo motor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
int
|
Angle value between 0 and the actuation range. |
required |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
set_angle_relative_to_center(relative_angle)
async
Sets the angle of the servo motor relative to the center position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_angle
|
int
|
Relative angle value between -90 and 90 degrees. |
required |
Raises:
Type | Description |
---|---|
ServoError
|
If the relative angle is not within the left and right limits. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\servo.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
switch
SwitchHandler
A class to handle a switch connected to a Raspberry Pi Pico.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\switch.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
__init__(serial_communication, switch_pin, led=None)
Initializes the switch handler with the specified pin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serial_communication
|
SerialCommunication
|
Serial communication handler. |
required |
switch_pin
|
int
|
The GPIO number where the switch is connected. |
required |
led
|
LEDHandler | None
|
Optional LED handler for visual feedback when the switch is pressed. |
None
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\switch.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
wait()
async
Waits for the switch to be pressed.
This method blocks until the switch is pressed (i.e., the pin reads LOW).
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\switch.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
utils
is_instance(obj, class_or_tuple)
Check if the object is an instance of the specified class or tuple of classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
The object to check. |
required |
class_or_tuple
|
Union[type, tuple[Any, ...]]
|
The class or tuple of classes to check against. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If the object is not an instance of the specified class or tuple of classes. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\utils.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
vl53l0x
VL53L0XError
Bases: Exception
Custom exception class for VL53L0X errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
__init__(message)
Initializes the VL53L0XError with a custom message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
13 14 15 16 17 18 |
|
__str__()
Returns a string representation of the VL53L0XError.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
20 21 22 23 24 |
|
VL53L0XHandler
This class handles the initialization and reading of multiple VL53L0X ToF sensors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
__init__(i2c, xshut_pins)
Initializes the VL53L0XHandler with default settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i2c
|
I2C
|
The I2C bus instance to communicate with the sensors. |
required |
xshut_pins
|
tuple
|
A tuple of GPIO pins used to control the XSHUT lines of the sensors. |
required |
Raises:
Type | Description |
---|---|
VL53L0XError
|
If there is an error initializing the sensors. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
multiple_tof_sensors_reading()
async
Asynchronously reads the distance from multiple VL53L0X ToF sensors.
Raises:
Type | Description |
---|---|
VL53L0XError
|
If there is an error reading from any sensor. |
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\vl53l0x.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
wifi
WifiError
Bases: Exception
Custom exception for Wi-Fi errors.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
__init__(message)
Initializes the WifiError with a custom message.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
15 16 17 18 19 20 |
|
__str__()
Returns a string representation of the WifiError.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
22 23 24 25 26 |
|
WifiHandler
A class to handle Wi-Fi connection and UDP socket operations.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
__del__()
Destructor to close the WI-FI connection and clean up resources.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
165 166 167 168 169 170 171 172 173 174 175 176 |
|
__init__(ssid=SSID, password=PASSWORD)
Initializes the WifiHandler with default values.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
close_udp_socket()
Close UDP socket.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
connect(attempts=ATTEMPTS)
async
Connect to WI-FI using credentials from environment variables.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
create_socket()
Create a socket pool for creating sockets.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
create_udp_socket()
Create UDP socket.
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
send_udp_message(message, target_ip=TARGET_IP, target_port=TARGET_PORT)
async
Send message over UDP
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message to send. |
required |
target_ip
|
str
|
The target IP address. |
TARGET_IP
|
target_port
|
int
|
The target port number. |
TARGET_PORT
|
Source code in devices\raspberry_pi_pico_2w\circuit_python\src\lib\wifi.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|