pyMAVLinCS 1.2.0__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymavlincs-1.2.1/PKG-INFO +361 -0
- pymavlincs-1.2.1/README.md +347 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS/__init__.py +1 -1
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS/setup_logger.py +19 -7
- pymavlincs-1.2.1/pyMAVLinCS.egg-info/PKG-INFO +361 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS.egg-info/SOURCES.txt +4 -6
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyproject.toml +2 -2
- pymavlincs-1.2.1/tests/test_01_unit_offline.py +90 -0
- pymavlincs-1.2.1/tests/test_02_telemetry_comms.py +85 -0
- pymavlincs-1.2.1/tests/test_03_flight_guided.py +77 -0
- pymavlincs-1.2.1/tests/test_04_missions_auto.py +71 -0
- pymavlincs-1.2.0/PKG-INFO +0 -412
- pymavlincs-1.2.0/README.md +0 -398
- pymavlincs-1.2.0/pyMAVLinCS.egg-info/PKG-INFO +0 -412
- pymavlincs-1.2.0/tests/test_basic.py +0 -39
- pymavlincs-1.2.0/tests/test_commands.py +0 -68
- pymavlincs-1.2.0/tests/test_control.py +0 -35
- pymavlincs-1.2.0/tests/test_math.py +0 -46
- pymavlincs-1.2.0/tests/test_mcc.py +0 -65
- pymavlincs-1.2.0/tests/test_telemetry.py +0 -91
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/LICENSE +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS/mavecstra.py +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS/mavtypes.py +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS/mission_control_code.py +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS.egg-info/dependency_links.txt +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS.egg-info/requires.txt +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/pyMAVLinCS.egg-info/top_level.txt +0 -0
- {pymavlincs-1.2.0 → pymavlincs-1.2.1}/setup.cfg +0 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyMAVLinCS
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Python API for autonomous drone control based on pymavlink
|
|
5
|
+
Author-email: Noah Redon <redonnoah.cs@gmail.com>
|
|
6
|
+
License: GPL-3.0-or-later
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pymavlink>=2.4.49
|
|
11
|
+
Requires-Dist: pyserial
|
|
12
|
+
Requires-Dist: geopy
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
<h1 align="center"> pyMAVLinCS </h1>
|
|
16
|
+
<p align="center"> The high-level Python API for reliable, autonomous drone control, advanced telemetry, and MAVLink mission management. </p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<img alt="License_new" src="https://img.shields.io/badge/License-GPL%20v3-yellow">
|
|
20
|
+
<a href="https://github.com/noahredon/pyMAVLinCS/actions/workflows/test.yml"><img alt="Tests" src="https://img.shields.io/github/actions/workflow/status/noahredon/pyMAVLinCS/test.yml?branch=main&label=tests&logo=github"></a>
|
|
21
|
+
<img alt="GitHub" src="https://img.shields.io/badge/github-noahredon-blue?logo=github">
|
|
22
|
+
<img alt="Python" src="https://img.shields.io/badge/Python-%3E%3D3.10-blue?logo=python">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
## 📖 Table of Contents
|
|
28
|
+
- [✨ Overview](#-overview)
|
|
29
|
+
- [🚀 Key Features](#-key-features)
|
|
30
|
+
- [🛠️ Tech Stack & Architecture](#-tech-stack--architecture)
|
|
31
|
+
- [📁 Project Structure](#-project-structure)
|
|
32
|
+
- [⚙️ Getting Started](#-getting-started)
|
|
33
|
+
- [🎯 Usage](#-usage)
|
|
34
|
+
- [🤝 Contributing](#-contributing)
|
|
35
|
+
- [📝 License](#-license)
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
## ✨ Overview
|
|
40
|
+
|
|
41
|
+
pyMAVLinCS is a powerful, professional-grade Python library designed to simplify the development of autonomous systems by providing a high-level, stable, and feature-rich interface for MAVLink-based flight controllers (like ArduPilot and PX4).
|
|
42
|
+
|
|
43
|
+
> ⚠️ **The Problem:** Developing complex drone missions or ground control stations (GCS) often requires deep, low-level integration with the MAVLink protocol. This involves handling command acknowledgments, managing asynchronous message streams (like `STATUSTEXT` or `TIMESYNC`), performing complex geographic calculations, and ensuring thread safety, leading to verbose and error-prone code.
|
|
44
|
+
|
|
45
|
+
pyMAVLinCS eliminates this complexity by wrapping the core `pymavlink` functionality into an intuitive, object-oriented API (`MAVLinCS` class). It enables developers and engineers to execute mission-critical commands, retrieve comprehensive telemetry, manage gimbal payloads, and handle inter-system communication using simple, Pythonic method calls. This allows users to focus entirely on mission logic and operational safety, drastically reducing development time and enhancing code reliability.
|
|
46
|
+
|
|
47
|
+
The library is built around core Python features, geographic computations (`geopy`), and a thread-safe MAVLink message handler (`pymavlink`). Internal handler classes ensure seamless management of complex MAVLink processes like `STATUSTEXT` chunk reconstruction, `TIMESYNC` latency calculation, automatic `.tlog` flight recording, and structured console/file logging.
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
## 🚀 Key Features
|
|
52
|
+
|
|
53
|
+
pyMAVLinCS provides comprehensive capabilities spanning control, data retrieval, mission management, and advanced system configuration through the core `MAVLinCS` class.
|
|
54
|
+
|
|
55
|
+
### 📡 Real-Time Telemetry and System Status
|
|
56
|
+
|
|
57
|
+
Gain instant access to crucial flight and system data using simple method calls that handle message retrieval and parsing automatically:
|
|
58
|
+
- 🛰️ **Global & Local Position:** Retrieve current GPS coordinates (`position_gps`: latitude, longitude, relative altitude, MSL altitude) and local NED coordinates (`position_local`).
|
|
59
|
+
- 🧭 **Attitude and Velocity:** Get precise attitude Euler angles (`angles`) and angular rates (`angular_rates`). Retrieve linear velocities in three dimensions (`speed`) and absolute speed norm (`speed_module`).
|
|
60
|
+
- ⚡ **Power Monitoring:** Check remaining battery percentage (`battery_percentage`) and current voltage in Volts (`battery_voltage`).
|
|
61
|
+
- ⚙️ **Flight Status:** Instantly check arming status (`motors_armed`, `motors_disarmed`), autopilot type (`autopilot_int`, `autopilot_str`), current flight mode (`mode`, `custom_mode`), and PX4 mode details (`base_mode`, `custom_main_mode`, `custom_sub_mode`).
|
|
62
|
+
- 🌐 **Fix Status:** Confirm the status of the GPS system, including 3D fix availability (`gps_3d_fix`).
|
|
63
|
+
- 🕒 **Timing Data:** Access system boot time in seconds (`time_boot`) and milliseconds (`time_boot_ms`), and Unix timestamp in microseconds (`time_usec`).
|
|
64
|
+
|
|
65
|
+
### 🕹️ Autonomous Control and Action Execution
|
|
66
|
+
|
|
67
|
+
Execute mission-critical commands with built-in acknowledgment handling to ensure reliable action completion:
|
|
68
|
+
- 🔑 **System State Management:** Safely arm (`arm`) or disarm (`disarm`) the drone, with automatic pre-arm mode checks on ArduPilot, optional forced execution, and configurable timeouts.
|
|
69
|
+
- 🚁 **Takeoff & Landing:** Initiate automated takeoff (`takeoff`) to a specified altitude (including in-air vertical repositioning) or perform an automated landing (`land`).
|
|
70
|
+
- 🔄 **Flight Mode Control:** Change the flight mode using human-readable mode names, ArduPilot mode IDs, or PX4 mode tuples (`set_mode`).
|
|
71
|
+
- 🗺️ **Targeted Movement:** Set precise GPS position targets (`set_gps_pos_target`) or local NED position targets (`set_local_pos_target`) with optional yaw control.
|
|
72
|
+
- 💨 **Velocity Control:** Directly command the drone's velocity components (`set_speed`: North, East, Down in m/s) and heading.
|
|
73
|
+
- 🏠 **Return to Launch (RTL):** Send a Return-To-Launch request (`return_to_launch`) for safe mission abort.
|
|
74
|
+
- 🎯 **Dynamic Vehicle Following:** Autonomously take off and follow another moving MAVLink vehicle in real time (`do_follow`, `do_follow_with_takeoff`).
|
|
75
|
+
- 🛬 **Precision Landing Target:** Stream visual/IR landing target offsets in the drone's body frame (`send_landing_target`).
|
|
76
|
+
- 🔧 **System Configuration & Reboot:** Modify flight controller parameters on the fly (`write_parameter`), adjust telemetry message streaming rates (`set_msg_rate`), or trigger an autopilot reboot (`reboot`).
|
|
77
|
+
- 🛡️ **Built-in Safety Switches:** Instantly inhibit physical flight commands (`allow_actions = False`) or abort all blocking waits across threads (`mission_ended = True`).
|
|
78
|
+
|
|
79
|
+
### 📐 Advanced Position and Geographic Utility
|
|
80
|
+
|
|
81
|
+
Utilize powerful built-in mathematical functions for complex navigation and coordinate system management:
|
|
82
|
+
- 📍 **Home Position Management:** Request and retrieve the designated HOME position (`request_home_position`, `home_position`) and set a new HOME location (`set_home`, `set_home_current_pos`).
|
|
83
|
+
- 🌍 **EKF Origin:** Get or set the EKF origin location (`ekf_origin`, `set_ekf_origin`) for accurate local navigation initialization.
|
|
84
|
+
- 📏 **Distance Calculation:** Calculate 2D/3D distances between the flight controller and a specified GPS point (`get_distance_with_gps_pos`) or local coordinate point (`get_distance_with_local_pos`).
|
|
85
|
+
- 🔄 **Coordinate Conversion Utilities:** Perform geometric transformations, including Quaternion to Euler conversion (`quaternion_to_euler`), 2D/3D distances between arbitrary points (`distance_between_two_gps_points`, `distance_between_two_local_points`), Cartesian/polar projections to GPS coordinates (`cartesian_to_geographic_point`, `polar_to_geographic_point`), and GPS-to-Cartesian displacements (`geographic_to_cartesian_point`).
|
|
86
|
+
|
|
87
|
+
### ⚙️ Mission Planning and Waypoint Management
|
|
88
|
+
|
|
89
|
+
Simplify the workflow for designing and executing automated `AUTO` missions:
|
|
90
|
+
- 🔢 **Waypoint Management:** Clear stored missions (`clear_waypoints`), announce waypoint counts (`send_waypoint_count`), and upload individual mission items (`send_waypoint`).
|
|
91
|
+
- ▶️ **Mission Execution:** Start the loaded mission from the ground or in flight (`start_mission`).
|
|
92
|
+
- ✅ **Mission Status:** Check the active waypoint sequence number (`current_waypoint_seq`) and verify if the waypoint mission is completed (`is_waypoint_mission_completed`).
|
|
93
|
+
|
|
94
|
+
### 📸 Gimbal and Payload Control
|
|
95
|
+
|
|
96
|
+
Integrated support for controlling camera gimbals and servo peripherals:
|
|
97
|
+
- 🖼️ **Angle & Rate Control:** Orient the gimbal precisely by setting pitch/yaw angles, rotation speeds, and reference frames (`set_gimbal_angles`), or read current gimbal orientation (`gimbal_angles`).
|
|
98
|
+
- 📌 **ROI Position Targeting:** Command the gimbal to track a specific GPS coordinate (`set_gimbal_target`).
|
|
99
|
+
- 🔌 **Gimbal Modes:** Set the gimbal to retract mode (`set_gimbal_retract`) or neutral position (`set_gimbal_neutral`).
|
|
100
|
+
- 📏 **Servo Control:** Actuate any servo channel (`set_servo`) and read live PWM outputs (`servo_pwm`).
|
|
101
|
+
|
|
102
|
+
### 🔔 Asynchronous Communication, Callbacks & Logging
|
|
103
|
+
|
|
104
|
+
Dedicated handler classes simplify listening for and sending custom messages:
|
|
105
|
+
- 📼 **Automatic `.tlog` Flight Logging:** Automatically records all incoming and outgoing MAVLink packets into a standard `.tlog` binary file (`MavLogger`), ready for replay in Mission Planner or QGroundControl.
|
|
106
|
+
- 💬 **Status Text Handling:** Automatically reassemble multi-chunk `STATUSTEXT` messages (`StatustextReceiver`, `last_statustext_from_sysidcompid`) and send chunked status texts (`send_statustext`).
|
|
107
|
+
- 🕰️ **Latency Monitoring:** Broadcast `TIMESYNC` requests (`send_timesync`) and monitor one-way link latency (`get_latence_ms_with_sysidcompid`).
|
|
108
|
+
- 📢 **Mission Control Codes (MCC):** Define, send, check, and delete custom named integer codes (`MCC`, `send_mcc`, `check_mcc`, `delete_mcc`, `send_named_value_int`) for multi-agent or GCS-to-companion synchronization.
|
|
109
|
+
- ⚡ **Event Callbacks:** Register custom callbacks for incoming messages (`set_additional_recv_msg_callback`), outgoing messages (`set_additional_send_callback`), complete status texts (`set_statustext_callback`), or MCC events (`set_mcc_callback`).
|
|
110
|
+
|
|
111
|
+
### ⏳ Synchronized Wait Operations
|
|
112
|
+
|
|
113
|
+
Implement robust, blocking operations with timeout and abort support:
|
|
114
|
+
- 🔒 **Arming Synchronization:** Wait until motors are confirmed armed or disarmed (`wait_motors_armed`, `wait_motors_disarmed`).
|
|
115
|
+
- ✈️ **Mode Synchronization:** Wait for a flight mode transition to complete (`wait_mode_changed`).
|
|
116
|
+
- 📍 **Navigation Synchronization:** Wait for a 3D GPS fix (`wait_gps_3d_fix`), HOME position reception (`wait_for_home`), or target proximity in GPS/local coordinates (`wait_proximity_with_gps_pos`, `wait_proximity_with_local_pos`).
|
|
117
|
+
- 📝 **Command & Mission Acknowledgments:** Block execution until a specific `COMMAND_ACK` or `MISSION_ACK` is received and validated (`wait_command_ack`, `wait_mission_ack`).
|
|
118
|
+
|
|
119
|
+
***
|
|
120
|
+
|
|
121
|
+
## 🛠️ Tech Stack & Architecture
|
|
122
|
+
|
|
123
|
+
pyMAVLinCS is designed as a focused Python library, utilizing proven components for reliable aerospace communication and data processing.
|
|
124
|
+
|
|
125
|
+
| Technology | Purpose | Why it was Chosen |
|
|
126
|
+
| :--- | :--- | :--- |
|
|
127
|
+
| **Python (>=3.10)** | Primary development language for the API. | Provides clean type-annotated syntax ideal for robotics and embedded companion computers. |
|
|
128
|
+
| **pymavlink** | Core dependency for MAVLink protocol communication. | Standard library for parsing, packing, and transmitting MAVLink 2 messages. |
|
|
129
|
+
| **geopy** | Dependency for geographic calculations. | Provides accurate geodesics for distance, bearing, and coordinate projection. |
|
|
130
|
+
| **colorama** | Terminal output formatting. | Enables color-coded severity levels in the built-in console logger. |
|
|
131
|
+
| **pytest** | Testing framework for unit and SITL integration tests. | Powers automated continuous integration against ArduPilot SITL. |
|
|
132
|
+
|
|
133
|
+
***
|
|
134
|
+
|
|
135
|
+
## 📁 Project Structure
|
|
136
|
+
|
|
137
|
+
The project structure separates the core MAVLink interface, supporting utility classes, usage examples, and automated SITL tests.
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
📂 pyMAVLinCS/
|
|
141
|
+
├── 📂 pyMAVLinCS/ # Core Library Package
|
|
142
|
+
│ ├── 📄 __init__.py # Main entry point (MAVLinCS class definition)
|
|
143
|
+
│ ├── 📄 mavecstra.py # Threading, TimesyncHandler, StatustextReceiver, MavLogger
|
|
144
|
+
│ ├── 📄 mavtypes.py # Typed data models (GPSPosition, Angles, Speed, etc.)
|
|
145
|
+
│ ├── 📄 mission_control_code.py # Class definition for MCC (Missio Control Code)
|
|
146
|
+
│ └── 📄 setup_logger.py # Logging setup utility and custom console/file formatters
|
|
147
|
+
├── 📂 examples/ # Demonstrative usage scripts
|
|
148
|
+
│ ├── 📄 01_basic_takeoff_and_land.py # Pre-flight telemetry, arming, takeoff, and landing
|
|
149
|
+
│ ├── 📄 02_guided_navigation_and_velocity.py # Local NED, GPS polar projection, velocity circle, RTL
|
|
150
|
+
│ ├── 📄 03_autonomous_waypoint_mission.py # Building, uploading, and monitoring AUTO missions
|
|
151
|
+
│ └── 📄 04_custom_mcc_and_callbacks.py # Custom MCCs, asynchronous callbacks, and TIMESYNC
|
|
152
|
+
├── 📂 tests/ # Automated test suite (Unit & ArduPilot SITL)
|
|
153
|
+
│ ├── 📄 conftest.py # Pytest configuration and automated SITL fixtures
|
|
154
|
+
│ ├── 📄 test_01_unit_offline.py # Offline geometry, math, MCC, and safety guard tests
|
|
155
|
+
│ ├── 📄 test_02_telemetry_comms.py # Telemetry getters, HOME, TIMESYNC, callbacks, and params
|
|
156
|
+
│ ├── 📄 test_03_flight_guided.py # Full GUIDED flight test (takeoff, NED, GPS, speed, servo)
|
|
157
|
+
│ └── 📄 test_04_missions_auto.py # In-air and ground-start AUTO waypoint mission tests
|
|
158
|
+
├── 📂 .github/ # GitHub configuration
|
|
159
|
+
│ └── 📂 workflows/ # Continuous Integration & Delivery workflows
|
|
160
|
+
│ ├── 📄 test.yml # CI workflow (pytest against ArduPilot SITL master)
|
|
161
|
+
│ └── 📄 publish.yml # CD workflow for PyPI package publication
|
|
162
|
+
├── 📄 pytest.ini # Pytest configuration file
|
|
163
|
+
├── 📄 pyproject.toml # Project metadata, dependencies, and build requirements
|
|
164
|
+
├── 📄 LICENSE # Project License (GPL-3.0-or-later)
|
|
165
|
+
├── 📄 README.md # Project documentation (this file)
|
|
166
|
+
└── 📄 .gitignore # Git ignore rules
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
***
|
|
170
|
+
|
|
171
|
+
## ⚙️ Getting Started
|
|
172
|
+
|
|
173
|
+
### Prerequisites
|
|
174
|
+
|
|
175
|
+
Ensure you have the following installed:
|
|
176
|
+
- **Python:** Version **3.10** or higher (`>=3.10` is required).
|
|
177
|
+
- **A MAVLink-compatible flight controller or simulator** (e.g., ArduPilot SITL, PX4, Pixhawk, Cube).
|
|
178
|
+
- **A communication link** (e.g., UDP, TCP, USB/Serial telemetry radio).
|
|
179
|
+
|
|
180
|
+
### Installation
|
|
181
|
+
|
|
182
|
+
1. **Install the library using pip:**
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
pip install pyMAVLinCS
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
2. **Verify installation:**
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from pyMAVLinCS import MAVLinCS
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
***
|
|
195
|
+
|
|
196
|
+
## 🎯 Usage
|
|
197
|
+
|
|
198
|
+
pyMAVLinCS is used by instantiating the `MAVLinCS` class with your connection address. The instance automatically opens the link, waits for a valid `HEARTBEAT`, configures telemetry rates, starts the background `MavThread`, and begins recording a `.tlog` file.
|
|
199
|
+
|
|
200
|
+
### 1. Establishing a Connection
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from pyMAVLinCS import MAVLinCS
|
|
204
|
+
|
|
205
|
+
# Example 1: Connect via UDP to an ArduPilot SITL / GCS endpoint
|
|
206
|
+
drone = MAVLinCS(
|
|
207
|
+
address="udpin:127.0.0.1:14550",
|
|
208
|
+
mavlogfile="flight.tlog",
|
|
209
|
+
timeout_heartbeat=10,
|
|
210
|
+
pos_rate=4
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# Example 2: Connect via Serial (replace /dev/ttyACM0 with your serial port)
|
|
214
|
+
# drone = MAVLinCS(address="/dev/ttyACM0", baud=57600)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 2. Performing Autonomous Actions (Control)
|
|
218
|
+
|
|
219
|
+
Execute flight commands with built-in acknowledgment and state verification:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
try:
|
|
223
|
+
# Wait for the drone to achieve a 3D GPS fix before proceeding
|
|
224
|
+
drone.logger.info("Waiting for 3D GPS Fix...")
|
|
225
|
+
if not drone.wait_gps_3d_fix(timeout=30):
|
|
226
|
+
raise RuntimeError("GPS 3D Fix timeout.")
|
|
227
|
+
|
|
228
|
+
# Arm the drone (automatically switches to GUIDED mode if needed on ArduPilot)
|
|
229
|
+
if not drone.arm(timeout_arming=10):
|
|
230
|
+
raise RuntimeError("Drone failed to arm.")
|
|
231
|
+
|
|
232
|
+
# Execute a takeoff to 10 meters (waits until target altitude is reached)
|
|
233
|
+
if not drone.takeoff(altitude=10.0, precision=0.5, timeout_takeoff=30):
|
|
234
|
+
raise RuntimeError("Drone takeoff failed.")
|
|
235
|
+
|
|
236
|
+
# Land safely and wait for motors to disarm
|
|
237
|
+
drone.land(timeout_land=60)
|
|
238
|
+
except KeyboardInterrupt:
|
|
239
|
+
drone.mission_ended = True
|
|
240
|
+
finally:
|
|
241
|
+
drone.close()
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 3. Retrieving Real-Time Telemetry
|
|
245
|
+
|
|
246
|
+
Access structured `NamedTuple` data models defining the vehicle's state:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
# Get current GPS position and local NED position
|
|
250
|
+
gps_pos = drone.position_gps()
|
|
251
|
+
local_pos = drone.position_local()
|
|
252
|
+
|
|
253
|
+
print("\n--- Telemetry Snapshot ---")
|
|
254
|
+
print(f"Lat: {gps_pos.lat:.6f}°, Lon: {gps_pos.lon:.6f}°")
|
|
255
|
+
print(f"Relative Alt: {gps_pos.relative_alt:.2f}m | Alt (MSL): {gps_pos.alt:.2f}m")
|
|
256
|
+
print(f"Local NED -> North: {local_pos.x:.2f}m, East: {local_pos.y:.2f}m, Down: {local_pos.z:.2f}m")
|
|
257
|
+
|
|
258
|
+
# Get attitude angles (roll, pitch, yaw in radians)
|
|
259
|
+
angles = drone.angles()
|
|
260
|
+
print(f"Roll: {angles.roll:.2f} rad, Pitch: {angles.pitch:.2f} rad, Yaw: {angles.yaw:.2f} rad")
|
|
261
|
+
|
|
262
|
+
# Check battery status
|
|
263
|
+
print(f"Battery: {drone.battery_percentage()}% ({drone.battery_voltage():.2f}V)")
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 4. Mission Control Codes (MCC) & Callbacks
|
|
267
|
+
|
|
268
|
+
pyMAVLinCS provides Mission Control Codes (`MCC`) to simplify event synchronization between ground stations and companion computers over MAVLink (`NAMED_VALUE_INT`):
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from pyMAVLinCS import MAVLinCS, MCC
|
|
272
|
+
|
|
273
|
+
# Define a custom Mission Control Code
|
|
274
|
+
DRONE_READY = MCC(
|
|
275
|
+
value=1,
|
|
276
|
+
name="DRONE_READY",
|
|
277
|
+
level="SUCCESS",
|
|
278
|
+
description="Drone initialized and ready for mission."
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
drone = MAVLinCS(address="udpin:127.0.0.1:14550")
|
|
282
|
+
|
|
283
|
+
# Register a callback triggered whenever an MCC is received
|
|
284
|
+
drone.set_mcc_callback(lambda mcc: print(f"Received MCC: {mcc}"))
|
|
285
|
+
|
|
286
|
+
# Send, check, and delete an MCC
|
|
287
|
+
drone.send_mcc(DRONE_READY)
|
|
288
|
+
if drone.check_mcc(DRONE_READY):
|
|
289
|
+
drone.delete_mcc(DRONE_READY)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### 5. Closing the Connection
|
|
293
|
+
|
|
294
|
+
Always close the connection when finished to cleanly stop the background `MavThread`, close the serial/UDP link, and flush the `.tlog` file:
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
drone.close()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
***
|
|
301
|
+
|
|
302
|
+
## 🤝 Contributing
|
|
303
|
+
|
|
304
|
+
We welcome contributions to improve pyMAVLinCS! Your input helps make this project a more robust and reliable tool for autonomous vehicle development.
|
|
305
|
+
|
|
306
|
+
### How to Contribute
|
|
307
|
+
|
|
308
|
+
1. **Fork the repository:** Click the 'Fork' button at the top right of this page.
|
|
309
|
+
2. **Create a feature branch:**
|
|
310
|
+
```bash
|
|
311
|
+
git checkout -b feature/new-telemetry-endpoint
|
|
312
|
+
```
|
|
313
|
+
3. **Make your changes:** Improve code, documentation, or features within the `pyMAVLinCS/` directory.
|
|
314
|
+
4. **Test thoroughly:** Ensure all existing and new functionality works as expected. Automated tests run on push and PR via GitHub Actions using ArduPilot SITL. You can run the test suite locally with `pytest`:
|
|
315
|
+
```bash
|
|
316
|
+
# Run the automated test suite:
|
|
317
|
+
pytest tests/ -v -s
|
|
318
|
+
|
|
319
|
+
# Or execute an example script:
|
|
320
|
+
python examples/01_basic_takeoff_and_land.py
|
|
321
|
+
```
|
|
322
|
+
5. **Commit your changes:** Write clear, descriptive commit messages.
|
|
323
|
+
```bash
|
|
324
|
+
git commit -m "Fix: Corrected latency calculation in TimesyncHandler"
|
|
325
|
+
```
|
|
326
|
+
6. **Push to your branch:**
|
|
327
|
+
```bash
|
|
328
|
+
git push origin feature/new-telemetry-endpoint
|
|
329
|
+
```
|
|
330
|
+
7. **Open a Pull Request:** Submit your changes for review by the maintainers.
|
|
331
|
+
|
|
332
|
+
### Development Guidelines
|
|
333
|
+
|
|
334
|
+
- ✅ Follow the existing Python code style and type-hinting conventions (` PEP 8 `).
|
|
335
|
+
- 📝 Add comprehensive docstrings and comments for complex logic, especially within `MAVLinCS` and `mavecstra.py`.
|
|
336
|
+
- 🧪 Whenever possible, ensure changes are verified against ArduPilot/PX4 SITL or real hardware.
|
|
337
|
+
- 📚 Update documentation, including the `README.md`, for any changed functionality or new public methods.
|
|
338
|
+
- 🔄 Ensure backward compatibility when modifying existing API calls.
|
|
339
|
+
- 🎯 Keep commits focused and atomic, addressing a single feature or bug fix per commit.
|
|
340
|
+
|
|
341
|
+
***
|
|
342
|
+
|
|
343
|
+
## 📝 License
|
|
344
|
+
|
|
345
|
+
This project is licensed under the **GPL-3.0-or-later** license - see the [LICENSE](LICENSE) file for complete details.
|
|
346
|
+
|
|
347
|
+
### What this means:
|
|
348
|
+
|
|
349
|
+
- ✅ **Commercial Use:** You can use this software for commercial purposes.
|
|
350
|
+
- ✅ **Modification:** You can modify the code.
|
|
351
|
+
- ✅ **Distribution:** You can distribute this software.
|
|
352
|
+
- ✅ **Private Use:** You can use this project privately.
|
|
353
|
+
- ✅ **Patent Use:** You are granted rights to use patents related to the software.
|
|
354
|
+
- ⚠️ **Source Code Disclosure:** If you distribute modified versions of this software, you must disclose the source code under the same `GPL v3` license terms.
|
|
355
|
+
- ⚠️ **Warranty:** The software is provided "as is," without warranty of any kind.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
<p align="center">
|
|
360
|
+
<a href="#-table-of-contents">⬆️ Back to Top</a>
|
|
361
|
+
</p>
|