Skip to content

About

High-level API to directly control the Clone Hand.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clone API client for the Clone Robot

Website | Code examples

The Clone client package offers high-level API to directly control the Clone Robot. Current repository version contains already built version of the package, development is done outside GitHub and for that reasons we do not accept pull requests, however we are open for any suggestions and bug reports using the issue tracking system.

⚠ Package In Development

This repository is in pre-beta, prone to drastic changes in the future, so please be aware of this. We will be slowly migrating development onto GitHub with the full introduction of releases and pull requests.

We use GitHub tagging mechanism for each update of the package for convenience.

Note: This README describes the API written in asyncio however the non-async version is also available as a almost drop-in replacement just by replacing clone_client.client with clone_client.sync.client. Every example and function can be used in both versions after few simple modifications (such as removing await and async keywords), with the exception of contructor call of sync Client which is missing server keyword argument (initialization only via address is available). The sync example is available in this file.

Depracation Warning With the sync version of a client being a native part of client core library the previous clone_client_sync package is now depracated and not maintained.

Requirements

Obviously you're gonna need the Clone Robot to use this package. Please contact us if you want to include our product in your research.

The package requires Python >= 3.10, < 4.0.

Installation

Unfortunately, we do not provide PyPI releases just yet, but you can use this repository as an installation candidate using pip:

https://pip.pypa.io/en/stable/cli/pip_install/#examples

Usage

Getting started

To start using this package with a version of the hardware, you're gonna need a unique name provided along with the Clone Robot..

from clone_client.client import Client

async def entrypoint():
    async with Client("robot") as client:
        ...

you can also use address in the network directly:

from clone_client.client import Client

async def entrypoint():
    async with Client(address="192.168.1.10") as client:
        ...

If you want more information about what is happening during initialization process (helpful for debugging) we recommend setting up logging module to INFO or DEBUG level.

Using controller

The controller is a simple communication interface that allows you to send commands to the robot. It mostly controls muscles and water pump (pressure source).

Note: For some versions of the robot the water pump might not be available due to external pressure source. In those cases the pump API would raise an exception.

from clone_client.client import Client

async def entrypoint():
    async with Client("robot") as client:
        # Start the waterpump and wait for it to reach desired pressure
        await client.start_waterpump()
        await client.wait_for_desired_pressure()

        # Send pressures instructions for each muscle
        data = [0 for _ in range(client.number_of_muscles)]
        await client.set_pressures(data)

set_pressures function accepts a sequence of floats and each value represents a normalized pressure instruction for a single muscle.

The value range is normalized to [0, 1]. To get information about what is the maxiumum pressure achievable for each muscle, you can use a following script:

async def entrypoint():
    async with Client("robot") as client:
        sinfo = await client.get_system_info()

        # e.g. checking the calibration range for the first muscle
        # Values are presented in milibars, negative values are
        # a normal feedback from the pressure sensor due to noise
        m_min = sinfo.calibration.pressure_sensors[0].min
        m_max = sinfo.calibration.pressure_sensors[0].max

        print(f"Muscle 0: min={m_min}, max={m_max}")

Setting the pressure is also achievable using stream. This offer the same functionality but in a bit more robust and more performant way due to limited numbers of request / response cycles.

async def entrypoint():
    async with Client("robot") as client:
        async def generator():
            pressures = [0] * client.number_of_muscles
            while 1:
                yield pressures

       await client.stream_set_pressures(generator())

See the stream example for more information about how to use the stream.

Note: We do not limit the control frequency internally, however there are hardware limitations that might prevent you from setting the pressure too fast.

Recommended control frequency for our development products can be calculated as:

  • hard cap: 10000 / (no_muscles * 1.5) (166Hz for Clone Hand)
  • soft cap: 10000 / (no_muscles * 1.25) (200Hz for Clone Hand)

We are aware of these limitations and are working on hardware changes to allow for much higher control frequency.

We offer a utility context manager that ensures very precise ticks, see: clone_client.utils:

from clone_client.client import Client
from clone_client.utils import async_precise_interval

async def entrypoint():
    async with Client("robot") as client:
        interval = async_precise_interval(1 / 100, precision=0.9)
        while True:
            await anext(interval)
            await client.set_pressures([0.2] * client.number_of_muscles)

Warning: We do not limit the number of concurrent muscle actuations. Setting pressures must be use with caution to ensure the safety of the hardware (to avoid too much tension / strains on the bone / joint). For initial experiments limit the number of actuated muscles or operate on lower values (such as 0.2 - 0.3).

