Python API for controlling modular electronics, MODI.


Keywords
python, modi
License
MIT
Install
pip install pymodi==1.2.0

Documentation


Python Versions PyPI Release (latest by date) Read the Docs (version) GitHub Workflow Status (Build) Coveralls Coverage CodeFactor Grade GitHub LICENSE Lines of Code

Description

Python API for controlling modular electronics, MODI.

Promotion Video

PyMODI Intro Video

Features

PyMODI provides a control of modular electronics, MODI

  • Platform agnostic control of modules through serial connection
  • Explicit CAN communication to MODI modules via magnetic connector
  • Utilities of wireless connection with BLE (Bluetooth Low Engery)
  • Update of MODI firmware consisting of both ESP32 and STM32 modules
  • Direct manipulation of MODI network module using MODI Play

Build Status

master develop
GitHub Workflow Status GitHub Workflow Status

System Support

System 3.6 3.7 3.8
Linux GitHub Workflow Status (branch) GitHub Workflow Status (branch) GitHub Workflow Status (branch)
Mac OS GitHub Workflow Status (branch) GitHub Workflow Status (branch) GitHub Workflow Status (branch)
Windows GitHub Workflow Status (branch) GitHub Workflow Status (branch) GitHub Workflow Status (branch)

Contribution Guidelines

We appreciate all contributions. If you are planning to report bugs, please do so here. Feel free to fork our repository to your local environment, and please send us feedback by filing an issue.

If you want to contribute to pymodi, be sure to review the contribution guidelines. This project adheres to pymodi's code of conduct. By participating, you are expected to uphold this code.

Contributor Covenant

Installation

When installing PyMODI package, we highly recommend you to use Anaconda to manage the distribution. With Anaconda, you can use an isolated virtual environment, solely for PyMODI.

[Optional] Once you install Anaconda, then:

# Install new python environment for PyMODI package, choose python version >= 3.6
conda create --name pymodi python=3.6

# After you properly install the python environment, activate it
conda activate pymodi

# Ensure that your python version is compatible with PyMODI
python --version

Install the latest PyMODI if you haven't installed it yet:

python -m pip install pymodi --user --upgrade

You can also install PyMODI at develop branch (containing latest changes but it can be unstable) with:

python -m pip install git+https://github.com/LUXROBO/pymodi.git@develop --user --upgrade

Alternatively, you can install a stable copy of PyMODI at a tag (representing a previous release) with:

python -m pip install git+https://github.com/LUXROBO/pymodi.git@v1.0.0 --user --upgrade

Usage

Import modi package and create MODI object (we call it "bundle", a bundle of MODI modules).

# Import modi package
import modi

"""
Create MODI object, make sure that you have connected your network module
to your machine while other modules are attached to the network module
"""
bundle = modi.MODI()

[Optional] Specify how you would like to establish the connection between your machine and the network module.

# 1. Serial connection (via USB), it's the default connection method
bundle = modi.MODI(conn_type="ser")

# 2. CAN connection (via CAN shield, not recommended to use it directly)
bundle = modi.MODI(conn_type="can")

# 3. BLE (Bluetooth Low Energy) connection, it's wireless! But it can be slow :(
bundle = modi.MODI(conn_type="ble", network_uuid="YOUR_NETWORK_MODULE_UUID")

List and create connected modules' object.

# List connected modules
print(bundle.modules)

# List connected leds
print(bundle.leds)

# Pick the first led object from the bundle
led = bundle.leds[0]

Visualize how modules are connected.

# Print topology map without indicating module id
bundle.print_topology_map()

# Print topology map with module id printed
bundle.print_topology_map(print_id=True)

Let's blink the LED 5 times.

import time

for _ in range(5):
    # turn on for 0.5 second
    led.turn_on()
    time.sleep(0.5)

    # turn off for 0.5 second
    led.turn_off()
    time.sleep(0.5)

If you are still not sure how to use PyMODI, you can play PyMODI tutorial over REPL:

$ python -m modi --tutorial

As well as an interactive usage examples:

$ python -m modi --usage

Moreover, we provide api documentation, usage and creation examples, and a descriptive web page.

Additional Usage

To update MODI network module (the network module must be connected on serial),

$ python -m modi --update_network

To update MODI network module's base (as above, the network module must be connected on serial),

$ python -m modi --update_network_base

To update MODI modules (all modules but the network module),

$ python -m modi --update_modules

To diagnose MODI modules (helpful to find existing malfunctioning modules),

$ python -m modi --inspect

To debug MODI modules with PyMODI debugger,

$ python -m modi --debug

To check the performance of PyMODI on your machine,

$ python -m modi --performance

To initialize MODI modules implicitly (set i flag to enable REPL mode),

$ python -im modi --initialize

To see what other commands are available,

$ python -m modi --help

Sponsored by

Ministry of SMEs and StartUps