Skip to main content

BotballKit

An object-oriented wrapper for the KIPR library

Why

The KIPR library is bad in many ways. First of all, it's not even a real Python library, it's just a rushed implementation of its C library.

This is how you import it:

kipr = ctypes.CDLL('/usr/lib/libkipr.so')

Okay, so it's technically not a pure Python library, but it still looks like one, right?

kipr = ctypes.CDLL('/usr/lib/libkipr.so')

status = kipr.digital(0)
print(status)

kipr.motor(0, 100)
kipr.motor(1, 100)
kipr.msleep(2000)

No. This looks like a C library, because that's all it is. It's barely object-oriented and the names of the functions are inconsistent and not Pythonic.

The Solution

The solution to this is a nice, object-oriented wrapper for the official KIPR library. Here's an example that sees if a push sensor is being pressed.

from BotballKit import Bot, Sensor, SensorType

bot = Bot()
sensor = Sensor(bot, SensorType.DIGITAL, 0)
left_motor = Motor(bot, 0)
right_motor = Motor(bot, 1)

status = sensor.status()
print(status)

left_motor.move_async(100, 2)
right_motor.move(100, 2)

Much better, right? You create a bot object, a sensor object, two motor objects for each wheel, then you simply get the status of the sensor and print it and move the bot forward for two seconds.

But It's Longer

While in this example the code is longer than the same example with the official library, as you keep adding on to this program the code will be shorter.

Also having an object-oriented library with much more consistent method names can make it easier to remember and harder to make mistakes.

Documentation

Creating a Bot

The first step to using this library is to create a Bot object. Doing that is as simple as:

from BotballKit import Bot

bot = Bot()

Now we have a Bot object stored in the bot variable.

The Bot constructor can optionally take these parameters:

  • wait_for_port: Optional[int] = None: Waits for a sensor on the specified port to be True before starting anything else. This will block the thread until the condition is met.

  • time_limit: Optional[float] = None: Stops the program after the specified number of seconds.

Bot objects also have these methods:

  • Bot.stop_all_motors(): Stops all motors associated with the bot.

  • Bot.enable_all_servos(): Enables all servos associated with the bot.

  • Bot.disable_all_servos(): Disables all servos associated with the bot.

Sensors

Creating Sensor objects is also very simple:

from BotballKit import Sensor, SensorType

sensor = Sensor(bot, SensorType.DIGITAL, 0)

The Sensor constructor must have these parameters:

  • bot: Bot: Your bot object.

  • type: SensorType: The type of sensor you want to use. The two options are SensorType.DIGITAL and SensorType.ANALOG.

  • port: int: The port your sensor is physically connected to.

It has this method available:

  • Sensor.status() -> Union[bool, int]: Gets the status of the sensor. If the sensor is digital, it will return a bool. If the sensor is analog, it will return an int.

Motors

To create a Motor, all you have to do is:

from BotballKit import Motor

motor = Motor(bot, 0)

The Motor constructor requires these parameters be passed:

  • bot: Bot: Your bot object.

  • port: int: The port your motor is physically connected to.

They have these methods available:

  • Motor.stop(): Stops the motor.

  • Motor.move(power: int, seconds: float): Moves the motor with the specified power between -100 and 100 for the specified amount of seconds.

  • Motor.move_async(power: int, seconds: float): Does the same thing as the Motor.move method except it runs asynchronously.

Servos

Creating servos is also easy:

from BotballKit import Servo

servo = Servo(bot, 0)
servo.enable()

All servos need to be enabled to work. This can be done with the Servo.enable method or the Bot.enable_all_servos method.

Its constructor takes the following parameters:

  • Servo.enable(default_position: Optional[int] = None): Enables the servo. If the default_position parameter is specified, the servo will be set to that position when enabled.

  • Servo.disable(default_position: Optional[int] = None): Disables the servo. If the default_position parameter is specified, the servo will be set to that position when disabled.

  • Servo.is_enabled() -> bool: Returns whether the servo is enabled or not.

  • Servo.toggle(default_position: Optional[int] = None): Toggles the servo. If the default_position parameter is specified, the servo will be set to that position when toggled.

  • Servo.position(position: Optional[int] = None) -> Optional[int]: Gets or sets the position of the servo. If no parameters are specified, it will return the current position as an int. If the position parameter is specified, it will set the servo position to that value and return None.

Release files for BotballKit 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BotballKit 1.0
File Size Uploaded
BotballKit-1.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BotballKit 1.0
File Interpreter ABI Platform
BotballKit-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / BotballKit-1.0.tar.gz

Download URL BotballKit-1.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e0df593a088883c539995ef755f0ccee2154252d589b4aae5f0fc6d5fc23fb92
BLAKE2b-256 checksum
How to use checksums
10a38ade167158e92004d868ab4bacc858e941b475f5f3b33d4201a9f53779ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release files / BotballKit-1.0-py3-none-any.whl

Download URL BotballKit-1.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4eebddcd66e8b6f90c5359dfc74121682c7d6ccf483915a5c93702453823aed
BLAKE2b-256 checksum
How to use checksums
5a4454c5a36e9d5ccefebb02cb3de68bec335659137355de8207d93a5e20b3fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page