Skip to main content

pymoos2

pymoos2

Write MOOS-IvP applications in Python. pymoos2 speaks the native MOOSDB protocol, so Python apps run beside C++ apps under pAntler, appcast to uMAC and pMarineViewer, and read the same .moos mission files.

pip install pymoos2

Python 3.8 or newer.

A first app

from pymoos2 import AppCastingMOOSApp, ACTable, run


class Doubler(AppCastingMOOSApp):

    def on_startup(self):
        self.gain = self.config("gain", default=2.0, type=float)
        self.nav_x = 0.0

    def register_variables(self):
        self.register("NAV_X")

    def on_new_mail(self, mail):
        for msg in mail:
            if msg.name == "NAV_X":
                self.nav_x = msg.double()

    def iterate(self):
        self.notify("NAV_X_SCALED", self.nav_x * self.gain)

    def build_report(self):
        table = ACTable(["Variable", "Value"])
        table.add("NAV_X", f"{self.nav_x:.2f}")
        self.report(table)
        return True


if __name__ == "__main__":
    import sys
    run(Doubler, "pDoubler", sys.argv[1])
ProcessConfig = pDoubler
{
  AppTick   = 4
  CommsTick = 4
  gain      = 3
}

Building in a moos-ivp tree

Python apps live in src/ beside the C++ apps and build with the tree's ./build.sh. Add this once to the top-level CMakeLists.txt, next to find_package(MOOS) (python3 -m pymoos2 --cmake-block prints it):

#=======================================================================
# Find pymoos2 (Python MOOS apps)
#   Python: -DPYMOOS2_PYTHON, the active venv, ../venv, or python3 on PATH
#=======================================================================
find_program(PYMOOS2_PYTHON NAMES python3 python
             HINTS ENV VIRTUAL_ENV "${CMAKE_SOURCE_DIR}/../venv" PATH_SUFFIXES bin)
execute_process(COMMAND "${PYMOOS2_PYTHON}" -m pymoos2 --cmake-dir
                OUTPUT_VARIABLE PyMOOS2_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
find_package(PyMOOS2 QUIET)
if(NOT PyMOOS2_FOUND)
  message(WARNING "pymoos2 is not importable with ${PYMOOS2_PYTHON} - Python apps will not be built. "
                  "pip install pymoos2 there, or configure with -DPYMOOS2_PYTHON=<python>.")
  unset(PYMOOS2_PYTHON CACHE)
  function(pymoos2_add_script_app)
  endfunction()
  function(pymoos2_add_package_app)
  endfunction()
endif()

Then generate apps in src/ and add them with ADD_SUBDIRECTORY:

python3 -m pymoos2 --GenAppCastingMOOSApp Foo p "Your Name"   # script app
python3 -m pymoos2 --GenPackageApp Bar p "Your Name"           # package app

Each app's CMakeLists.txt is one call:

pymoos2_add_package_app(NAME pBar PACKAGE pbar)

cmake --install build --prefix <dir> installs the apps; the prefix can be moved afterwards.

From the root of a tree, python3 -m pymoos2 --example adds three example apps and a mission that runs them.

Geodesy

Most IvP helm behaviors use local SI coordinates: meters east and north of the mission origin. pymoos2.geodesy converts with PROJ.

from pymoos2.geodesy import LocalFrame, geodesic, distortion

frame = LocalFrame(42.358456, -71.087589)        # UTM, zone fixed by the origin
x, y = frame.to_xy(42.3601, -71.0942)
lat, lon = frame.to_latlon(x, y)

geodesic.distance(42.36, -71.09, 51.48, 0.0)     # WGS84 meters
distortion(frame, lat, lon)                      # scale and heading error of the flat frame here

LocalFrame(..., projection="aeqd") suits long ranges and the poles.

Tests

git clone https://github.com/raymondturrisi/pymoos2 && cd pymoos2
pip install -e .[test]
./test.sh              # every test, with its result
./test.sh --wheel      # test the built wheel in a fresh venv

License

MIT

Metadata

Release files for pymoos2 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymoos2 1.0.1
File Size Uploaded Provenance Actions
pymoos2-1.0.1.tar.gz 213.8 kB Without provenance Details for pymoos2-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymoos2 1.0.1
File Interpreter ABI Platform Actions
pymoos2-1.0.1-py3-none-any.whl Python 3 none any Details for pymoos2-1.0.1-py3-none-any.whl

Total release size: 428.1 kB

Release files / pymoos2-1.0.1.tar.gz

Download URL pymoos2-1.0.1.tar.gz
Size 213.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f74f6b199dad29453ceae5e5ee791284a69196e27e9d92ab6d7e0d4c71531b3
BLAKE2b-256 checksum
How to use checksums
0432df628f73d211cad836279eaf12b658c8ce3a0970dcb85a2c4d5936cc2534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pymoos2-1.0.1-py3-none-any.whl

Download URL pymoos2-1.0.1-py3-none-any.whl
Size 214.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ac38e05565b29dc90d68eeda0b8cd6fc6d4efbe9ba47b9ac3b3279be2769b4c
BLAKE2b-256 checksum
How to use checksums
8550b398f57225f2e5852f94e7bc107a4152c0c8a4363f6be82351f4903e4436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for pymoos2 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page