A pack of two simulation environments for robot SK8O developed at FEE CTU in Prague.
Project description
This folder contains two ways to simulate SK8O in Python:
- a linear approximation of a Segway ~ SK8O with fixed legs in
sk8o_sim/segway, - a non-linear simulation of SK8O using MuJoCo ("full model") in
sk8o_sim/full.
This project targets Python 3.11, though it was originally written for Python 3.9, which may affect some parts of the codebase (particularly the typing annotations). The necessary packages can be installed using the standard requirements.txt file e.g. by
pip install -r sk8o_sim/requirements.txt
For more information, check my diploma thesis.
Segway
Files in sk8o_sim/segway contain the linear approximation of a Segway that was used to train RL models and to tune the LQR. It is highly configurable, can generate randomized models, simulate motor quantization and can be rendered via pygame. Note that by default, the measurement and process noise can be quite severe (in addition to initial conditions not necessarily too close to the equilibrium), so even the LQR that works just fine on SK8O may sometimes fail to stabilize the robot.
What it does not support is any way to end the simulation due to the robot falling - it is up to you to decide when the approximation is no longer valid!
Main components
The building block of the simulation is the SegwaySimData dataclass found in sk8o_sim/segway/data.py. It contains all the simulation data and some helper functions. In sk8o_sim/segway/simulation.py, you can find how the simulation is performed and view.py is in charge of the rendering.
Demo
A very crude simulation of an LQR stabilization with "slow-mo" rendering can be run using the following code:
import time
import numpy as np
from sk8o_sim import (
SegwayLQRController,
SegwayLQRControllerCfg,
SegwaySimulation,
SegwaySimulationCfg,
)
# initialize everything
sim = SegwaySimulation(SegwaySimulationCfg())
data = sim.reset()
controller = SegwayLQRController(SegwayLQRControllerCfg())
# run the simulation
sim_time = 10 # [s]
for k in range(sim_time * controller.control_frequency):
action = controller(data)
data = sim.run(action, 1 / controller.control_frequency)
sim.render()
time.sleep(0.5)
Note that the FPS will likely be unstable in this example. For a more advanced interaction, check out the interactive_segway.py file.
Full model
The full model is implemented in MuJoCo and can be found in sk8o_sim/full. The mujoco-python-viewer package is used for rendering.
If you've familiarized yourself with the Segway simulation, this one should hopefully feel similar. Again, you will mostly work with what's contained in the simulation.py -- this time the class is FullSimulation and will generate FullSimulationData objects found in data.py. This class is essentially a wrapper around MuJoCo that also computes the equivalent Segway states for easier control.
One (admittedly experimental) trick of this simulation is the option to "lock" SK8O's hips/legs (see the (un)lock_hips methods) for testing.
Controllers
The controllers can be found in sk8o_sim/controllers.py and include SegwayLQRController to control the wheels as per Adam's thesis and a simple PID hip controller, SK8OHipController. Both implement the SK8OController interface and are combined in the SK8OFullController class which controls both. You can use this class if you wish to implement control only for the wheels for example by likewise implementing the simple interface and overwriting the wheel_controller argument in SK8OFullController.
Configuration
The project is ready for OmegaConfhydra: the configs.py file contains all the configuration that is available for the simulation, rendering and controllers. This allows you to control everything via custom YAML configs and/or command-line arguments with a little bit of work. This should also make logging the configuration easy. If you experiment with many versions of a new controller, you can leverage this to easily compare the changes you've made using e.g. Weights & Biases or similar software. To see a sample, see the config_demo.py file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sk8o_sim-0.0.2.tar.gz.
File metadata
- Download URL: sk8o_sim-0.0.2.tar.gz
- Upload date:
- Size: 13.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df01328533b5b43ef68b5b3b78c9ba75547eeaf015511358de7db008b88aeefe
|
|
| MD5 |
f7788286e26adc7a669724f350cdca83
|
|
| BLAKE2b-256 |
58c537f1527527f2d0cb43ac0106ed0e08af961382eb6d016e4018480f49151b
|
File details
Details for the file sk8o_sim-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sk8o_sim-0.0.2-py3-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b82e8936ca349ebe8050bad9cd21f1ed58338678d2514850d2d993bbb79dc20d
|
|
| MD5 |
7b05beed29d12b4fe39b948b8a3e79a9
|
|
| BLAKE2b-256 |
7a57b4870c74de0f633f7e497dbbf2d6d6b96e52575cfa082207873db1c837f6
|