Skip to content

Examples

All examples include two variants for serial, and MQTT. Source code can be found here

For more information, see Serial vs. MQTT

Core

Robot Connection

examples/core/connecting_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

while True:
    time.sleep(1)
examples/core/connecting.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect("kevinbot", "localhost", 1883)

while True:
    time.sleep(1)

Robot Enabling and Disabling

examples/core/enable_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

robot.request_enable()  # Ask the core to enable
while not robot.get_state().enabled:  # Wait until the core is enabled
    time.sleep(0.01)

time.sleep(3)

robot.request_disable()  # Ask the core to disable
while robot.get_state().enabled:  # Wait until the core is disabled
    time.sleep(0.01)

time.sleep(3)  # Let the user see that the robot is disabled before disconnecting
examples/core/enable.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect()

robot.request_enable()  # Ask the core to enable
while not robot.get_state().enabled:  # Wait until the core is enabled
    time.sleep(0.01)

time.sleep(3)

robot.request_disable()  # Ask the core to disable
while robot.get_state().enabled:  # Wait until the core is disabled
    time.sleep(0.01)

time.sleep(3)  # Let the user see that the robot is disabled before disconnecting

Robot Emergency Stop

examples/core/estop_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

robot.e_stop()
examples/core/estop.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect()

robot.e_stop()

Robot State Retrieval

examples/core/state_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

while True:
    print(robot.get_state())  # noqa: T201
    time.sleep(1)
examples/core/state.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect()

while True:
    print(robot.get_state())  # noqa: T201
    time.sleep(1)

Robot Uptime Retrieval

examples/core/uptimes_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

while True:
    print(f"Uptime (s) : {robot.get_state().uptime}")  # noqa: T201
    print(f"Uptime (ms): {robot.get_state().uptime_ms}")  # noqa: T201
    time.sleep(1)
examples/core/uptimes.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect()

while True:
    print(f"Uptime (s) : {robot.get_state().uptime}")  # noqa: T201
    print(f"Uptime (ms): {robot.get_state().uptime_ms}")  # noqa: T201
    time.sleep(1)

Battery

Robot Battery Readings

examples/battery/readings_serial.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import SerialKevinbot

robot = SerialKevinbot()
robot.connect("/dev/ttyAMA2", 921600, 5, 1)

time.sleep(3)  # Wait to get data

print(f"Voltages: {robot.get_state().battery.voltages}")  # noqa: T201
print(f"Raw Voltages: {robot.get_state().battery.raw_voltages}")  # noqa: T201
print(f"States: {robot.get_state().battery.states}")  # noqa: T201
examples/battery/readings.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# SPDX-FileCopyrightText: 2024-present Kevin Ahr <meowmeowahr@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import time

from kevinbotlib import MqttKevinbot

robot = MqttKevinbot()
robot.connect()

time.sleep(3)  # Wait to get data

print(f"Voltages: {robot.get_state().battery.voltages}")  # noqa: T201
print(f"Raw Voltages: {robot.get_state().battery.raw_voltages}")  # noqa: T201
print(f"States: {robot.get_state().battery.states}")  # noqa: T201