Bittle()
High level class that represents your Bittle.
Attributes
id (UUID): Bittle's unique id.
bluetoothManager (BluetoothManager): Manager for sending messages to Bittle through Bluetooth.
wifiManager (WifiManager): Manager for sending messages to Bittle through WiFi.
serialManager (SerialManager): Manager for sending messages to Bittle through Serial communication.
gait (Gait): Current gait (WALK by default); used to send movement commands.
commands ({Command : str}): Map with avaliable commands and its Serial translation.
Methods
connect_bluetooth(get_first_bittle=True): Connects to Bittle through Bluetooth connection. Returns True if connected, False otherwise. If get_first_bittle is enabled, searchs for BitleSPP among paired devices and connect to it.
send_command_bluetooth(command): Sends a command to Bittle through Bluetooth connection.
send_msg_bluetooth(message): Sends a custom message to Bittle through Bluetooth connection.
receive_msg_bluetooth(buffer_size=1014): Returns received message from Bittle through Bluetooth connection (bytes).
disconnect_bluetooth(): Closes Bluetooth connection with Bittle.
has_wifi_connection(): Checks wether there is connection with REST API. Returns True if there is connection, False otherwise.
send_command_wifi(command): Sends a command to Bittle through WiFi connection. Returns REST API response code (int), -1 if there is no connection.
send_msg_wifi(message): Sends a custom message to Bittle through WiFi connection. Returns REST API response code (int), -1 if there is no connection.
send_movement_bluetooth(direction): Sends a movement command to Bittle through Bluetooth connection. This method sends current gait plus direction, only WALK gait is avaliable for backward directions.
send_movement_wifi(direction): Sends a movement command to Bittle through WiFi connection. This method sends current gait plus direction, only WALK gait is avaliable for backward directions.
connect_serial(discover_port=True): Connects to Bittle through Serial. Return True if connected, False otherwise. If discover_port is enabled, search among avaliable communication ports the one associated to CH340 USB driver, which is used by Bittle and connect to it.
send_command_serial(command): Sends a command to Bittle through Serial connection.
send_msg_serial(message): Sends a custom message to Bittle through Serial connection.
receive_msg_serial(buffer_size): Returns received message from Bittle through Serial connection (bytes).
send_movement_serial(direction): Sends a movement command to Bittle through Serial connection. Thid method sends current gait plus direction, only WALK gait is avaliable for backward directions.
disconnect_serial(): Closes Serial connection with Bittle.
Examples
The following example shows the complete process of creating a Bittle instance and communicating with it through Bluetooth. If connection is successful, send GREETING and REST commands to check whether Bittle receives and replies to them:
The following example shows the complete process of creating a Bittle instance and communicating with it through WiFi. If connection is successful, send GREETING and REST commands to check whether Bittle receives and replies to them:
The following example shows the complete process of creating a Bittle instance and communicating with it through Serial. If connection is successful, send GREETING and REST commands to check wether Bittle receives and replies to them:
Last updated