forked from johncarl81/dragonfly-controller
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
executable file
·77 lines (61 loc) · 2.71 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env python3
import argparse
import subprocess
import tempfile
import time
import os
from string import Template
def template(templateFileName, values):
fp = tempfile.NamedTemporaryFile(mode = "w")
result = Template(open(templateFileName).read()).substitute(values)
fp.write(result)
fp.seek(0)
return fp
def run(args):
processes = []
dragonfly_dir = "/home/ubuntu/dev/dragonfly"
env = os.environ.copy()
if args.cyclone_network:
cyclone_parameters = {'networkInterface': args.cyclone_network}
cyclone_dds_config = template(f"{dragonfly_dir}/templates/cyclonedds.xml.template", cyclone_parameters)
env['CYCLONEDDS_URI'] = f"file://{cyclone_dds_config.name}"
mavros_parameters = {
'name': args.name,
'sysid_thismav': args.sysid_thismav,
}
mavros_params = template(f"{dragonfly_dir}/templates/mavros.launch.yaml.template", mavros_parameters)
run_log = open(f"{dragonfly_dir}/logs/run.log", "a")
pump_log = open(f"{dragonfly_dir}/logs/pump.log", "a")
command_log = open(f"{dragonfly_dir}/logs/command.log", "a")
mavros_log = open(f"{dragonfly_dir}/logs/mavros.log", "a")
processes.append(subprocess.Popen(f"ros2 daemon start", env=env, shell=True))
time.sleep(10)
processes.append(subprocess.Popen(f"ros2 run mavros mavros_node --ros-args -r __ns:=/{args.name}/mavros --params-file {mavros_params.name}", env=env, shell=True, stdout=mavros_log, stderr=subprocess.STDOUT))
time.sleep(10)
processes.append(subprocess.Popen(f"ros2 run dragonfly virtualco2publisher {args.name}", env=env, shell=True))
processes.append(subprocess.Popen(f"ros2 run dragonfly co2publisher {args.name}", env=env, shell=True))
processes.append(subprocess.Popen(f"ros2 run dragonfly logger {args.name}", env=env, shell=True, stdout=run_log, stderr=subprocess.STDOUT))
processes.append(subprocess.Popen(f"ros2 run dragonfly pump {args.name}", env=env, shell=True, stdout=pump_log, stderr=subprocess.STDOUT))
processes.append(subprocess.Popen(f"ros2 run dragonfly command {args.name}", env=env, shell=True, stdout=command_log, stderr=subprocess.STDOUT))
processes.append(subprocess.Popen(f"ros2 run dragonfly announce {args.name}", env=env, shell=True))
for p in processes:
p.wait()
def get_args():
parser = argparse.ArgumentParser(description='Dragonfly controller')
parser.add_argument(
'--name',
type=str)
parser.add_argument(
'--sysid_thismav',
type=int)
parser.add_argument(
'--cyclone_network',
type=str,
default=None)
args = parser.parse_args()
return args
def main():
args = get_args()
run(args)
if __name__ == '__main__':
main()