-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from farhangnaderi/pr-examples-upload-params
Examples: Add files via upload
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,64 @@ | ||
#!/usr/bin/env python | ||
|
||
import asyncio | ||
import argparse | ||
from mavsdk import System | ||
from tqdm import tqdm | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"connection", | ||
help="Connection string (e.g. udp://:14540)") | ||
parser.add_argument( | ||
"param_file", help="Param file to be uploaded with .params format") | ||
|
||
args = parser.parse_args() | ||
|
||
asyncio.run(set_params(args)) | ||
|
||
|
||
async def set_params(args): | ||
drone = System() | ||
await drone.connect(system_address=args.connection) | ||
print("Connected to the Vehicle") | ||
param_plugin = drone.param | ||
params = await param_plugin.get_all_params() | ||
float_params = params.float_params | ||
int_params = params.int_params | ||
custom_params = params.custom_params | ||
int_param_names = [p.name for p in int_params] | ||
float_param_names = [p.name for p in float_params] | ||
custom_param_names = [p.name for p in custom_params] | ||
|
||
async for is_in_air in drone.telemetry.in_air(): | ||
if is_in_air: | ||
print("Waiting until vehicle is landed...") | ||
else: | ||
break | ||
|
||
with open(args.param_file, "r") as param_file: | ||
print("Uploading Parameters... Please do not arm the vehicle!") | ||
for line in tqdm(param_file, unit='lines'): | ||
if line.startswith("#"): | ||
continue | ||
|
||
columns = line.strip().split("\t") | ||
vehicle_id = columns[0] | ||
component_id = columns[1] | ||
name = columns[2] | ||
value = columns[3] | ||
type = columns[4] | ||
if name in int_param_names: | ||
await drone.param.set_param_int(name, int(value)) | ||
elif name in float_param_names: | ||
await drone.param.set_param_float(name, float(value)) | ||
elif name in custom_param_names: | ||
await drone.param.set_param_custom(name, value) | ||
|
||
print("Params uploaded!") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |