WWW-POSIM v0.6.16Simulator documentation
Documentation menu
WWW-POSIM / Simulator documentation

Control ArduPilot with Python

Run Python for one WAM-V or BlueROV2 in a personal Autopilot workspace. ArduPilot handles the selected mode and actuator mixing; your callback supplies manual inputs. A fleet is not required.

Prepare the environment

Use WWW-POSIM 0.6.16 or newer and SDK 0.4.3. Start a personal world in Autopilot mode and wait for navigation and pre-arm readiness. Stop missions, release manual control and disconnect QGC. Keep the installed app and workspace open. Open the prepared Python terminal described in ROS terminals & connections, then install the SDK into that environment:

python -m pip install --upgrade https://github.com/IOES-Lab/homebrew-www-posim/releases/download/v0.6.16/www_posim_ros-0.4.3-py3-none-any.whl

Run a short WAM-V command

Check that the water around the vehicle is clear. Save this as ardupilot_manual.py and run python ardupilot_manual.py in the same terminal. It selects MANUAL, arms, sends a small forward input for two seconds and requests disarm in the cleanup block:

from www_posim_ros import ArduPilotSession

with ArduPilotSession.local(control=True) as sim:
    sim.set_mode("MANUAL")
    try:
        sim.arm(True)
        sim.control_manual(
            lambda elapsed: {"x": 0.2, "r": 0.0},
            duration=2.0,
            gain=0.25,
        )
    finally:
        sim.arm(False)

Input and control ownership

The callback receives elapsed wall-clock seconds and returns a dictionary. Axes x, y, z, r range from −1 to 1; omitted axes are zero. WAM-V accepts x and r; BlueROV2 accepts all four. These are normalized inputs, not metres per second or newtons. Duration is greater than zero and at most 30 seconds. Gain is 0.1–0.35; begin with 0.25.

The helper claims control with neutral input, refreshes it at up to 10 Hz and releases it with neutral input when finished, interrupted or a callback raises an error. The vehicle watchdog stops manual input after 0.6 seconds without a valid update. sim.stop() and session exit release input; they do not disarm or change mode. The example explicitly requests disarm. Neutral input does not remove inertia or wave forces.

Mode and arming requests wait for flight-controller confirmation. WAM-V supports MANUAL, HOLD and STEERING; BlueROV2 supports MANUAL, STABILIZE and ALT_HOLD. Another manual controller, mission or QGC can block a request. A changed world or expired lease ends control rather than silently reacquiring it. If cleanup is rejected, inspect the current owner and vehicle state in the workspace before retrying.

Website and ROS telemetry

For your own website workspace, replace the context manager with the following line. Enter your account password at the terminal prompt; do not put it in source code:

with ArduPilotSession.remote(email="YOU@example.com", control=True) as sim:

Use sim.topics and sim.latest(topic) to read fresh ROS message dictionaries in either connection. A telemetry read does not grant ROS command authority. Control an installed workspace require ROS 2 mode; this chapter sends requests through ArduPilot. Close the Python controller before Control with QGC.

Search documentation