Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.11)
project (python-moos)

find_package(MOOS 10 REQUIRED)
Expand Down
24 changes: 24 additions & 0 deletions Documentation/examples/simpleapp.moos
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Example mission file for simpleapp.py
// Standard MOOS pattern: python simpleapp.py (modify code to call app.run('simpleapp.moos'))

ServerHost = localhost
ServerPort = 9000
Community = pymoos_example

// Start MOOSDB with: MOOSDB simpleapp.moos

ProcessConfig = MOOSDB
{
ServerHost = localhost
ServerPort = 9000
}

ProcessConfig = pymoos_simple_app
{
AppTick = 2.0
CommsTick = 10.0

// Custom configuration parameters
variable_name = simple_app_var
max_iterations = 10
}
76 changes: 76 additions & 0 deletions Documentation/examples/simpleapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import pymoos
import time

# A simple example using the CMOOSApp wrapper:
# a) we make an app object and set up callbacks for the application lifecycle
# b) we run the app which starts the main loop
# The app class provides a more structured approach than comms, with separate
# callbacks for startup, iteration, and mail handling

app = pymoos.app()

# OnStartUp is called when the app first starts
def on_startup():
print("App starting up...")

# Note: AppTick and CommsTick from the mission file are automatically
# handled by CMOOSApp - you don't need to read or set them manually.

# Read custom configuration parameters from the mission file
# The mission file should have a ProcessConfig block for this app
success, var_name = app.get_configuration_string('variable_name')
if success:
print(f"Will publish to variable: {var_name}")
else:
print("Using default variable name: simple_app_var")

success, max_iter = app.get_configuration_int('max_iterations')
if success:
print(f"Will run for {max_iter} iterations")

return True

# OnConnectToServer is called when connection to MOOSDB is established
def on_connect_to_server():
print("Connected to MOOSDB, registering for variables...")
return app.register('simple_app_var', 0)

# OnNewMail is called when new mail arrives
def on_new_mail(mail):
print(f"Received {len(mail)} messages:")
for msg in mail:
msg.trace()
return True

# Iterate is the main work loop, called at the frequency set by AppTick in the mission file
iteration_count = 0
def iterate():
global iteration_count
iteration_count += 1
print(f"Iterate #{iteration_count}")

# Publish a message
app.notify('simple_app_var', f'iteration {iteration_count}', pymoos.time())

# Run for 10 iterations then stop
if iteration_count >= 10:
return False

return True

def main():
# Set up the callbacks
app.set_on_start_up_callback(on_startup)
app.set_on_connect_to_server_callback(on_connect_to_server)
app.set_on_new_mail_callback(on_new_mail)
app.set_iterate_callback(iterate)

# Standard MOOS pattern: app_name and mission file
# The mission file contains ServerHost, ServerPort, AppTick, CommsTick, and Community
app.run('pymoos_simple_app', 'simpleapp.moos')

# Alternative: Run without mission file (uses default Mission.moos)
# app.run('pymoos_simple_app')

