-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ADSB selected the most dangerous vehicle by CPA calculation #11346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
error414
wants to merge
5
commits into
iNavFlight:maintenance-10.x
Choose a base branch
from
error414:error414/feature/adsb-intercept-calc
base: maintenance-10.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6de9355
* add ADSB simulator script to inject ADSB contact to FC for devel pu…
error414 dbc5c63
fix documentation: update ADS-B
error414 cca5ea5
fix CPA calculation
error414 5669e50
update_cli_docs
error414 36e2c23
add testes for ADSB
error414 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import json | ||
| import time | ||
| import argparse | ||
| import serial | ||
| from pymavlink.dialects.v20 import common as mavlink2 | ||
|
|
||
| def load_aircraft(json_file): | ||
| with open(json_file, "r") as f: | ||
| return json.load(f) | ||
|
|
||
| def create_mavlink(serial_port): | ||
| mav = mavlink2.MAVLink(serial_port) | ||
| mav.srcSystem = 1 | ||
| mav.srcComponent = mavlink2.MAV_COMP_ID_ADSB | ||
| return mav | ||
|
|
||
| def send_heartbeat(mav): | ||
| mav.heartbeat_send( | ||
| mavlink2.MAV_TYPE_ADSB, | ||
| mavlink2.MAV_AUTOPILOT_INVALID, | ||
| 0, | ||
| 0, | ||
| 0 | ||
| ) | ||
|
|
||
| def send_adsb(mav, aircraft): | ||
| for ac in aircraft: | ||
| icao = int(ac["icao_address"]) | ||
| lat = int(ac["lat"] * 1e7) | ||
| lon = int(ac["lon"] * 1e7) | ||
| alt_mm = int(ac["altitude"] * 1000) | ||
| heading_cdeg = int(ac["heading"] * 100) | ||
| hor_vel_cms = int(ac["hor_velocity"] * 100) | ||
| ver_vel_cms = int(ac["ver_velocity"] * 100) | ||
| callsign = ac["callsign"].encode("ascii").ljust(9, b'\x00') | ||
|
|
||
| msg = mavlink2.MAVLink_adsb_vehicle_message( | ||
| ICAO_address=icao, | ||
| lat=lat, | ||
| lon=lon, | ||
| altitude_type=0, | ||
| altitude=alt_mm, | ||
| heading=heading_cdeg, | ||
| hor_velocity=hor_vel_cms, | ||
| ver_velocity=ver_vel_cms, | ||
| callsign=callsign, | ||
| emitter_type=0, | ||
| tslc=1, | ||
| flags=3, | ||
| squawk=0 | ||
| ) | ||
|
|
||
| mav.send(msg) | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("com_port") | ||
| parser.add_argument("json_file") | ||
| parser.add_argument("--baud", default=115200, type=int) | ||
| parser.add_argument("--rate", default=1.0, type=float) | ||
| args = parser.parse_args() | ||
|
|
||
| ser = serial.Serial(args.com_port, args.baud) | ||
| mav = create_mavlink(ser) | ||
|
|
||
| aircraft = load_aircraft(args.json_file) | ||
|
|
||
| period = 1.0 / args.rate | ||
| last_hb = 0 | ||
|
error414 marked this conversation as resolved.
|
||
|
|
||
| while True: | ||
| now = time.time() | ||
|
|
||
| if now - last_hb >= 1.0: | ||
| send_heartbeat(mav) | ||
| last_hb = now | ||
|
|
||
| send_adsb(mav, aircraft) | ||
| time.sleep(period) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| [ | ||
| { | ||
| "icao_address": 1002, | ||
| "lat": 49.2341564, | ||
| "lon": 16.5505527, | ||
| "altitude": 300, | ||
| "heading": 275, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V550" | ||
| }, | ||
| { | ||
| "icao_address": 1001, | ||
| "lat": 49.2344299, | ||
| "lon": 16.5610206, | ||
| "altitude": 300, | ||
| "heading": 237, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V250" | ||
| }, | ||
| { | ||
| "icao_address": 1003, | ||
| "lat": 49.2422463, | ||
| "lon": 16.5645653, | ||
| "altitude": 300, | ||
| "heading": 29, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V1100" | ||
| }, | ||
| { | ||
| "icao_address": 1004, | ||
| "lat": 49.2377083, | ||
| "lon": 16.5520834, | ||
| "altitude": 300, | ||
| "heading": 110, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V650X3" | ||
| }, | ||
| { | ||
| "icao_address": 1005, | ||
| "lat": 49.2388158, | ||
| "lon": 16.5730266, | ||
| "altitude": 300, | ||
| "heading": 261, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V1250X4" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # ADSB Vehicle MAVLink Simulator | ||
|
|
||
| A Python tool for simulating ADS-B aircraft traffic over a serial connection using the MAVLink protocol. Useful for testing ADS-B receivers, ground station software, or flight controller integrations without real aircraft. | ||
|
|
||
| --- | ||
|
|
||
| ## Requirements | ||
| ```bash | ||
| pip install pymavlink pyserial | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Usage | ||
| ```bash | ||
| python adsb_uart_sender.py <com_port> <json_file> [--baud BAUD] [--rate RATE] | ||
| ``` | ||
|
error414 marked this conversation as resolved.
|
||
|
|
||
| ### Arguments | ||
|
|
||
| | Argument | Required | Default | Description | | ||
| |---|---|---|---| | ||
| | `com_port` | ✅ | — | Serial port (e.g. `COM3`, `/dev/ttyUSB0`) | | ||
| | `json_file` | ✅ | — | Path to JSON file with aircraft definitions | | ||
| | `--baud` | ❌ | `115200` | Serial baud rate | | ||
| | `--rate` | ❌ | `1.0` | Update rate in Hz | | ||
|
|
||
| ### Examples | ||
| ```bash | ||
| # Windows | ||
| python adsb_uart_sender.py COM3 aircraft.json | ||
|
|
||
| # Linux | ||
| python adsb_uart_sender.py /dev/ttyUSB0 aircraft.json --baud 57600 --rate 2.0 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Aircraft JSON Format | ||
|
|
||
| Each aircraft is defined as an object in a JSON array: | ||
| ```json | ||
| [ | ||
| { | ||
| "icao_address": 1001, | ||
| "lat": 49.2344299, | ||
| "lon": 16.5610206, | ||
| "altitude": 300, | ||
| "heading": 237, | ||
| "hor_velocity": 30, | ||
| "ver_velocity": 0, | ||
| "callsign": "V250" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| | Field | Type | Unit | Description | | ||
| |---|---|---|---| | ||
| | `icao_address` | int | — | Unique ICAO identifier | | ||
| | `lat` | float | degrees | Latitude | | ||
| | `lon` | float | degrees | Longitude | | ||
| | `altitude` | float | meters ASL | Altitude above sea level | | ||
| | `heading` | float | degrees (0–360) | Track heading | | ||
| | `hor_velocity` | float | m/s | Horizontal speed | | ||
| | `ver_velocity` | float | m/s | Vertical speed (positive = climb) | | ||
| | `callsign` | string | — | Aircraft callsign (max 8 chars) | | ||
|
|
||
| --- | ||
|
|
||
| ## How It Works | ||
|
|
||
| The simulator connects to a serial port and continuously transmits two MAVLink message types: | ||
|
|
||
| - **HEARTBEAT** — sent once per second to identify the component as an ADS-B device | ||
| - **ADSB_VEHICLE** — sent for each aircraft at the configured rate, containing position, velocity, heading and identification data | ||
|
|
||
| All aircraft from the JSON file are broadcast in every update cycle. The positions are static — aircraft do not move between updates. | ||
|
|
||
| --- | ||
|
|
||
| ## Notes | ||
|
|
||
| - Altitude is transmitted in millimeters internally (`altitude * 1000`) as required by the MAVLink `ADSB_VEHICLE` message spec | ||
| - Heading is transmitted in centidegrees (`heading * 100`) | ||
| - Callsigns are ASCII-encoded and null-padded to 9 bytes | ||
| - `flags` is set to `3` (lat/lon and altitude valid) | ||
| - `tslc` (time since last communication) is hardcoded to `1` second | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.