On top of pressure controller the client implements a various way to control muscles such as timed impulses and oscilations. See the implementations for more information.

Reading feedback data

Clone Robot is equipped with a set of sensors that allow you to read current pressure in each muscle and the IMU data (beta). You can also check the current and desired (target) pressure of the water pump.

from clone_client.client import Client

async def entrypoint():
    async with Client("robot") as client:
        # Start the water pump and wait for it to reach desired pressure
        await client.start_waterpump()
        await client.wait_for_desired_pressure()

        # Get current information about water pump
        waterpump_info = await client.get_waterpump_info()

        # Whether or not water pump controller is running
        print("Is running", waterpump_info.is_running)

        # Current pressure in the water pump
        print("Current pressure", waterpump_info.pressure)

        # Desired pressure in the water pump
        print("Desired pressure", waterpump_info.desired_pressure)

        # Get current telemetry in the muscles
        telemetry = await client.get_telemetry()
        print("Pressurs ", telemetry.sensor_data.pressures)

Receiving feedback data is also available using subscription. This offer the same functionality but it's hooked directly into the internal feedback loop offering always up-to-date data.

from clone_client.client import Client

async def entrypoint():
    async with Client("robot") as client:
        async for telemetry in client.subscribe_telemetry():
            print("Pressures ", telemetry.sensor_data.pressures)

Example code can be found in the examples directory.

Data ordering

Both set_pressures (or stream_set_pressures) and get_pressures (or subscribe_telemetry) functions are based on the data in the same order as the muscles are connected to the controller. It is important to preserve the ordering of sent data to avoid any problems with the hardware or/and your own software.

To get the current order of the muscles, you can can use muscle_order property of the client.

We also provide utils to get the name of the specific muscle based on its index and vice versa.

from clone_client.client import Client

async def entrypoint():
    async with Client("robot") as client:
        # Get the muscle order
        muscle_order = client.muscle_order

        # Get the name of the muscle with index 0
        muscle_name = client.muscle_name(0)

        # Get the index of the muscle with name "muscle_0"
        muscle_index = client.muscle_index("muscle_0")

It is recommended to save the muscle order in your application and in case of any changes in the hardware you can verify whether or not the order is still the same to avoid potential problems in e.g. training a custom NN model.

Remapping

To facilitate reshuffling of both received and sent sequences of data, what can be useful in cases when same muscles are connected to control boards with different IDs or simply in different order, a Remapper class was added that can be found in remapper.py file.

async with Client("robot") as client:
    # Refresh system info, obtaining current mapping used by the golem
    await client.get_system_info()

    # Get ordering used by the golem
    remote_ordering = Remapper.swap_ordering(client.muscle_order)

    # Some operations changing the ordering, possibly saving it or reading a cached one
    # E.g. swapping two muscles:
    local_ordering = remote_ordering.copy()
    local_ordering["muscle0"], local_ordering["muscle1"] = (
        local_ordering["muscle1"],
        local_ordering["muscle0"],
    )

    # Create an instance of the Remapper
    remapper = Remapper(remote_ordering, local_ordering)

    # Subscribe for telemetry
    async for tele in client.subscribe_telemetry():

        # Convert a remote vector of pressures to local ordering
        pressures_local_ord = remapper.remote_to_local(tele.sensor_data.pressures)

        # Send a vector of pressures with local ordering to remote
        pressures_remote_ord = remapper.local_to_remote(pressures_local_ord)
        await client.set_pressures(pressures_remote)

Full example of the Remapper's usage you can find in this file. Note, that both local and remote orderings must contains same muscles' names and have same length.

API Reference

client

Please check the source code and examples for more information about the API. We try to provide detailed docstrings and typings for each function and class with comments in more complex parts of the code.

For all-in-one explanation please see this file

error_frames

clone_client.error_frames

Contains all errors that can occurr during the execution of any function of the Client related to networking. See docstrings for more information about when each error can occurr.

exceptions

clone_client.exceptions

Contains all exceptions that can occurr during the execution of any function of the Client. See docstrings for more information about when each exception can occurr.

Overall we try to keep typings and docstrings up to date so you can always check the source code for more information about the package.

Contributing

We are open for any suggestions and bug reports using issue system, however we do not accept pull requests at the moment.

In case of any problem please contact us at https://clonerobotics.com/contact.

About

High-level API to directly control the Clone Hand.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages