Robotics SDK

Drive your robot from the web, with plain Python.

Put a decorator on a Python function and it becomes a button, a slider or a joystick on cognira.dev. Link the robot to your account once, then drive it from any browser, anywhere. There are no ports to open and no app to build.

Three steps

  1. 01

    Install

    pip install cognira-robotics

  2. 02

    Decorate

    Put @robot.button, @robot.slider or @robot.joystick on the functions you already have.

  3. 03

    Run and approve

    The first robot.run() prints a code. Approve it on cognira.dev, and the robot appears under Robotics in the sidebar.

A whole rover

from cognira_robotics import Robot

robot = Robot("Rover")

@robot.joystick("Drive")
def drive(x, y):
    motors.set(left=y + x, right=y - x)

@robot.button("Horn", key="h")
def horn():
    buzzer.beep()

@robot.slider("Speed", min=0, max=100, unit="%")
def speed(value):
    motors.limit(value / 100)

@robot.on_stop
def stop():
    motors.stop()

@robot.every(2)
def report():
    robot.show("Battery", f"{battery.percent()}%")

robot.run()

Your controls appear on cognira.dev/robotics, each next to the function it runs. Values from robot.show() and lines from robot.log() stream back live. Each control can take a keyboard key, so key="w" lets you drive with WASD.

Controls

  • @robot.button → def fn()

    Runs once per press.

  • @robot.hold → def fn(pressed)

    True on press, False on release. Released for you if the connection drops.

  • @robot.toggle → def fn(on)

    An on/off switch.

  • @robot.slider → def fn(value)

    A slider, snapped to its step. Whole-number steps give you an int.

  • @robot.joystick → def fn(x, y)

    Each axis from −1 to 1. Centred for you if the connection drops.

  • @robot.text → def fn(text)

    A text box with a Send button.

Built to stop

  • Stop is always one key away. The red button and Esc run your @robot.on_stop function at once, even mid-command, and clear anything still queued.
  • A dead-man on held controls. If the browser goes quiet, joysticks centre and held buttons release on their own.
  • No stale commands. A press that arrives late is dropped instead of being replayed into a robot that has just reconnected.
  • Long tasks can be cut short. robot.sleep() wakes the moment Stop is pressed, so loops end cleanly.

Questions

What do I need to run the cognira Robotics SDK?
Python 3.8 or newer on the robot: a Raspberry Pi, a Jetson, a laptop wired to an Arduino, anything that runs Python. The SDK has no dependencies outside the standard library. Install it with pip install cognira-robotics.
Do I need to open ports or set up port forwarding?
No. The robot only makes outbound HTTPS requests to cognira, so it works behind home Wi-Fi, a school network or a phone hotspot.
What happens if my connection drops while the robot is moving?
Held buttons and joysticks are refreshed several times a second while you hold them. If the refreshes stop, the robot lets go after 1.5 seconds by default. Commands that could not be delivered in time are thrown away rather than replayed later, and the Stop button runs your stop function straight away.
Can I try it without an account?
Yes. robot.run(local=True) serves the same control panel from the robot itself at http://localhost:8700, with no sign-in.
How much does it cost?
Robotics is free on every cognira plan, including Free. Each account can link up to 25 robots.