sbhs_robomaster

SBHS RoboMaster API

A Python library for controlling the RoboMaster EP Core robot.

Installation

pip install sbhs-robomaster

Pre-requisite knowledge

This library heavily relies on async code.

A good tutorial on async code is at https://superfastpython.com/python-asyncio/ and the documentation is at https://docs.python.org/3/library/asyncio.html.

Usage

Look at How To for examples of common operations. Also look at sbhs_robomaster.client.RoboMasterClient for a list of available methods on the robot.

How To

Connect to the robot

import asyncio
from sbhs_robomaster import connect_to_robomaster, DIRECT_CONNECT_IP

async def main():
    async with await connect_to_robomaster(DIRECT_CONNECT_IP) as robot:
        # Do stuff with the robot
        pass

asyncio.run(main())

Move the robot

import asyncio
from sbhs_robomaster import connect_to_robomaster, DIRECT_CONNECT_IP

async def main():
    async with await connect_to_robomaster(DIRECT_CONNECT_IP) as robot:
        # Rotate the robot 90° clockwise
        await robot.rotate(90)

        # Rotate all wheels indefinitely at 50rpm
        await robot.set_all_wheel_speeds(50)
        await asyncio.sleep(5)

        # Stop the robot
        await robot.set_all_wheel_speeds(0)

        # Get the left wheels to rotate at 50rpm and the right wheels at 20
        await robot.set_left_right_wheel_speeds(50, 20)
        await asyncio.sleep(5)

        await robot.set_all_wheel_speeds(0)

asyncio.run(main())

Move the arm

import asyncio
from sbhs_robomaster import connect_to_robomaster, DIRECT_CONNECT_IP

async def main():
    async with await connect_to_robomaster(DIRECT_CONNECT_IP) as robot:
        # Move the arm to the position (79, 150). Each robot has its coordinates
        # relative to a different origin, so you will have to find the coordinates
        # for your robot yourself. (Using `robot.get_arm_position`)
        await robot.set_arm_position(79, 150)

        # Move the arm 10 units in the x direction and 10 units in the y direction.
        await robot.move_arm(10, 10)

        # Using `move_arm` is the same as:
        x, y = await robot.get_arm_position()
        await robot.set_arm_position(x + 10, y + 10)

asyncio.run(main())

Get line information

import asyncio
from sbhs_robomaster import connect_to_robomaster, DIRECT_CONNECT_IP, LineColour

async def main():
    async with await connect_to_robomaster(DIRECT_CONNECT_IP) as robot:
        await robot.set_line_recognition_enabled()
        await robot.set_line_recognition_colour(LineColour.Red)

        while True:
            print(await robot.line.get())

asyncio.run(main())

Also look at sbhs_robomaster.feed.Feed for more explanation and help.

Get IR information

import asyncio
from sbhs_robomaster import connect_to_robomaster, DIRECT_CONNECT_IP

async def main():
    async with await connect_to_robomaster(DIRECT_CONNECT_IP) as robot:
        await robot.set_ir_enabled()

        # Get the distance from the IR sensor 1
        print(await robot.get_ir_distance(1))

asyncio.run(main())

FAQ

Why the weird name?

Every other name related to the RoboMaster EP Core has been taken by now. 💀

What is the RoboMaster EP Core?

Check out the info page.

How do I do [x]?

Look at the How To section.

Can I see the official documentation?

The official documentation is a bit of a mess and the official sdk is both a mess and uses an undocumented binary api. But if you want to see it, you can find the official documentation here and the official sdk here.

Where's the source code for this?

Here.

 1"""
 2# SBHS RoboMaster API
 3A Python library for controlling the RoboMaster EP Core robot.
 4
 5## Installation
 6```sh
 7pip install sbhs-robomaster
 8```
 9
10## Pre-requisite knowledge
11This library heavily relies on async code.
12
13A good tutorial on async code is at [https://superfastpython.com/python-asyncio/](https://superfastpython.com/python-asyncio/)
14and the documentation is at [https://docs.python.org/3/library/asyncio.html](https://docs.python.org/3/library/asyncio.html).
15
16## Usage
17Look at How To for examples of common operations.
18Also look at `.client.RoboMasterClient` for a list of available methods on the robot.
19
20.. include:: ../../md_docs/how_to.md
21
22.. include:: ../../md_docs/faq.md
23"""
24
25from .client import *
26from .data import *
27from .feed import *