Skip to main content

Python module to control Upkie wheeled bipeds.

Project description

Upkie wheeled biped robot

CI Build instructions Documentation Coverage PyPI version Chat

Build instructions and software for Upkie wheeled bipeds. Develop on Linux 🐧 or macOS 🍏, deploy to the robot's Raspberry Pi 🍓. Questions about building and using an Upkie, or balancing robots in general, are welcome in the Discussions forum or on the Chat.

Quick sim

If you have Python and a C++ compiler (Ubuntu: sudo apt install curl g++ python3-dev), you can run an Upkie simulation right from the command line. It won't install anything on your machine, everything will run locally from the repository:

git clone https://github.com/tasts-robots/upkie.git
cd upkie
./start_wheel_balancer.sh

Connect a USB controller to move the robot around 🎮

Running a spine

The code of Upkie is organized into spines, which communicate with the simulation or mjbots actuators, and agents, the programs that implement robot behaviors. Check out this introduction for more details.

Simulation spine

In the example above we ran an agent called "wheel balancer". We could also start the simulation spine independently, and let it run waiting for agents to connect:

./start_simulation.sh

Robot spine

To run a spine on the robot, we first build it locally and upload it to the onboard Raspberry Pi:

make build
make upload ROBOT=your_upkie

Next, log into the Pi and run a pi3hat spine:

$ ssh user@your_upkie
user@your_upkie:~$ cd upkie
user@your_upkie:upkie$ make run_pi3hat_spine

Once the spine is running, you can run any agent in a separate shell on the robot, for example the wheel balancer:

user@robot:upkie$ make run_wheel_balancer

Running an agent

There are two ways we can develop and run agents: using the PyPI distribution, or Bazel. PyPI is better to get started and prototype everything in Python, while Bazel is better to recompile things from source.

PyPI

The PyPI distribution is the recommended way to control Upkie in Python. It is already fast enough for real-time control.

Installation

pip install upkie

Example

While running a spine, you can execute the following code in a Python interpreter or as a standalone Python script:

import gymnasium as gym
import upkie.envs

upkie.envs.register()

with gym.make("UpkieWheelsEnv-v4", frequency=200.0) as env:
    observation = env.reset()
    action = 0.0 * env.action_space.sample()
    for step in range(1_000_000):
        observation, reward, done, _ = env.step(action)
        if done:
            observation = env.reset()
        pitch = observation[0]
        action[0] = 10.0 * pitch

With a simulation spine, this code will reset the robot's state and execute the policy continuously. In a pi3hat spine, this code will control the robot directly.

Check out the examples/ directory for other examples.

Bazel

We use Bazel to build C++ spines that can run on both your host computer and the Raspberry Pi. Everything you see in the agents/ and spines/ directories is built with Bazel, including for instance the wheel balancer and the PPO balancer. Bazel builds everything locally, does not install anything on your system, and makes sure that all versions of all dependencies are correct. It is therefore better for sharing code with other Upkie's (no need to worry about what each user did or did not ``pip install`).

Use the following syntax to run an agent with Bazel:

./tools/bazelisk run -c opt //agents/wheel_balancer:agent

Here we added the -c opt to include optimization flags during compilation.

Code overview

Agents

Wheel balancer
A baseline agent designed to check out Upkie's physical capabilities. The robot balances with its wheels only, following PD feedback from the head pitch and wheel odometry to wheel velocities, plus a feedforward non-minimum phase trick for smoother transitions from standing to rolling.
Pink balancer
A more capable agent that combines wheeled balancing with inverse kinematics computed by Pink. This is the controller that runs in the first two videos of Upkie.
PPO balancer
An agent trained by reinforcement learning to balance with straight legs. Training uses the UpkieWheelsEnv gym environment and the PPO implementation from Stable Baselines3.

Environments

UpkieServosEnv
Upkie with full observation and joint position-velocity-torque actions.
UpkieWheelsEnv
Upkie with full observation but only wheel velocity actions.

Environments are single-threaded rather than vectorized. In return, they run as-is on the real robot.

Observers

Floor contact
Detect contact between the wheels and the floor. The pink and wheel balancers use contact as a reset flag for their integrators, to avoid over-spinning the wheels while the robot is in the air.
Wheel contact
Detect contact between a given wheel and the floor.
Wheel odometry
Measure the relative motion of the floating base with respect to the floor. Wheel odometry is part of their secondary task (after keeping the head straight), which is to stay around the same spot on the floor.

Spines

Bullet
Spawn Upkie in a Bullet simulation. Resetting this spine moves the robot back to its initial configuration in this world.
pi3hat
Spine is made to be called from a Raspberry Pi with an onboard mjbots pi3hat. Servos are stopped when the spine is stopped, and switch to position mode (which is a position-velocity-torque controller) when the spine idles. Check out the spine state machine for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

upkie-1.3.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

upkie-1.3.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file upkie-1.3.0.tar.gz.

File metadata

  • Download URL: upkie-1.3.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for upkie-1.3.0.tar.gz
Algorithm Hash digest
SHA256 111ed0226c45e0fa0e7cc9fa782020194f371217536bf5d5a905cafe409365e0
MD5 7617c78e7a0c447dbd0634724db462ec
BLAKE2b-256 4a9822b7ba784d7630dc4cc0cc3c9eed9523da882b78d926ce8718b88891bdb6

See more details on using hashes here.

File details

Details for the file upkie-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: upkie-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for upkie-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0785c922b544fd62abae056e2a81db41fbe81308895976efe45ae071315fae56
MD5 60c7cf25aa70ee5842bf8f18a8d0224d
BLAKE2b-256 da27512f5402496bfe84d531b9a176934984b140141c8bfb065cb32a1e23bb2e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page