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.
speedharm_auto_configure Namespace Reference

Functions

def log (msg)
 
def print_response (resp)
 
def get_active_experiment_url ()
 
def create_experiment (desc, loc)
 
def assign_experiment (veh_id, experiment_url)
 
def get_registered_veh_data ()
 
def create_algorithm (algo_name)
 
def assign_algorithm (veh_id, algo_url)
 
def main ()
 

Variables

string version_id = "v0.1"
 
string base_url = "http://35.153.64.44:8081"
 
string vehicles_url = "/rest/vehicles"
 
string experiments_url = "/rest/experiments"
 
string algorithms_url = "/rest/algorithms"
 
string default_algorithm = "gov.dot.fhwa.saxton.speedharm.executive.algorithms.ReduceSpeedAlgorithm"
 
int sleep_duration_millis = 1000
 

Function Documentation

◆ assign_algorithm()

def speedharm_auto_configure.assign_algorithm (   veh_id,
  algo_url 
)

Definition at line 85 of file speedharm_auto_configure.py.

85def assign_algorithm(veh_id, algo_url):
86 headers = { "Content-Type" : "application/json" }
87 data = json.dumps({"id": int(veh_id)})
88 r = requests.post(urlparse.urljoin(algo_url + "/vehicles", ""), data=data, headers=headers, verify=False)
90
def assign_algorithm(veh_id, algo_url)

References print_response().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_experiment()

def speedharm_auto_configure.assign_experiment (   veh_id,
  experiment_url 
)

Definition at line 66 of file speedharm_auto_configure.py.

66def assign_experiment(veh_id, experiment_url):
67 headers = { "Content-Type" : "application/json" }
68 data = json.dumps({"id": int(veh_id)})
69 r = requests.post(urlparse.urljoin(experiment_url + "/vehicles", ""), data=data, headers=headers, verify=False)
70
def assign_experiment(veh_id, experiment_url)

Referenced by main().

Here is the caller graph for this function:

◆ create_algorithm()

def speedharm_auto_configure.create_algorithm (   algo_name)

Definition at line 76 of file speedharm_auto_configure.py.

76def create_algorithm(algo_name):
77 full_url = urlparse.urljoin(base_url, algorithms_url)
78 headers = { "Content-Type" : "application/json" }
79 data = json.dumps({"className": algo_name})
80
81 r = requests.post(full_url, data=data, headers=headers, verify=False)
83 return r.headers["Location"]
84

References print_response().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_experiment()

def speedharm_auto_configure.create_experiment (   desc,
  loc 
)

Definition at line 59 of file speedharm_auto_configure.py.

59def create_experiment(desc, loc):
60 full_url = urlparse.urljoin(base_url, experiments_url)
61 headers = { "Content-Type" : "application/json" }
62 r = requests.post(full_url, data=json.dumps({"description": desc, "location": loc}), headers=headers, verify=False)
64 return r.headers["Location"]
65

References print_response().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_active_experiment_url()

def speedharm_auto_configure.get_active_experiment_url ( )

Definition at line 51 of file speedharm_auto_configure.py.

52 r = requests.get(urlparse.urljoin(base_url, experiments_url), verify=False).json()
53 for exp in r:
54 if exp["description"].find("AUTO-CONFIG") > -1:
55 return urlparse.urljoin(base_url, experiments_url + "/" + exp["id"])
56
57 return None
58

Referenced by main().

Here is the caller graph for this function:

◆ get_registered_veh_data()

def speedharm_auto_configure.get_registered_veh_data ( )

Definition at line 71 of file speedharm_auto_configure.py.

72 r = requests.get(urlparse.urljoin(base_url, vehicles_url), verify=False)
74 return r.json()
75

References print_response().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log()

def speedharm_auto_configure.log (   msg)

Definition at line 41 of file speedharm_auto_configure.py.

41def log(msg):
42 cur_datetime = datetime.utcnow()
43 unix_ts = calendar.timegm(cur_datetime.utctimetuple())
44 print("[" + str(unix_ts) + "] " + str(msg))
45

Referenced by main(), and print_response().

Here is the caller graph for this function:

◆ main()

def speedharm_auto_configure.main ( )

Definition at line 91 of file speedharm_auto_configure.py.

91def main():
92 log("Speed Harmonization Auto Configurator " + version_id + ".")
93 log("Connecting to " + base_url + "...")
94 while True:
95 for veh in get_registered_veh_data():
96 if not "expId" in veh:
97 # Vehicle isn't yet assigned to an experiment, assume it's also not assigned to an algorithm
98 log("Detected new vehicle ID=" + str(veh["id"]) + " with no experiment, assigning to experiment.")
99 active_experiment_url = get_active_experiment_url()
100 if not active_experiment_url:
101 cur_datetime = datetime.utcnow()
102 unix_ts = calendar.timegm(cur_datetime.utctimetuple())
103 active_experiment_url = create_experiment("AUTO-CONFIG Experiment Generated @ " + str(unix_ts), "UNSPECIFIED")
104 log("Created new experiment at " + active_experiment_url)
105 else:
106 log("Discovered active experiment at " + active_experiment_url)
107 assign_experiment(veh["id"], active_experiment_url)
108 log("Assigned vehicle ID=" + str(veh["id"]) + " to experiment " + active_experiment_url)
109 # Vehicle isn't yet assigned to an algorithm
110 log("Detected new vehicle ID=" + str(veh["id"]) + " with no algorithm, assigning to algorithm.")
111 algo_url = create_algorithm(default_algorithm)
112 log("Created new algorithm of type " + default_algorithm + " at " + algo_url)
113 assign_algorithm(veh["id"], algo_url)
114 log("Assigned vehicle ID=" + str(veh["id"]) + " to algorithm " + algo_url)
115 log("Sleeping " + str(sleep_duration_millis) + "ms...")
116 time.sleep(sleep_duration_millis / 1000.0)
117

References assign_algorithm(), assign_experiment(), create_algorithm(), create_experiment(), get_active_experiment_url(), get_registered_veh_data(), log(), and main().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_response()

def speedharm_auto_configure.print_response (   resp)

Definition at line 46 of file speedharm_auto_configure.py.

46def print_response(resp):
47 log(resp.status_code)
48 log(resp.headers)
49 log(resp.json())
50

References log().

Referenced by assign_algorithm(), create_algorithm(), create_experiment(), and get_registered_veh_data().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ algorithms_url

string speedharm_auto_configure.algorithms_url = "/rest/algorithms"

Definition at line 37 of file speedharm_auto_configure.py.

◆ base_url

string speedharm_auto_configure.base_url = "http://35.153.64.44:8081"

Definition at line 32 of file speedharm_auto_configure.py.

◆ default_algorithm

string speedharm_auto_configure.default_algorithm = "gov.dot.fhwa.saxton.speedharm.executive.algorithms.ReduceSpeedAlgorithm"

Definition at line 38 of file speedharm_auto_configure.py.

◆ experiments_url

string speedharm_auto_configure.experiments_url = "/rest/experiments"

Definition at line 36 of file speedharm_auto_configure.py.

◆ sleep_duration_millis

int speedharm_auto_configure.sleep_duration_millis = 1000

Definition at line 39 of file speedharm_auto_configure.py.

◆ vehicles_url

string speedharm_auto_configure.vehicles_url = "/rest/vehicles"

Definition at line 35 of file speedharm_auto_configure.py.

◆ version_id

string speedharm_auto_configure.version_id = "v0.1"

Definition at line 31 of file speedharm_auto_configure.py.