Skip to content

Commit cdbf00e

Browse files
Copilotmsis
andcommitted
Support standard MOOS pattern - run() reads server/port from mission file
Co-authored-by: msis <577139+msis@users.noreply.github.com>
1 parent 07fe5f9 commit cdbf00e

4 files changed

Lines changed: 42 additions & 16 deletions

File tree

Documentation/examples/simpleapp.moos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Example mission file for simpleapp.py
2-
// To run: python simpleapp.py --mission_file=simpleapp.moos
2+
// Standard MOOS pattern: python simpleapp.py (modify code to call app.run('simpleapp.moos'))
33

44
ServerHost = localhost
55
ServerPort = 9000

Documentation/examples/simpleapp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ def main():
6565
app.set_on_new_mail_callback(on_new_mail)
6666
app.set_iterate_callback(iterate)
6767

68-
# Run the application (this blocks until iterate returns False)
69-
# You can optionally provide a mission file path for configuration:
70-
# app.run('localhost', 9000, 'pymoos_simple_app', 'simpleapp.moos')
71-
# Or run without a mission file (using defaults in on_startup):
68+
# Standard MOOS pattern: Run with mission file
69+
# The mission file contains ServerHost, ServerPort, and Community
70+
# app.run('simpleapp.moos')
71+
72+
# Alternative: Run without mission file (provide server, port, name manually)
7273
app.run('localhost', 9000, 'pymoos_simple_app')
7374

7475
if __name__ == "__main__":

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ app.set_on_start_up_callback(on_startup)
7373
app.set_on_connect_to_server_callback(on_connect_to_server)
7474
app.set_iterate_callback(iterate)
7575

76-
# Optionally provide a mission file for configuration
77-
app.run('localhost', 9000, 'my_app', 'my_mission.moos')
76+
# Standard MOOS pattern: Run with mission file
77+
# ServerHost, ServerPort, and Community are read from the mission file
78+
app.run('my_mission.moos')
79+
80+
# Alternative: Run without mission file (provide connection details manually)
81+
# app.run('localhost', 9000, 'my_app')
7882
```
7983

80-
The `app` class automatically handles `AppTick` and `CommsTick` from the mission file.
84+
The `app` class automatically reads `ServerHost`, `ServerPort`, `AppTick`, and `CommsTick` from the mission file.
8185
For custom configuration parameters, use:
8286
- `get_configuration_string(param)` - Read string parameters
8387
- `get_configuration_double(param)` - Read numeric parameters

src/pyMOOS.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,24 @@ class AppWrapper : public CMOOSApp {
229229
// Clean shutdown
230230
}
231231

232-
bool Run(const std::string & sServer, int Port, const std::string & sMyName, const std::string & sMissionFile = "") {
232+
// Standard MOOS pattern: Run with mission file (reads server/port/name from file)
233+
bool Run(const std::string & sMissionFile) {
234+
SetMissionFile(sMissionFile);
235+
return BASE::Run();
236+
}
237+
238+
// Alternative: Run with explicit parameters (for when mission file is not used)
239+
bool Run(const std::string & sServer, int Port, const std::string & sMyName) {
233240
SetAppName(sMyName);
234241
SetServer(sServer, Port);
235-
if (!sMissionFile.empty()) {
236-
SetMissionFile(sMissionFile);
237-
}
242+
return BASE::Run();
243+
}
244+
245+
// Run with explicit parameters and mission file
246+
bool Run(const std::string & sServer, int Port, const std::string & sMyName, const std::string & sMissionFile) {
247+
SetAppName(sMyName);
248+
SetServer(sServer, Port);
249+
SetMissionFile(sMissionFile);
238250
return BASE::Run();
239251
}
240252

@@ -747,10 +759,19 @@ PYBIND11_MODULE(pymoos, m) {
747759
py::class_<MOOS::AppWrapper, CMOOSApp>(m, "app")
748760
.def(py::init<>())
749761

750-
.def("run", &MOOS::AppWrapper::Run,
751-
"Run the MOOS application.",
752-
py::arg("server"), py::arg("port"), py::arg("name"),
753-
py::arg("mission_file") = "")
762+
.def("run", static_cast<bool(MOOS::AppWrapper::*)(const std::string&)>(&MOOS::AppWrapper::Run),
763+
"Run the MOOS application with mission file. "
764+
"Server, port, and app name are read from the mission file.",
765+
py::arg("mission_file"))
766+
767+
.def("run", static_cast<bool(MOOS::AppWrapper::*)(const std::string&, int, const std::string&)>(&MOOS::AppWrapper::Run),
768+
"Run the MOOS application with explicit server, port, and name. "
769+
"Use this when not using a mission file.",
770+
py::arg("server"), py::arg("port"), py::arg("name"))
771+
772+
.def("run", static_cast<bool(MOOS::AppWrapper::*)(const std::string&, int, const std::string&, const std::string&)>(&MOOS::AppWrapper::Run),
773+
"Run the MOOS application with both explicit parameters and mission file.",
774+
py::arg("server"), py::arg("port"), py::arg("name"), py::arg("mission_file"))
754775

755776
.def("fetch", &MOOS::AppWrapper::FetchMailAsVector,
756777
"Fetch incoming mail as a vector.")

0 commit comments

Comments
 (0)