Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
reverse_waypoints.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3# Copyright (C) 2018-2021 LEIDOS.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17# This script can be used to reverse all waypoints order from a CARMA route file
18# To Run:
19# Create a text file and only copy and paste lines after 'waypoints:'
20# Add an empty line at the start of the file
21# Run "python reverse_waypoints.py <file_name>" to get a text file with reversed points
22
23import sys
24
25def main():
26 filepath = sys.argv[1]
27 waypoints = []
28 with open(filepath, 'r') as fp:
29 line = fp.readline()
30 counter = 0
31 while line:
32 if len(line) == 1:
33 counter += 1
34 waypoint = []
35 waypoint.append(line)
36 waypoints.append(waypoint)
37 else:
38 waypoints[counter - 1].append(line)
39 line = fp.readline()
40 print("Processed %d waypoints" % len(waypoints))
41 output_path = filepath + '_output'
42 with open(output_path, 'w') as fp:
43 for wp in reversed(waypoints):
44 for line in wp:
45 fp.write(line)
46 print("Done!")
47
48if __name__ == "__main__":
49 print("Running ReverseWaypoints.py...")
50 main()