Skip to content

Commit

Permalink
add simplectrlloop example; improve docs; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
justagist committed Aug 7, 2024
1 parent 8c78173 commit f78cf2b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 14 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## [0.0.3] - 2024-08-08
## [0.0.4] - 2024-08-08

### Adds

- Example on using SimpleManagedCtrlLoop and core components
- Improve docs and Readme

## [0.0.3]

### Adds

Expand All @@ -11,7 +18,7 @@
- Pypi installation issues
- mutable defaults in dataclass fields

## [0.0.1] - 2024-08-08
## [0.0.1]

### Adds

Expand Down
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# pyrcf

**WORK IN PROGRESS. NOT READY FOR USE.**
[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/downloads/)
[![GitHub release](https://img.shields.io/github/release/justagist/pyrcf.svg)](https://github.com/justagist/pyrcf/releases/)
[![License](https://img.shields.io/pypi/l/bencher)](https://opensource.org/license/mit/)

A Python Robot Control Framework for quickly prototyping control algorithms for different robot embodiments.

Expand All @@ -10,22 +12,46 @@ controllers and planners.

In the long run, this package will also provide implementations of popular motion planners and controllers from literature and using existing libraries.

> [!WARNING]
> **THIS PROJECT IS STILL IN ACTIVE DEVELOPMENT.**
## Continuous Integration Status

[![Ci](https://github.com/justagist/pyrcf/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/justagist/pyrcf/actions/workflows/ci.yml?query=branch%3Amain)
[![Codecov](https://codecov.io/gh/justagist/pyrcf/branch/main/graph/badge.svg?token=Y212GW1PG6)](https://codecov.io/gh/justagist/pyrcf)
[![GitHub issues](https://img.shields.io/github/issues/justagist/pyrcf.svg)](https://github.com/justagist/pyrcf/issues/)
[![GitHub pull-requests merged](https://badgen.net/github/merged-prs/justagist/pyrcf)](https://github.com/justagist/pyrcf/pulls?q=is%3Amerged)
<!-- [![GitHub release](https://img.shields.io/github/release/justagist/pyrcf.svg)](https://github.com/justagist/pyrcf/releases/) -->
[![License](https://img.shields.io/pypi/l/bencher)](https://opensource.org/license/mit/)
[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11-blue)](https://www.python.org/downloads/)
[![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)

## Installation

### From pypi

[![PyPI version](https://badge.fury.io/py/pyrcf.svg)](https://badge.fury.io/py/pyrcf)

- `pip install pyrcf`

### From source

- Clone repo and run from inside the directory `pip install .` (recommended to use virtual env) or run `pixi install` (if using [Pixi](https://pixi.sh)).

### Testing Installation

After installation, you should be able to run a robot visualiser script installed globally called `pyrcf-visualise-robot`. Run it with the first
argument as any of the robot descriptions mentioned in the [robot_descriptions.py repo](https://github.com/robot-descriptions/robot_descriptions.py/tree/main?tab=readme-ov-file#descriptions); e.g. `pyrcf-visualise-robot pepper_description`. This should
start a visualiser in pybullet, where you should be able to move all robot joints and base pose using sliders in the pybullet GUI.

You should also be able to run all the scripts in the `examples` folder.

**More examples and demos will be added soon.**

## PyRCF Philosophy

PyRCF follows the principle of a single thread control loop where components are communicating with each other strictly using pre-defined message types,
and run sequentially.

PyRCF is designed to be a prototyping tool to test different controllers and algorithms in simulation, and **NOT** optimised for real-time control on a real
robot. Although the framework has been tested on real robot interfaces, it is not recommended to do so unless you know what you are doing.

### A generic control loop

```text
Expand Down Expand Up @@ -59,11 +85,13 @@ END LOOP
This package provides interfaces to define custom components (such as controller, robot interface, global planner,
local planner, etc) that can be run in a control loop, as well as provides an implementation of a control loop
class which can execute these components in the required order at the specified rate. Implementations of simple
forms of all components are available in this package, including simulated interfaces for many robot embodiments.
forms of all components are also available in this package, including simulated interfaces for many robot embodiments.

Custom controllers and planners can be implemented and quickly tested on existing robot interfaces or on custom
robot interfaces (which can be easily defined).

More complex algorithms for control and planning will be provided by this package over time.

Tutorials and more details about concepts will be provided soon in the [tutorials](examples/tutorials) folder.

[![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
11 changes: 8 additions & 3 deletions examples/tutorials/01_basic_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
- GlobalMotionPlannerBase
See README.md to know exactly what each of these components do in the context of the PyRCF
framework.
framework. Also see the docs in the base classes to understand the mandatory functions to
be overridden when implementing these components (also see additional functions that can
be overridden if required).
This demo also demosntrates the contract between each components in the control loop.
This demo also demonstrates the contract between each components in the control loop.
Components are called in sequence in the control loop (no parallelisation -- see README
in this folder (examples/tutorials/README.md)).
Expand Down Expand Up @@ -40,7 +42,10 @@
from pyrcf.components.robot_interfaces import DummyRobot, RobotInterface
from pyrcf.components.global_planners.ui_reference_generators import DummyUI

# pylint: disable=W0621
# pylint: disable=W0621, W0105

"""NOTE: Read the docs in the __main__ below before going through the implementation
of DummyCtrlLoop."""


class DummyCtrlLoop:
Expand Down
64 changes: 64 additions & 0 deletions examples/tutorials/02_managed_ctrl_loop_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""This demo does (almost) exactly the same thing as the previous example (01), but
uses the SimpleManagedCtrlLoop that is provided by PyRCF.
This is a dummy control loop where each component simply prints something to the screen.
"""

from pyrcf.components.robot_interfaces import DummyRobot
from pyrcf.components.agents import PlannerControllerAgent
from pyrcf.components.state_estimators import DummyStateEstimator
from pyrcf.components.controller_manager import SimpleControllerManager
from pyrcf.components.global_planners.ui_reference_generators import DummyUI
from pyrcf.components.controllers import DummyController
from pyrcf.components.local_planners import DummyLocalPlanner
from pyrcf.control_loop import SimpleManagedCtrlLoop

if __name__ == "__main__":
# Load the same components as in the previous example.
# All these components simply prints stuff out, but they have implemented the required
# methods as required by their respective base classes, and hence can be used in the
# control loop.
robot = DummyRobot()
state_estimator = DummyStateEstimator()
controller = DummyController()
local_planner = DummyLocalPlanner()
global_planner = DummyUI()

# create a controller manager to manage the controllers in the control loop. This is to
# deal with cases where there are multiple controllers in the control loop. In our case
# we don't necessarily need it, but this is required for creating the ControlLoop object.
controller_manager = SimpleControllerManager()

# the simple controller manager manages different 'agents'. In our case, our 'agent' is
# just the local [planner and controller], so we use the PlannerControllerAgent implementation
# of AgentBase class. This could be any control policy that can take a global plan message
# and directly produce a control output to the robot without needing an intermediate local
# planner (e.g. a machine-learned control policy (in which case you could look at the
# MLAgentBase abstract class which is also derived from AgentBase)).
agent = PlannerControllerAgent(local_planner=local_planner, controller=controller)

# add this agent to the controller manager to handle its run in the control loop.
controller_manager.add_agent(agent=agent)
# NOTE: This could have been done during initialisation of the `SimpleControllerManager` object
# by passing the list of agents to be used as an argument to the constructor. See doc in class
# `SimpleControllerManager`.

# create a control loop with these components.
# The SimpleManagedCtrlLoop allows loading the different components and runs them at the
# required rate. It also handles proper loading and shutting down of components, as well
# as can provide some debugging and data logging capabilities.
control_loop = SimpleManagedCtrlLoop(
robot_interface=robot,
state_estimator=state_estimator,
controller_manager=controller_manager,
global_planner=global_planner,
)

ctrl_loop_rate: float = 2 # 2hz control loop as an example

# This will load the components in order (see log messages in terminal) and run them in sequence.
control_loop.run(loop_rate=ctrl_loop_rate)

# Sending a CtrlLoopExit signal (e.g. using KeyboardInterrupt) will close the control loop
# cleanly (i.e. by shutting down each component cleanly. See log messages showing the shutdown
# sequence.)
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyrcf"
version = "0.0.3"
version = "0.0.4"
authors = [{ name = "Saif Sidhik", email = "[email protected]" }]
description = "A Python Robot Control Framework for quickly prototyping control algorithms for different robot embodiments."
readme = "README.md"
Expand Down

0 comments on commit f78cf2b

Please sign in to comment.