if __name__ == "__main__":
main()
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
python-moos
===========
UPDATED FOR python3.12
python bindings for [MOOS](https://github.com/themoos/core-moos)

# Build Statuses
Expand All @@ -22,3 +23,74 @@ cd python-moos
python setup.py build
python setup.py install
```

# Usage

python-moos provides two main classes for interacting with MOOS:

## pymoos.comms - Asynchronous Communications

For simple publish/subscribe communication with the MOOSDB:

```python
import pymoos

comms = pymoos.comms()

def on_connect():
return comms.register('MY_VAR', 0)

comms.set_on_connect_callback(on_connect)
comms.run('localhost', 9000, 'my_client')
```

See `Documentation/examples/simplecomms.py` for a complete example.

## pymoos.app - MOOS Application Framework

For building full MOOS applications with structured lifecycle callbacks:

```python
import pymoos

app = pymoos.app()

def on_startup():
# AppTick and CommsTick are automatically read from mission file
# Read custom configuration parameters
success, my_param = app.get_configuration_string('my_param')
if success:
print(f"Configuration parameter: {my_param}")
return True

def on_connect_to_server():
return app.register('MY_VAR', 0)

def iterate():
# Main application loop
return True

app.set_on_start_up_callback(on_startup)
app.set_on_connect_to_server_callback(on_connect_to_server)
app.set_iterate_callback(iterate)

# Standard MOOS pattern: app name and mission file
# Mission file contains ServerHost, ServerPort, AppTick, CommsTick, and Community
app.run('my_app', 'my_mission.moos')

# Alternative: Run without specifying mission file (uses default 'Mission.moos')
# app.run('my_app')
```

The `app` class uses CMOOSApp::Run(app_name, mission_file) from the MOOS library.
The mission file automatically configures `ServerHost`, `ServerPort`, `AppTick`, and `CommsTick`.
For custom configuration parameters, use:
- `get_configuration_string(param)` - Read string parameters
- `get_configuration_double(param)` - Read numeric parameters
- `get_configuration_int(param)` - Read integer parameters
- `get_configuration_bool(param)` - Read boolean parameters

All methods return a tuple `(success, value)`.

See `Documentation/examples/simpleapp.py` for a complete example.

55 changes: 10 additions & 45 deletions pybind11/.appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,35 @@
version: 1.0.{build}
image:
- Visual Studio 2017
- Visual Studio 2015
test: off
skip_branch_with_pr: true
build:
parallel: true
platform:
- x64
- x86
environment:
matrix:
- PYTHON: 36
CPP: 14
- PYTHON: 38
CONFIG: Debug
- PYTHON: 27
CPP: 14
CONFIG: Debug
- CONDA: 36
CPP: latest
CONFIG: Release
matrix:
exclude:
- image: Visual Studio 2015
platform: x86
- image: Visual Studio 2015
CPP: latest
- image: Visual Studio 2017
CPP: latest
platform: x86
install:
- ps: |
if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }
if ($env:APPVEYOR_JOB_NAME -like "*Visual Studio 2017*") {
$env:CMAKE_GENERATOR = "Visual Studio 15 2017"
$env:CMAKE_INCLUDE_PATH = "C:\Libraries\boost_1_64_0"
$env:CXXFLAGS = "-permissive-"
} else {
$env:CMAKE_GENERATOR = "Visual Studio 14 2015"
}
if ($env:PYTHON) {
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
python -W ignore -m pip install --upgrade pip wheel
python -W ignore -m pip install pytest numpy --no-warn-script-location
} elseif ($env:CONDA) {
if ($env:CONDA -eq "27") { $env:CONDA = "" }
if ($env:PLATFORM -eq "x64") { $env:CONDA = "$env:CONDA-x64" }
$env:PATH = "C:\Miniconda$env:CONDA\;C:\Miniconda$env:CONDA\Scripts\;$env:PATH"
$env:PYTHONHOME = "C:\Miniconda$env:CONDA"
conda --version
conda install -y -q pytest numpy scipy
}
$env:CMAKE_GENERATOR = "Visual Studio 15 2017"
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
python -W ignore -m pip install --upgrade pip wheel
python -W ignore -m pip install pytest numpy --no-warn-script-location pytest-timeout
- ps: |
Start-FileDownload 'http://bitbucket.org/eigen/eigen/get/3.3.3.zip'
7z x 3.3.3.zip -y > $null
$env:CMAKE_INCLUDE_PATH = "eigen-eigen-67e894c6cd8f;$env:CMAKE_INCLUDE_PATH"
Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip'
7z x eigen-3.3.7.zip -y > $null
$env:CMAKE_INCLUDE_PATH = "eigen-3.3.7;$env:CMAKE_INCLUDE_PATH"
build_script:
- cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
-DPYBIND11_CPP_STANDARD=/std:c++%CPP%
-DCMAKE_CXX_STANDARD=14
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DCMAKE_SUPPRESS_REGENERATION=1
.
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger%
- cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger%
- if "%CPP%"=="latest" (cmake --build . --config %CONFIG% --target test_cmake_build -- /m /v:m /logger:%MSBuildLogger%)
on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log*
38 changes: 38 additions & 0 deletions pybind11/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# See all possible options and defaults with:
# clang-format --style=llvm --dump-config
BasedOnStyle: LLVM
AccessModifierOffset: -4
AllowShortLambdasOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: All
BreakConstructorInitializers: BeforeColon
ColumnLimit: 99
CommentPragmas: 'NOLINT:.*|^ IWYU pragma:'
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
Language: Cpp
SpaceAfterCStyleCast: true
Standard: Cpp11
StatementMacros: ['PyObject_HEAD']
TabWidth: 4
IncludeCategories:
- Regex: '<pybind11/.*'
Priority: -1
- Regex: 'pybind11.h"$'
Priority: 1
- Regex: '^".*/?detail/'
Priority: 1
SortPriority: 2
- Regex: '^"'
Priority: 1
SortPriority: 3
- Regex: '<[[:alnum:]._]+>'
Priority: 4
- Regex: '.*'
Priority: 5
...
79 changes: 79 additions & 0 deletions pybind11/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FormatStyle: file

Checks: |
*bugprone*,
*performance*,
clang-analyzer-optin.cplusplus.VirtualCall,
clang-analyzer-optin.performance.Padding,
cppcoreguidelines-init-variables,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing,
google-explicit-constructor,
llvm-namespace-comment,
misc-definitions-in-headers,
misc-misplaced-const,
misc-non-copyable-objects,
misc-static-assert,
misc-throw-by-value-catch-by-reference,
misc-uniqueptr-reset-release,
misc-unused-parameters,
modernize-avoid-bind,
modernize-loop-convert,
modernize-make-shared,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-shrink-to-fit,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-using,
readability-avoid-const-params-in-decls,
readability-braces-around-statements,
readability-const-return-type,
readability-container-size-empty,
readability-delete-null-pointer,
readability-else-after-return,
readability-implicit-bool-conversion,
readability-inconsistent-declaration-parameter-name,
readability-make-member-function-const,
readability-misplaced-array-index,
readability-non-const-parameter,
readability-qualified-auto,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-suspicious-call-argument,
readability-uniqueptr-delete-release,
-bugprone-chained-comparison,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-reserved-identifier,
-bugprone-unused-raii,
-performance-enum-size,

CheckOptions:
- key: modernize-use-equals-default.IgnoreMacros
value: false
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: true
- key: performance-inefficient-string-concatenation.StrictMode
value: true
- key: performance-unnecessary-value-param.AllowedTypes
value: 'exception_ptr$;'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: true

HeaderFilterRegex: 'pybind11/.*h'
Loading