pixhawkcontroller


Namepixhawkcontroller JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/Shahriar88/pixhawkcontroller
SummaryLightweight Pixhawk/ArduPilot controller utilities using pymavlink
upload_time2025-10-11 06:13:47
maintainerNone
docs_urlNone
authorMd Shahriar Forhad
requires_python>=3.9
licenseMIT
keywords pixhawk ardupilot mavlink pymavlink drone uav
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pixhawkcontroller

> Lightweight Python utilities to connect and control **Pixhawk / ArduPilot** flight controllers using [pymavlink](https://github.com/ArduPilot/pymavlink).  
> Supports Serial/UDP/TCP, quick telemetry, mission helpers, servo/relay/motor tests, tones, and common MAV_CMD wrappers.

---

## ✨ Features

* πŸ”Œ **Auto-detect Pixhawk/Cube over USB** by VID/PID (configurable defaults).  
* 🌐 **Serial / UDP / TCP** connection strings (`COMx`, `/dev/ttyUSB*`, `udp:127.0.0.1:14550`, `tcp:…`).  
* πŸ›° **INFO decode** from `AUTOPILOT_VERSION` + boot banners (vendor/product, FW/OS git hashes, capabilities).  
* 🧭 **Mode control** with family auto-selection (Copter/Plane/Rover).  
* πŸ›  **Servo + RC override** helpers with safe reset.  
* πŸ” **Relay repeat** & **motor test** wrappers.  
* πŸ—Ί **Mission helpers**: start, pause/continue, guided reposition, guided limits, condition delay.  
* πŸ›«/πŸ›¬ **NAV takeoff / land / RTL** shortcuts.  
* πŸ›‘ **Flight termination** (emergency stop β€” dangerous).  
* 🎢 **Buzzer tones** with QBasic-style strings & optional auto tones.  

---

## πŸ“¦ Installation

```bash
# (Optional) virtual environment
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# From source (editable)
git clone https://github.com/Shahriar88/pixhawkcontroller.git
cd pixhawkcontroller
pip install -e .
````

Core dependencies:

```bash
pymavlink >= 2.4.41
pyserial >= 3.5
```

Build/packaging dependencies:

```bash
build == 1.3.0
setuptools == 80.9.0
wheel == 0.45.1
twine == 6.2.0
packaging == 25.0
```

---

## 🧩 Project layout

* `pixhawkcontroller/main.py` β€” main implementation (class, helpers, demos).
* `pixhawkcontroller/__init__.py` β€” public API (exports classes and `find_usb_vid_pid`).
* `README.md` β€” this documentation.

---

## πŸš€ Quick Start

### 1) List available USB serial devices

Before connecting, you can quickly list all detected USB serial devices with VID/PID information:

```python
from pixhawkcontroller import find_usb_vid_pid

find_usb_vid_pid()
```

Example output:

```
USB Serial Devices:

{'port': 'COM5', 'vid': '2dae', 'pid': '1058', 'location': '1-1', 'description': 'CubeOrange+'}
{'port': 'COM6', 'vid': '0483', 'pid': '5740', 'location': '2-3', 'description': 'Pixhawk 2.4.8'}
```

Use this to identify your Pixhawk/Cube device’s correct VID/PID or port before connecting.

---

### 2) Import & connect

```python
from pixhawkcontroller import FlightControllerInterface, TonesQb

# Auto-detect (USB VID/PID)
fc = FlightControllerInterface()
fc.connect()

# Or explicit serial:
# fc = FlightControllerInterface(device='COM3', baudrate=115200)            # Windows
# fc = FlightControllerInterface(device='/dev/ttyUSB0', baudrate=115200)    # Linux
# fc = FlightControllerInterface(device='/dev/tty.usbmodem14101', baudrate=115200)  # macOS

# Or SITL via UDP:
# fc = FlightControllerInterface(device='udp:127.0.0.1:14550')
# fc.connect()

# Or TCP:
# fc = FlightControllerInterface(device='tcp:192.168.1.100:5760')
# fc.connect()
```

The constructor defaults include a VID/PID pair (CubePilot Orange+ by default) and will auto-scan serial ports when `device` is not provided.

---

### 3) Print board info & telemetry

```python
fc.print_info()        # vendor/product, FW/OS hashes, capabilities, IDs
fc.print_telemetry()   # mode, family, armed, GPS fix, location, battery
```

These use `AUTOPILOT_VERSION` and recent messages (`HEARTBEAT`, `GPS_RAW_INT`, `GLOBAL_POSITION_INT`, `SYS_STATUS`).

---

## πŸ”Œ VID/PID: explicit examples

```python
# ArduPilot Bootloader (USB-CDC) β€” same as Pixhawk 2.4.8
# Vendor: 0x1209  Product: 0x5741
fc = FlightControllerInterface(vid='1209', pid='5741')  # bootloader mode
fc.connect()

# Pixhawk 2.4.8 (STMicroelectronics VCP, ChibiOS)
# Vendor: 0x0483  Product: 0x5740
fc = FlightControllerInterface(vid='0483', pid='5740')
fc.connect()

# Cube+ family (CubePilot)
# Vendor: 0x2DAE  Product: 0x1101 (CubeBlack+) or 0x1058 (CubeOrange+)
fc = FlightControllerInterface(vid='2DAE', pid='1058')  # CubeOrange+
# fc = FlightControllerInterface(vid='2DAE', pid='1101')  # CubeBlack+
fc.connect()
```

These match the VID/PID map included in the code.

---

## πŸ›° Mode control (auto family)

```python
fc.set_mode("GUIDED")
fc.set_mode("AUTO")
fc.set_mode("RTL")
fc.set_mode("SMART_RTL")
# Plane example: fc.set_mode("MANUAL") / "FBWA" / "CRUISE"
```

Vehicle family (`copter`/`plane`/`rover`) is inferred from `HEARTBEAT.type`.
The method retries via `SET_MODE`, then falls back to `MAV_CMD_DO_SET_MODE` if needed.

---

## πŸ›  Servo / RC override

```python
# Direct servo output (PWM Β΅s)
fc.set_servo(9, 900);  time.sleep(2)
fc.set_servo(9, 1500); time.sleep(2)
fc.set_servo(9, 1900)

# RC override (ch1..8). Example: throttle mid for 2 s, then clear.
if not fc.check_arm_status():
    fc.arm()           # use fc.arm(force=True) to override prechecks (dangerous)
fc.set_rc_pwm(3, 1500)
time.sleep(2)
fc.clear_rc_overrides()
fc.disarm()
```

Servo uses `MAV_CMD_DO_SET_SERVO`; RC override uses `RC_CHANNELS_OVERRIDE`;
`check_arm_status()` reads `MAV_MODE_FLAG_SAFETY_ARMED`.

---

## πŸ” Relay / Motor test

```python
# Toggle a relay repeatedly (index/count/period)
fc.repeat_relay(relay_number=0, count=10, period_s=2.0)

# Spin motor #1 at 20% for 3 seconds (type=0 β†’ percent)
fc.motor_test(motor_index=1, throttle_type=0, throttle_value=20.0, duration_s=3.0)
```

Relay uses `MAV_CMD_DO_REPEAT_RELAY`; motor test uses `MAV_CMD_DO_MOTOR_TEST`.

---

## πŸ—Ί Mission helpers

```python
# Start mission (requires AUTO)
fc.set_mode("AUTO")
fc.mission_start()

# Pause & resume mission
fc.pause_continue_mission(True)   # pause
time.sleep(5)
fc.pause_continue_mission(False)  # continue

# Reposition in GUIDED (lat, lon, alt), optional speed and auto-switch to GUIDED
lat, lon, alt = 23.911222, 90.254833, 46
fc.do_reposition(lat, lon, alt, speed_m_s=3.0, change_mode_to_guided=True)

# Apply guided limits (timeout and leash)
fc.do_guided_limits(timeout_s=60, horiz_max_m=50)

# Insert condition delay (useful inside a mission)
fc.condition_delay(5)
```

Covers `MAV_CMD_MISSION_START`, `MAV_CMD_DO_PAUSE_CONTINUE`,
`MAV_CMD_DO_REPOSITION`, `MAV_CMD_DO_GUIDED_LIMITS`, `MAV_CMD_CONDITION_DELAY`.

---

## πŸ›« Takeoff / πŸ›¬ Land / πŸ” RTL / πŸ›‘ Termination

```python
# Takeoff (Copter/Plane; Rover usually ignores)
fc.nav_takeoff(target_alt_m=20.0, min_pitch_deg=0.0)

# Land now (current location by default)
fc.nav_land()

# Return to Launch
fc.return_to_launch()

# Emergency stop (dangerous!)
# fc.flight_termination(True)
```

Implements `MAV_CMD_NAV_TAKEOFF`, `MAV_CMD_NAV_LAND`,
`MAV_CMD_NAV_RETURN_TO_LAUNCH`, `MAV_CMD_DO_FLIGHTTERMINATION`.
**Use termination only in emergencies** β€” it cuts actuators immediately.

---

## πŸ”Š Tones & auto cues

```python
# Manual tones
from pixhawkcontroller import TonesQb
fc.play_tune(TonesQb.def_tone)
time.sleep(1)
fc.play_tune(TonesQb.twinkle_little_star)

# Optional audible cues on events:
fc.auto_play_tune = True   # or False to disable sounds
# (connect/arm/close paths in the code play short cues if enabled)
```

Tone strings are QBasic-style and compatible with ArduPilot’s tone parser.

---

## πŸ§ͺ Demo blocks (safe by default)

`main.py` ships with demo sections gated by flags:

* `SAFE_DEMO = False` β€” full, commented walkthrough (flip to `True` to run).
* A second mini-demo (SITL-friendly) under another `if False:` block.

Both demonstrate connection, info/telemetry, modes, servo/RC, mission helpers, guided controls, and cleanup.

---

## 🧰 Utility: list USB serials (again)

```python
from pixhawkcontroller import find_usb_vid_pid
find_usb_vid_pid()  # prints all USB serial devices with VID/PID/port/description
```

Use this to identify what VID/PID your board exposes on your OS.

---

## πŸ›‘ Safety

* **Test in SITL first** (no props):
  `sim_vehicle.py -v Rover --console --map` (or Copter/Plane).
* Commands like `.arm()`, `.set_servo()`, `.set_rc_pwm()` can move actuators.
* **Flight termination** immediately stops actuators β€” only for emergencies.

---

## πŸ“˜ Examples

### List USB serials (before connecting)

```python
from pixhawkcontroller import find_usb_vid_pid

find_usb_vid_pid()
# β†’ prints dicts with port, vid/pid, location, description
```

### Connect (auto-detect or explicit)

```python
from pixhawkcontroller import FlightControllerInterface

# Auto-detect over USB (uses default VID/PID scanning)
fc = FlightControllerInterface()
fc.connect()

# Or explicit serial:
# fc = FlightControllerInterface(device="COM3", baudrate=115200)            # Windows
# fc = FlightControllerInterface(device="/dev/ttyUSB0", baudrate=115200)    # Linux
# fc = FlightControllerInterface(device="/dev/tty.usbmodem14101", baudrate=115200)  # macOS
# fc.connect()

# Or SITL:
# fc = FlightControllerInterface(device="udp:127.0.0.1:14550"); fc.connect()
```

### Board info & quick telemetry

```python
fc.print_info()      # Vendor/Product, FW/OS git hashes, capabilities, IDs
fc.print_telemetry() # Mode/Family, Armed, GPS fix, Location, Battery
```

### Explicit VID/PID examples

```python
# Bootloader (USB-CDC) β€” same vendor/product seen on many Pixhawk bootloaders
fc = FlightControllerInterface(vid="1209", pid="5741"); fc.connect()

# Pixhawk 2.4.8 (ST VCP / ChibiOS)
fc = FlightControllerInterface(vid="0483", pid="5740"); fc.connect()

# Cube+ family (CubePilot)
fc = FlightControllerInterface(vid="2DAE", pid="1058"); fc.connect()  # CubeOrange+
# fc = FlightControllerInterface(vid="2DAE", pid="1101"); fc.connect()  # CubeBlack+
```

### Change modes (auto family: copter/plane/rover)

```python
fc.set_mode("GUIDED")
fc.set_mode("AUTO")
fc.set_mode("RTL")
fc.set_mode("SMART_RTL")
```

### Arm / RC override (use with caution)

```python
# Arm only if not already armed
if not fc.check_arm_status():
    fc.arm()  # use fc.arm(force=True) to override prechecks (dangerous)

# Override throttle (ch3) to 1500 Β΅s for 2 seconds, then clear
fc.set_rc_pwm(3, 1500)
import time; time.sleep(2)
fc.clear_rc_overrides()

# Disarm when done
fc.disarm()
```

### Servo control (PWM Β΅s)

```python
import time
fc.set_servo(9, 900);  time.sleep(1.5)
fc.set_servo(9, 1500); time.sleep(1.5)
fc.set_servo(9, 1900)
```

### Relay & Motor test

```python
# Toggle relay #0 β†’ 10 cycles, 2.0 s period
fc.repeat_relay(relay_number=0, count=10, period_s=2.0)

# Run motor #1 at 20% for 3s (type=0 β†’ percent)
fc.motor_test(motor_index=1, throttle_type=0, throttle_value=20.0, duration_s=3.0)
```

### Mission helpers

```python
# Start current mission (set AUTO first)
fc.set_mode("AUTO")
fc.mission_start()

# Pause / continue (in AUTO)
fc.pause_continue_mission(True)
time.sleep(5)
fc.pause_continue_mission(False)
```

### Guided reposition & yaw

```python
# Move in GUIDED to a lat/lon/alt at 3 m/s and auto-switch to GUIDED
lat, lon, alt = 23.911222, 90.254833, 46
fc.do_reposition(lat, lon, alt, speed_m_s=3.0, change_mode_to_guided=True)

# Yaw to heading 90Β° at 30Β°/s (absolute)
fc.set_yaw_speed(90.0, 30.0, absolute=True)
```

### Guided limits & condition delay

```python
# Limit GUIDED motion (timeout=60s, horizontal leash=50m)
fc.do_guided_limits(timeout_s=60, horiz_max_m=50)

# Insert a 5s delay (useful inside AUTO missions)
fc.condition_delay(5)
```

### Takeoff / Land / RTL / (Emergency) Termination

```python
# Takeoff to 20m (Copter/Plane; Rover usually ignores)
fc.nav_takeoff(target_alt_m=20.0, min_pitch_deg=0.0)

# Land at current location
fc.nav_land()

# Return To Launch
fc.return_to_launch()

# Emergency stop (cuts actuators immediately) β€” DANGEROUS
# fc.flight_termination(True)
```

### Rover-specific: reverse direction

```python
# Reverse on, wait, then off (Rover only)
fc.set_reverse(True)
time.sleep(1.0)
fc.set_reverse(False)
```

### Tones (QBasic-style) & optional auto cues

```python
from pixhawkcontroller import TonesQb

# Manual tunes
fc.play_tune(TonesQb.def_tone)
time.sleep(1)
fc.play_tune(TonesQb.twinkle_little_star)

# Optional audible cues for events in your methods
fc.auto_play_tune = True  # set False to silence
```

### Clean shutdown

```python
# Final snapshot then close
fc.print_telemetry()

if fc.check_arm_status():
    fc.disarm()

fc.close()
```

---

## ❓ Troubleshooting

* **No device found / auto-detect fails**: run `find_usb_vid_pid()` and use explicit VID/PID.
  On Linux, add your user to `dialout` and re-log.
* **Mode won’t change**: ensure TX mode switch isn’t overriding; check pre-arm checks and link quality (`STATUSTEXT`).
* **No `AUTOPILOT_VERSION`**: ensure `SERIAL0_PROTOCOL=2` and you’re connected to the MAVLink port.

---

## πŸ“š References

* [ArduPilot MAVLink Commands & Mission Items](https://ardupilot.org/dev/docs/mavlink-mission-command-messages.html)
* [MAVLink Message Definitions](https://mavlink.io/en/messages/common.html)
* [ArduPilot ToneTester](https://ardupilot.org/dev/docs/code-overview-ardupilot.html#tonetester) (for previewing tunes)

---

## πŸ“œ License

MIT License Β© 2025 Md Shahriar Forhad
See the [LICENSE](./LICENSE) file for full terms.

---

## ⚠️ Disclaimer

> This software is provided *as-is* for educational and experimental use only.
> Use it at your own risk. The author assumes no liability for any damage, injury, or loss resulting from its use.

```



























            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Shahriar88/pixhawkcontroller",
    "name": "pixhawkcontroller",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "pixhawk, ardupilot, mavlink, pymavlink, drone, uav",
    "author": "Md Shahriar Forhad",
    "author_email": "shahriar.forhad.eee@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/46/84/77018982d63c321c693b69e27e35e7503b86c09e46d2825581a062dae2a3/pixhawkcontroller-0.0.2.tar.gz",
    "platform": null,
    "description": "# pixhawkcontroller\r\n\r\n> Lightweight Python utilities to connect and control **Pixhawk / ArduPilot** flight controllers using [pymavlink](https://github.com/ArduPilot/pymavlink).  \r\n> Supports Serial/UDP/TCP, quick telemetry, mission helpers, servo/relay/motor tests, tones, and common MAV_CMD wrappers.\r\n\r\n---\r\n\r\n## \u2728 Features\r\n\r\n* \ud83d\udd0c **Auto-detect Pixhawk/Cube over USB** by VID/PID (configurable defaults).  \r\n* \ud83c\udf10 **Serial / UDP / TCP** connection strings (`COMx`, `/dev/ttyUSB*`, `udp:127.0.0.1:14550`, `tcp:\u2026`).  \r\n* \ud83d\udef0 **INFO decode** from `AUTOPILOT_VERSION` + boot banners (vendor/product, FW/OS git hashes, capabilities).  \r\n* \ud83e\udded **Mode control** with family auto-selection (Copter/Plane/Rover).  \r\n* \ud83d\udee0 **Servo + RC override** helpers with safe reset.  \r\n* \ud83d\udd01 **Relay repeat** & **motor test** wrappers.  \r\n* \ud83d\uddfa **Mission helpers**: start, pause/continue, guided reposition, guided limits, condition delay.  \r\n* \ud83d\udeeb/\ud83d\udeec **NAV takeoff / land / RTL** shortcuts.  \r\n* \ud83d\uded1 **Flight termination** (emergency stop \u2014 dangerous).  \r\n* \ud83c\udfb6 **Buzzer tones** with QBasic-style strings & optional auto tones.  \r\n\r\n---\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\n# (Optional) virtual environment\r\npython3 -m venv venv\r\nsource venv/bin/activate  # Windows: venv\\Scripts\\activate\r\n\r\n# From source (editable)\r\ngit clone https://github.com/Shahriar88/pixhawkcontroller.git\r\ncd pixhawkcontroller\r\npip install -e .\r\n````\r\n\r\nCore dependencies:\r\n\r\n```bash\r\npymavlink >= 2.4.41\r\npyserial >= 3.5\r\n```\r\n\r\nBuild/packaging dependencies:\r\n\r\n```bash\r\nbuild == 1.3.0\r\nsetuptools == 80.9.0\r\nwheel == 0.45.1\r\ntwine == 6.2.0\r\npackaging == 25.0\r\n```\r\n\r\n---\r\n\r\n## \ud83e\udde9 Project layout\r\n\r\n* `pixhawkcontroller/main.py` \u2014 main implementation (class, helpers, demos).\r\n* `pixhawkcontroller/__init__.py` \u2014 public API (exports classes and `find_usb_vid_pid`).\r\n* `README.md` \u2014 this documentation.\r\n\r\n---\r\n\r\n## \ud83d\ude80 Quick Start\r\n\r\n### 1) List available USB serial devices\r\n\r\nBefore connecting, you can quickly list all detected USB serial devices with VID/PID information:\r\n\r\n```python\r\nfrom pixhawkcontroller import find_usb_vid_pid\r\n\r\nfind_usb_vid_pid()\r\n```\r\n\r\nExample output:\r\n\r\n```\r\nUSB Serial Devices:\r\n\r\n{'port': 'COM5', 'vid': '2dae', 'pid': '1058', 'location': '1-1', 'description': 'CubeOrange+'}\r\n{'port': 'COM6', 'vid': '0483', 'pid': '5740', 'location': '2-3', 'description': 'Pixhawk 2.4.8'}\r\n```\r\n\r\nUse this to identify your Pixhawk/Cube device\u2019s correct VID/PID or port before connecting.\r\n\r\n---\r\n\r\n### 2) Import & connect\r\n\r\n```python\r\nfrom pixhawkcontroller import FlightControllerInterface, TonesQb\r\n\r\n# Auto-detect (USB VID/PID)\r\nfc = FlightControllerInterface()\r\nfc.connect()\r\n\r\n# Or explicit serial:\r\n# fc = FlightControllerInterface(device='COM3', baudrate=115200)            # Windows\r\n# fc = FlightControllerInterface(device='/dev/ttyUSB0', baudrate=115200)    # Linux\r\n# fc = FlightControllerInterface(device='/dev/tty.usbmodem14101', baudrate=115200)  # macOS\r\n\r\n# Or SITL via UDP:\r\n# fc = FlightControllerInterface(device='udp:127.0.0.1:14550')\r\n# fc.connect()\r\n\r\n# Or TCP:\r\n# fc = FlightControllerInterface(device='tcp:192.168.1.100:5760')\r\n# fc.connect()\r\n```\r\n\r\nThe constructor defaults include a VID/PID pair (CubePilot Orange+ by default) and will auto-scan serial ports when `device` is not provided.\r\n\r\n---\r\n\r\n### 3) Print board info & telemetry\r\n\r\n```python\r\nfc.print_info()        # vendor/product, FW/OS hashes, capabilities, IDs\r\nfc.print_telemetry()   # mode, family, armed, GPS fix, location, battery\r\n```\r\n\r\nThese use `AUTOPILOT_VERSION` and recent messages (`HEARTBEAT`, `GPS_RAW_INT`, `GLOBAL_POSITION_INT`, `SYS_STATUS`).\r\n\r\n---\r\n\r\n## \ud83d\udd0c VID/PID: explicit examples\r\n\r\n```python\r\n# ArduPilot Bootloader (USB-CDC) \u2014 same as Pixhawk 2.4.8\r\n# Vendor: 0x1209  Product: 0x5741\r\nfc = FlightControllerInterface(vid='1209', pid='5741')  # bootloader mode\r\nfc.connect()\r\n\r\n# Pixhawk 2.4.8 (STMicroelectronics VCP, ChibiOS)\r\n# Vendor: 0x0483  Product: 0x5740\r\nfc = FlightControllerInterface(vid='0483', pid='5740')\r\nfc.connect()\r\n\r\n# Cube+ family (CubePilot)\r\n# Vendor: 0x2DAE  Product: 0x1101 (CubeBlack+) or 0x1058 (CubeOrange+)\r\nfc = FlightControllerInterface(vid='2DAE', pid='1058')  # CubeOrange+\r\n# fc = FlightControllerInterface(vid='2DAE', pid='1101')  # CubeBlack+\r\nfc.connect()\r\n```\r\n\r\nThese match the VID/PID map included in the code.\r\n\r\n---\r\n\r\n## \ud83d\udef0 Mode control (auto family)\r\n\r\n```python\r\nfc.set_mode(\"GUIDED\")\r\nfc.set_mode(\"AUTO\")\r\nfc.set_mode(\"RTL\")\r\nfc.set_mode(\"SMART_RTL\")\r\n# Plane example: fc.set_mode(\"MANUAL\") / \"FBWA\" / \"CRUISE\"\r\n```\r\n\r\nVehicle family (`copter`/`plane`/`rover`) is inferred from `HEARTBEAT.type`.\r\nThe method retries via `SET_MODE`, then falls back to `MAV_CMD_DO_SET_MODE` if needed.\r\n\r\n---\r\n\r\n## \ud83d\udee0 Servo / RC override\r\n\r\n```python\r\n# Direct servo output (PWM \u00b5s)\r\nfc.set_servo(9, 900);  time.sleep(2)\r\nfc.set_servo(9, 1500); time.sleep(2)\r\nfc.set_servo(9, 1900)\r\n\r\n# RC override (ch1..8). Example: throttle mid for 2 s, then clear.\r\nif not fc.check_arm_status():\r\n    fc.arm()           # use fc.arm(force=True) to override prechecks (dangerous)\r\nfc.set_rc_pwm(3, 1500)\r\ntime.sleep(2)\r\nfc.clear_rc_overrides()\r\nfc.disarm()\r\n```\r\n\r\nServo uses `MAV_CMD_DO_SET_SERVO`; RC override uses `RC_CHANNELS_OVERRIDE`;\r\n`check_arm_status()` reads `MAV_MODE_FLAG_SAFETY_ARMED`.\r\n\r\n---\r\n\r\n## \ud83d\udd01 Relay / Motor test\r\n\r\n```python\r\n# Toggle a relay repeatedly (index/count/period)\r\nfc.repeat_relay(relay_number=0, count=10, period_s=2.0)\r\n\r\n# Spin motor #1 at 20% for 3 seconds (type=0 \u2192 percent)\r\nfc.motor_test(motor_index=1, throttle_type=0, throttle_value=20.0, duration_s=3.0)\r\n```\r\n\r\nRelay uses `MAV_CMD_DO_REPEAT_RELAY`; motor test uses `MAV_CMD_DO_MOTOR_TEST`.\r\n\r\n---\r\n\r\n## \ud83d\uddfa Mission helpers\r\n\r\n```python\r\n# Start mission (requires AUTO)\r\nfc.set_mode(\"AUTO\")\r\nfc.mission_start()\r\n\r\n# Pause & resume mission\r\nfc.pause_continue_mission(True)   # pause\r\ntime.sleep(5)\r\nfc.pause_continue_mission(False)  # continue\r\n\r\n# Reposition in GUIDED (lat, lon, alt), optional speed and auto-switch to GUIDED\r\nlat, lon, alt = 23.911222, 90.254833, 46\r\nfc.do_reposition(lat, lon, alt, speed_m_s=3.0, change_mode_to_guided=True)\r\n\r\n# Apply guided limits (timeout and leash)\r\nfc.do_guided_limits(timeout_s=60, horiz_max_m=50)\r\n\r\n# Insert condition delay (useful inside a mission)\r\nfc.condition_delay(5)\r\n```\r\n\r\nCovers `MAV_CMD_MISSION_START`, `MAV_CMD_DO_PAUSE_CONTINUE`,\r\n`MAV_CMD_DO_REPOSITION`, `MAV_CMD_DO_GUIDED_LIMITS`, `MAV_CMD_CONDITION_DELAY`.\r\n\r\n---\r\n\r\n## \ud83d\udeeb Takeoff / \ud83d\udeec Land / \ud83d\udd01 RTL / \ud83d\uded1 Termination\r\n\r\n```python\r\n# Takeoff (Copter/Plane; Rover usually ignores)\r\nfc.nav_takeoff(target_alt_m=20.0, min_pitch_deg=0.0)\r\n\r\n# Land now (current location by default)\r\nfc.nav_land()\r\n\r\n# Return to Launch\r\nfc.return_to_launch()\r\n\r\n# Emergency stop (dangerous!)\r\n# fc.flight_termination(True)\r\n```\r\n\r\nImplements `MAV_CMD_NAV_TAKEOFF`, `MAV_CMD_NAV_LAND`,\r\n`MAV_CMD_NAV_RETURN_TO_LAUNCH`, `MAV_CMD_DO_FLIGHTTERMINATION`.\r\n**Use termination only in emergencies** \u2014 it cuts actuators immediately.\r\n\r\n---\r\n\r\n## \ud83d\udd0a Tones & auto cues\r\n\r\n```python\r\n# Manual tones\r\nfrom pixhawkcontroller import TonesQb\r\nfc.play_tune(TonesQb.def_tone)\r\ntime.sleep(1)\r\nfc.play_tune(TonesQb.twinkle_little_star)\r\n\r\n# Optional audible cues on events:\r\nfc.auto_play_tune = True   # or False to disable sounds\r\n# (connect/arm/close paths in the code play short cues if enabled)\r\n```\r\n\r\nTone strings are QBasic-style and compatible with ArduPilot\u2019s tone parser.\r\n\r\n---\r\n\r\n## \ud83e\uddea Demo blocks (safe by default)\r\n\r\n`main.py` ships with demo sections gated by flags:\r\n\r\n* `SAFE_DEMO = False` \u2014 full, commented walkthrough (flip to `True` to run).\r\n* A second mini-demo (SITL-friendly) under another `if False:` block.\r\n\r\nBoth demonstrate connection, info/telemetry, modes, servo/RC, mission helpers, guided controls, and cleanup.\r\n\r\n---\r\n\r\n## \ud83e\uddf0 Utility: list USB serials (again)\r\n\r\n```python\r\nfrom pixhawkcontroller import find_usb_vid_pid\r\nfind_usb_vid_pid()  # prints all USB serial devices with VID/PID/port/description\r\n```\r\n\r\nUse this to identify what VID/PID your board exposes on your OS.\r\n\r\n---\r\n\r\n## \ud83d\udee1 Safety\r\n\r\n* **Test in SITL first** (no props):\r\n  `sim_vehicle.py -v Rover --console --map` (or Copter/Plane).\r\n* Commands like `.arm()`, `.set_servo()`, `.set_rc_pwm()` can move actuators.\r\n* **Flight termination** immediately stops actuators \u2014 only for emergencies.\r\n\r\n---\r\n\r\n## \ud83d\udcd8 Examples\r\n\r\n### List USB serials (before connecting)\r\n\r\n```python\r\nfrom pixhawkcontroller import find_usb_vid_pid\r\n\r\nfind_usb_vid_pid()\r\n# \u2192 prints dicts with port, vid/pid, location, description\r\n```\r\n\r\n### Connect (auto-detect or explicit)\r\n\r\n```python\r\nfrom pixhawkcontroller import FlightControllerInterface\r\n\r\n# Auto-detect over USB (uses default VID/PID scanning)\r\nfc = FlightControllerInterface()\r\nfc.connect()\r\n\r\n# Or explicit serial:\r\n# fc = FlightControllerInterface(device=\"COM3\", baudrate=115200)            # Windows\r\n# fc = FlightControllerInterface(device=\"/dev/ttyUSB0\", baudrate=115200)    # Linux\r\n# fc = FlightControllerInterface(device=\"/dev/tty.usbmodem14101\", baudrate=115200)  # macOS\r\n# fc.connect()\r\n\r\n# Or SITL:\r\n# fc = FlightControllerInterface(device=\"udp:127.0.0.1:14550\"); fc.connect()\r\n```\r\n\r\n### Board info & quick telemetry\r\n\r\n```python\r\nfc.print_info()      # Vendor/Product, FW/OS git hashes, capabilities, IDs\r\nfc.print_telemetry() # Mode/Family, Armed, GPS fix, Location, Battery\r\n```\r\n\r\n### Explicit VID/PID examples\r\n\r\n```python\r\n# Bootloader (USB-CDC) \u2014 same vendor/product seen on many Pixhawk bootloaders\r\nfc = FlightControllerInterface(vid=\"1209\", pid=\"5741\"); fc.connect()\r\n\r\n# Pixhawk 2.4.8 (ST VCP / ChibiOS)\r\nfc = FlightControllerInterface(vid=\"0483\", pid=\"5740\"); fc.connect()\r\n\r\n# Cube+ family (CubePilot)\r\nfc = FlightControllerInterface(vid=\"2DAE\", pid=\"1058\"); fc.connect()  # CubeOrange+\r\n# fc = FlightControllerInterface(vid=\"2DAE\", pid=\"1101\"); fc.connect()  # CubeBlack+\r\n```\r\n\r\n### Change modes (auto family: copter/plane/rover)\r\n\r\n```python\r\nfc.set_mode(\"GUIDED\")\r\nfc.set_mode(\"AUTO\")\r\nfc.set_mode(\"RTL\")\r\nfc.set_mode(\"SMART_RTL\")\r\n```\r\n\r\n### Arm / RC override (use with caution)\r\n\r\n```python\r\n# Arm only if not already armed\r\nif not fc.check_arm_status():\r\n    fc.arm()  # use fc.arm(force=True) to override prechecks (dangerous)\r\n\r\n# Override throttle (ch3) to 1500 \u00b5s for 2 seconds, then clear\r\nfc.set_rc_pwm(3, 1500)\r\nimport time; time.sleep(2)\r\nfc.clear_rc_overrides()\r\n\r\n# Disarm when done\r\nfc.disarm()\r\n```\r\n\r\n### Servo control (PWM \u00b5s)\r\n\r\n```python\r\nimport time\r\nfc.set_servo(9, 900);  time.sleep(1.5)\r\nfc.set_servo(9, 1500); time.sleep(1.5)\r\nfc.set_servo(9, 1900)\r\n```\r\n\r\n### Relay & Motor test\r\n\r\n```python\r\n# Toggle relay #0 \u2192 10 cycles, 2.0 s period\r\nfc.repeat_relay(relay_number=0, count=10, period_s=2.0)\r\n\r\n# Run motor #1 at 20% for 3s (type=0 \u2192 percent)\r\nfc.motor_test(motor_index=1, throttle_type=0, throttle_value=20.0, duration_s=3.0)\r\n```\r\n\r\n### Mission helpers\r\n\r\n```python\r\n# Start current mission (set AUTO first)\r\nfc.set_mode(\"AUTO\")\r\nfc.mission_start()\r\n\r\n# Pause / continue (in AUTO)\r\nfc.pause_continue_mission(True)\r\ntime.sleep(5)\r\nfc.pause_continue_mission(False)\r\n```\r\n\r\n### Guided reposition & yaw\r\n\r\n```python\r\n# Move in GUIDED to a lat/lon/alt at 3 m/s and auto-switch to GUIDED\r\nlat, lon, alt = 23.911222, 90.254833, 46\r\nfc.do_reposition(lat, lon, alt, speed_m_s=3.0, change_mode_to_guided=True)\r\n\r\n# Yaw to heading 90\u00b0 at 30\u00b0/s (absolute)\r\nfc.set_yaw_speed(90.0, 30.0, absolute=True)\r\n```\r\n\r\n### Guided limits & condition delay\r\n\r\n```python\r\n# Limit GUIDED motion (timeout=60s, horizontal leash=50m)\r\nfc.do_guided_limits(timeout_s=60, horiz_max_m=50)\r\n\r\n# Insert a 5s delay (useful inside AUTO missions)\r\nfc.condition_delay(5)\r\n```\r\n\r\n### Takeoff / Land / RTL / (Emergency) Termination\r\n\r\n```python\r\n# Takeoff to 20m (Copter/Plane; Rover usually ignores)\r\nfc.nav_takeoff(target_alt_m=20.0, min_pitch_deg=0.0)\r\n\r\n# Land at current location\r\nfc.nav_land()\r\n\r\n# Return To Launch\r\nfc.return_to_launch()\r\n\r\n# Emergency stop (cuts actuators immediately) \u2014 DANGEROUS\r\n# fc.flight_termination(True)\r\n```\r\n\r\n### Rover-specific: reverse direction\r\n\r\n```python\r\n# Reverse on, wait, then off (Rover only)\r\nfc.set_reverse(True)\r\ntime.sleep(1.0)\r\nfc.set_reverse(False)\r\n```\r\n\r\n### Tones (QBasic-style) & optional auto cues\r\n\r\n```python\r\nfrom pixhawkcontroller import TonesQb\r\n\r\n# Manual tunes\r\nfc.play_tune(TonesQb.def_tone)\r\ntime.sleep(1)\r\nfc.play_tune(TonesQb.twinkle_little_star)\r\n\r\n# Optional audible cues for events in your methods\r\nfc.auto_play_tune = True  # set False to silence\r\n```\r\n\r\n### Clean shutdown\r\n\r\n```python\r\n# Final snapshot then close\r\nfc.print_telemetry()\r\n\r\nif fc.check_arm_status():\r\n    fc.disarm()\r\n\r\nfc.close()\r\n```\r\n\r\n---\r\n\r\n## \u2753 Troubleshooting\r\n\r\n* **No device found / auto-detect fails**: run `find_usb_vid_pid()` and use explicit VID/PID.\r\n  On Linux, add your user to `dialout` and re-log.\r\n* **Mode won\u2019t change**: ensure TX mode switch isn\u2019t overriding; check pre-arm checks and link quality (`STATUSTEXT`).\r\n* **No `AUTOPILOT_VERSION`**: ensure `SERIAL0_PROTOCOL=2` and you\u2019re connected to the MAVLink port.\r\n\r\n---\r\n\r\n## \ud83d\udcda References\r\n\r\n* [ArduPilot MAVLink Commands & Mission Items](https://ardupilot.org/dev/docs/mavlink-mission-command-messages.html)\r\n* [MAVLink Message Definitions](https://mavlink.io/en/messages/common.html)\r\n* [ArduPilot ToneTester](https://ardupilot.org/dev/docs/code-overview-ardupilot.html#tonetester) (for previewing tunes)\r\n\r\n---\r\n\r\n## \ud83d\udcdc License\r\n\r\nMIT License \u00a9 2025 Md Shahriar Forhad\r\nSee the [LICENSE](./LICENSE) file for full terms.\r\n\r\n---\r\n\r\n## \u26a0\ufe0f Disclaimer\r\n\r\n> This software is provided *as-is* for educational and experimental use only.\r\n> Use it at your own risk. The author assumes no liability for any damage, injury, or loss resulting from its use.\r\n\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lightweight Pixhawk/ArduPilot controller utilities using pymavlink",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/Shahriar88/pixhawkcontroller",
        "Issues": "https://github.com/Shahriar88/pixhawkcontroller/issues",
        "Source": "https://github.com/Shahriar88/pixhawkcontroller"
    },
    "split_keywords": [
        "pixhawk",
        " ardupilot",
        " mavlink",
        " pymavlink",
        " drone",
        " uav"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c6b6e3a53132622615e41ab52ac6e8aa2b3beb68549f81eb154e7b29b364cd53",
                "md5": "1a8ce3349aa1033947d0e4ab402994f5",
                "sha256": "c4ae6ffb57fba45baa867297da9cb487410c96d3d1358ca3ca22d4e1dc4b4c36"
            },
            "downloads": -1,
            "filename": "pixhawkcontroller-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a8ce3349aa1033947d0e4ab402994f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 24469,
            "upload_time": "2025-10-11T06:13:45",
            "upload_time_iso_8601": "2025-10-11T06:13:45.911181Z",
            "url": "https://files.pythonhosted.org/packages/c6/b6/e3a53132622615e41ab52ac6e8aa2b3beb68549f81eb154e7b29b364cd53/pixhawkcontroller-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "468477018982d63c321c693b69e27e35e7503b86c09e46d2825581a062dae2a3",
                "md5": "fca56e953c80a172154e4e16de0c2bf4",
                "sha256": "bce6d6be0cf8ca99e76ddad3a0e449f8051f99ff95eb790cb012e42693de02d2"
            },
            "downloads": -1,
            "filename": "pixhawkcontroller-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "fca56e953c80a172154e4e16de0c2bf4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 28859,
            "upload_time": "2025-10-11T06:13:47",
            "upload_time_iso_8601": "2025-10-11T06:13:47.117115Z",
            "url": "https://files.pythonhosted.org/packages/46/84/77018982d63c321c693b69e27e35e7503b86c09e46d2825581a062dae2a3/pixhawkcontroller-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-11 06:13:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Shahriar88",
    "github_project": "pixhawkcontroller",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pixhawkcontroller"
}
        
Elapsed time: 1.15378s