Skip to content

Commit 1871ffa

Browse files
authored
Merge pull request #561 from farhangnaderi/pr-examples-upload-params
Examples: Add files via upload
2 parents 29f2502 + 31b12f6 commit 1871ffa

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

examples/upload_params.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
3+
import asyncio
4+
import argparse
5+
from mavsdk import System
6+
from tqdm import tqdm
7+
8+
9+
def main():
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument(
12+
"connection",
13+
help="Connection string (e.g. udp://:14540)")
14+
parser.add_argument(
15+
"param_file", help="Param file to be uploaded with .params format")
16+
17+
args = parser.parse_args()
18+
19+
asyncio.run(set_params(args))
20+
21+
22+
async def set_params(args):
23+
drone = System()
24+
await drone.connect(system_address=args.connection)
25+
print("Connected to the Vehicle")
26+
param_plugin = drone.param
27+
params = await param_plugin.get_all_params()
28+
float_params = params.float_params
29+
int_params = params.int_params
30+
custom_params = params.custom_params
31+
int_param_names = [p.name for p in int_params]
32+
float_param_names = [p.name for p in float_params]
33+
custom_param_names = [p.name for p in custom_params]
34+
35+
async for is_in_air in drone.telemetry.in_air():
36+
if is_in_air:
37+
print("Waiting until vehicle is landed...")
38+
else:
39+
break
40+
41+
with open(args.param_file, "r") as param_file:
42+
print("Uploading Parameters... Please do not arm the vehicle!")
43+
for line in tqdm(param_file, unit='lines'):
44+
if line.startswith("#"):
45+
continue
46+
47+
columns = line.strip().split("\t")
48+
vehicle_id = columns[0]
49+
component_id = columns[1]
50+
name = columns[2]
51+
value = columns[3]
52+
type = columns[4]
53+
if name in int_param_names:
54+
await drone.param.set_param_int(name, int(value))
55+
elif name in float_param_names:
56+
await drone.param.set_param_float(name, float(value))
57+
elif name in custom_param_names:
58+
await drone.param.set_param_custom(name, value)
59+
60+
print("Params uploaded!")
61+
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)