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.
RouteCreation_CSV2Yaml.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright (C) 2017-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
18# This script can be used to convert csv files into route files for use in the CARMA platform
19# Currently only lat,lon, and speed limit are supported fields
20# To Run:
21# python routeFileFromCSVScript.py <csv_file> <yaml_file> <route_name>
22# Example:
23# c:\Python27\python routeFileFromCSVScript.py ATC_city_1_20m_waypoints.csv exampleRoute.yaml ExampleRoute
24import csv
25import sys
26
27# Function generates a yaml block representing a waypoint with the specified lat,lon, and speedlimit
28def waypointAsYAMLString(lat, lon, speedLimit):
29 return (
30 ' - !gov.dot.fhwa.saxton.carma.route.RouteWaypoint\n'
31 ' location: !gov.dot.fhwa.saxton.carma.geometry.geodesic.Location\n'
32 ' latitude: ' + str(lat) + '\n'
33 ' longitude: ' + str(lon) + '\n'
34 ' altitude: 0.0\n'
35 ' minCrossTrack: -10.0\n'
36 ' maxCrossTrack: 10.0\n'
37 ' lowerSpeedLimit: 0\n'
38 ' upperSpeedLimit: ' + str(speedLimit) + '\n'
39 ' laneCount: 1\n'
40 ' interiorLaneMarkings: SOLID_WHITE\n'
41 ' leftMostLaneMarking: SOLID_YELLOW\n'
42 ' rightMostLaneMarking: SOLID_WHITE\n'
43 '\n'
44 )
45
46# Main function which converts the provided csv file to the specified route file
47def convertCSVToRouteFile(csvPath, routeFilePath, routeName):
48 print('Converting csv file to route file...')
49 with open(csvPath, 'rb') as csvfile: # Open csv file
50 with open(routeFilePath, 'wb') as yamlfile: # Open yaml file
51 waypoint_reader = csv.reader(csvfile, delimiter=',')
52 # Write header
53 yamlfile.write('!gov.dot.fhwa.saxton.carma.route.Route' + '\n')
54 yamlfile.write('routeName: ' + routeName + '\n')
55 yamlfile.write('maxJoinDistance: ' + '40.0' + '\n')
56 yamlfile.write('waypoints:\n')
57 latIndex = 2
58 lonIndex = 3
59 speedLimitIndex = 4
60 firstLine = True
61 for row in waypoint_reader:
62 if (firstLine): # Find needed column index and skip header row
63 index = 0
64 for col_name in row:
65 if (col_name == 'Latitude'):
66 latIndex = index
67 elif (col_name == 'Longitude'):
68 lonIndex = index
69 elif (col_name == 'Speed'):
70 speedLimitIndex = index
71 index += 1
72 firstLine = False
73 continue
74 lat = float(row[latIndex])
75 lon = float(row[lonIndex])
76 speedLimit = int(row[speedLimitIndex])
77 # Write waypoint to file
78 yamlfile.write(waypointAsYAMLString(lat,lon,speedLimit))
79
80 print('Done converting csv file to route file')
81
82# Main execution
83if __name__ == "__main__":
84
85 # Check if all arguments are provided
86 if (len(sys.argv) <= 3):
87 print('Please rerun with command line arguments <input csv file path> <output route yaml file path> <route name>')
88 else: # Run the converter
89 convertCSVToRouteFile(sys.argv[1], sys.argv[2], sys.argv[3])
def waypointAsYAMLString(lat, lon, speedLimit)
def convertCSVToRouteFile(csvPath, routeFilePath, routeName)