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
}

Posts go out at the next CommsTick; raise CommsTick for lower latency.

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.2

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.2
File Size Uploaded Provenance Actions
pymoos2-1.0.2.tar.gz 214.5 kB Without provenance Details for pymoos2-1.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 429.0 kB

Release files / pymoos2-1.0.2.tar.gz

Download URL pymoos2-1.0.2.tar.gz
Size 214.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5396f7f96e7bcdbeb58e9685af3287e5c6eb7bb6e528edb9d2842b623c1a9a75
BLAKE2b-256 checksum
How to use checksums
8284d4b55262be0cd7963415dfbda453a42e70f5f9377a3e63784aa256727fc5
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.2-py3-none-any.whl

Download URL pymoos2-1.0.2-py3-none-any.whl
Size 214.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1b54e048e80e66557440e3c40456a26dfe7574d8a60cd99d38c2fa788c116cd
BLAKE2b-256 checksum
How to use checksums
0df11252b5037c050a77061f5b0a1c806cd4238f99c9113dccd0a04dfc1181d8
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.2

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