forked from Auterion/px4-simulation-ignition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d889d93
commit 34d3ebe
Showing
27 changed files
with
294,648 additions
and
594 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 |
---|---|---|
@@ -1,10 +1,21 @@ | ||
#!/bin/bash | ||
|
||
# present working directory | ||
PWD=$(pwd) | ||
|
||
# Clone c_library_v2 commit matching with current px4-firmware mavlink commit | ||
# => mavlink/c_library_v2:fbdb7c29 is built from mavlink/mavlink:08112084 | ||
git clone -q https://github.com/mavlink/c_library_v2.git ${PWD}/mavlink && \ | ||
cd ${PWD}/mavlink && git checkout -q fbdb7c29e47902d44eeaa58b4395678a9b78f3ae && \ | ||
rm -rf ${PWD}/mavlink/.git && cd ${PWD} | ||
|
||
export _MAVLINK_INCLUDE_DIR=${PWD}/mavlink | ||
|
||
|
||
if [ ! -e build ]; then | ||
mkdir build | ||
fi | ||
cd build | ||
cmake .. | ||
make | ||
cpack -G DEB | ||
|
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
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
Binary file not shown.
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,87 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
import jinja2 | ||
import argparse | ||
import os | ||
import shutil | ||
import fnmatch | ||
import numpy as np | ||
|
||
|
||
def get_file_contents(filepath): | ||
with open(filepath, 'rb') as f: | ||
return f.read() | ||
|
||
def str2bool(v): | ||
if v.lower() in ('yes', 'true', 't', 'y', '1'): | ||
return True | ||
elif v.lower() in ('no', 'false', 'f', 'n', '0'): | ||
return False | ||
else: | ||
raise argparse.ArgumentTypeError('Boolean value expected.') | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filename', help="file that the sdf file should be generated from") | ||
parser.add_argument('env_dir') | ||
parser.add_argument('--output-file', help="sdf output file") | ||
parser.add_argument('--stdout', action='store_true', default=False, help="dump to stdout instead of file") | ||
parser.add_argument('--vehicle_name', default="ssrc_fog_x", help="Name of the vehicle") | ||
parser.add_argument('--mavlink_addr', default="127.0.0.1", help='Address of PX4 mavlink receiver') | ||
parser.add_argument('--mavlink_udp_local_port', default="14540", help='listening UDP port of mavlink plugin') | ||
parser.add_argument('--mavlink_udp_remote_port', default="14541", help='UDP port of PX4 mavlink receiver') | ||
parser.add_argument('--mavlink_tcp_port', default="4560", help='TCP port of PX4 mavlink receiver') | ||
|
||
args = parser.parse_args() | ||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(args.env_dir)) | ||
template = env.get_template(os.path.relpath(args.filename, args.env_dir)) | ||
|
||
# create dictionary with useful modules etc. | ||
try: | ||
import rospkg | ||
rospack = rospkg.RosPack() | ||
except ImportError: | ||
pass | ||
rospack = None | ||
|
||
d = {'np': np, 'rospack': rospack, \ | ||
'vehicle_name': args.vehicle_name, \ | ||
'mavlink_addr': args.mavlink_addr, \ | ||
'mavlink_udp_local_port': args.mavlink_udp_local_port, \ | ||
'mavlink_udp_remote_port': args.mavlink_udp_remote_port, \ | ||
'mavlink_tcp_port': args.mavlink_tcp_port} | ||
|
||
result = template.render(d) | ||
|
||
if args.stdout: | ||
print(result) | ||
|
||
else: | ||
if args.output_file: | ||
filename_out = args.output_file | ||
else: | ||
if not args.filename.endswith('.sdf.jinja'): | ||
raise Exception("ERROR: Output file can only be determined automatically for " + \ | ||
"input files with the .sdf.jinja extension") | ||
filename_out = args.filename.replace('.sdf.jinja', '.sdf') | ||
assert filename_out != args.filename, "Not allowed to overwrite template" | ||
|
||
# Overwrite protection mechanism: after generation, the file will be copied to a "last_generated" file. | ||
# In the next run, we can check whether the target file is still unmodified. | ||
filename_out_last_generated = filename_out + '.last_generated' | ||
|
||
if os.path.exists(filename_out) and os.path.exists(filename_out_last_generated): | ||
# Check whether the target file is still unmodified. | ||
if get_file_contents(filename_out).strip() != get_file_contents(filename_out_last_generated).strip(): | ||
raise Exception("ERROR: generation would overwrite changes to `{}`. ".format(filename_out) + \ | ||
"Changes should only be made to the template file `{}`. ".format(args.filename) + \ | ||
"Remove `{}` ".format(os.path.basename(filename_out)) + \ | ||
"(after extracting your changes) to disable this overwrite protection.") | ||
|
||
with open(filename_out, 'w') as f_out: | ||
print(('{:s} -> {:s}'.format(args.filename, filename_out))) | ||
f_out.write(result) | ||
|
||
# Copy the contents to a "last_generated" file for overwrite protection check next time. | ||
shutil.copy(filename_out, filename_out_last_generated) |
Oops, something went wrong.