Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def draw_waypoints(self, waypoints, vertical_shift, persistency=-1):
"""
Draw a list of waypoints at a certain height given in vertical_shift.
:param waypoints: list or iterable container with the waypoints to draw
:param vertical_shift: height in meters
:return:
"""
for w in waypoints:
wp = w + carla.Location(z=vertical_shift)
self.world.debug.draw_point(wp, size=0.1, color=carla.Color(0, 255, 0), life_time=persistency)
def draw_waypoints(world, route):
x0 = route[0,0]
y0 = route[0,1]
for k in range(1,route.shape[0]):
r = route[k,:]
x1 = r[0]
y1 = r[1]
dx = x1-x0
dy = y1-y0
if math.sqrt(dx*dx+dy*dy) > 30: # original 2.5
x0 = x1
y0 = y1
begin = carla.Location(x = x1,y = y1, z = 0.2)
angle = math.radians(r[2])
end = begin + carla.Location(x=6*math.cos(angle), y=6*math.sin(angle))
world.debug.draw_arrow(begin, end, arrow_size=12,life_time=90, color=carla.Color(238,18, 137,0))
def draw_waypoints(self, waypoints, turn_positions_and_labels, vertical_shift, persistency=-1):
"""
Draw a list of waypoints at a certain height given in vertical_shift.
:param waypoints: list or iterable container with the waypoints to draw
:param vertical_shift: height in meters
:return:
"""
for w in waypoints:
wp = w[0].location + carla.Location(z=vertical_shift)
self.world.debug.draw_point(wp, size=0.1, color=carla.Color(0, 255, 0), life_time=persistency)
for start, end, conditions in turn_positions_and_labels:
if conditions == RoadOption.LEFT: # Yellow
color = carla.Color(255, 255, 0)
elif conditions == RoadOption.RIGHT: # Cyan
color = carla.Color(0, 255, 255)
elif conditions == RoadOption.CHANGELANELEFT: # Orange
color = carla.Color(255, 64, 0)
elif conditions == RoadOption.CHANGELANERIGHT: # Dark Cyan
color = carla.Color(0, 64, 255)
else: # STRAIGHT
color = carla.Color(128, 128, 128) # Gray
for position in range(start, end):
self.world.debug.draw_point(waypoints[position][0].location + carla.Location(z=vertical_shift),
size=0.2, color=color, life_time=persistency)
def _build_scenario_instances(self, world, ego_vehicle, scenario_definitions, town, timeout=300, debug_mode=False):
"""
Based on the parsed route and possible scenarios, build all the scenario classes.
"""
scenario_instance_vec = []
if debug_mode:
for scenario in scenario_definitions:
loc = carla.Location(scenario['trigger_position']['x'],
scenario['trigger_position']['y'],
scenario['trigger_position']['z']) + carla.Location(z=2.0)
world.debug.draw_point(loc, size=1.0, color=carla.Color(255, 0, 0), life_time=100000)
world.debug.draw_string(loc, str(scenario['name']), draw_shadow=False,
color=carla.Color(0, 0, 255), life_time=100000, persistent_lines=True)
for definition in scenario_definitions:
# Get the class possibilities for this scenario number
possibility_vec = NUMBER_CLASS_TRANSLATION[definition['name']]
scenario_class = possibility_vec[definition['type']]
# Create the other actors that are going to appear
if definition['other_actors'] is not None:
list_of_actor_conf_instances = self._get_actors_instances(definition['other_actors'])
else:
list_of_actor_conf_instances = []
# Create an actor configuration for the ego-vehicle trigger position
def _draw_waypoints(self, world, waypoints, turn_positions_and_labels, vertical_shift, persistency=-1):
"""
Draw a list of waypoints at a certain height given in vertical_shift.
"""
for w in waypoints:
wp = w[0].location + carla.Location(z=vertical_shift)
world.debug.draw_point(wp, size=0.1, color=carla.Color(0, 255, 0), life_time=persistency)
for start, end, conditions in turn_positions_and_labels:
if conditions == RoadOption.LEFT: # Yellow
color = carla.Color(255, 255, 0)
elif conditions == RoadOption.RIGHT: # Cyan
color = carla.Color(0, 255, 255)
elif conditions == RoadOption.CHANGELANELEFT: # Orange
color = carla.Color(255, 64, 0)
elif conditions == RoadOption.CHANGELANERIGHT: # Dark Cyan
color = carla.Color(0, 64, 255)
else: # STRAIGHT
color = carla.Color(128, 128, 128) # Gray
for position in range(start, end):
world.debug.draw_point(waypoints[position][0].location + carla.Location(z=vertical_shift),
size=0.2, color=color, life_time=persistency)
world.debug.draw_point(waypoints[0][0].location + carla.Location(z=vertical_shift), size=0.2,
color=carla.Color(0, 0, 255), life_time=persistency)
world.debug.draw_point(waypoints[-1][0].location + carla.Location(z=vertical_shift), size=0.2,
color=carla.Color(255, 0, 0), life_time=persistency)
Draw a connected path from start of route to end.
Green node = start
Red node = point along path
Blue node = destination
"""
for i in range(0, len(self.route_waypoints)-1, skip+1):
w0 = self.route_waypoints[i][0]
w1 = self.route_waypoints[i+1][0]
self.world.debug.draw_line(
w0.transform.location + carla.Location(z=0.25),
w1.transform.location + carla.Location(z=0.25),
thickness=0.1, color=carla.Color(255, 0, 0),
life_time=life_time, persistent_lines=False)
self.world.debug.draw_point(
w0.transform.location + carla.Location(z=0.25), 0.1,
carla.Color(0, 255, 0) if i == 0 else carla.Color(255, 0, 0),
life_time, False)
self.world.debug.draw_point(
self.route_waypoints[-1][0].transform.location + carla.Location(z=0.25), 0.1,
carla.Color(0, 0, 255),
life_time, False)
print(actor.get_transform())
# ego vehicle acts
self.ego_vehicle.apply_control(ego_action)
if self.spectator:
spectator = self.world.get_spectator()
ego_trans = self.ego_vehicle.get_transform()
spectator.set_transform(carla.Transform(ego_trans.location + carla.Location(z=50),
carla.Rotation(pitch=-90)))
# show current score
total_score, route_score, infractions_score = self.compute_current_statistics()
print("{}/{}".format(route_score, infractions_score))
self.world.debug.draw_string(ego_trans.location + carla.Location(z=15),
"[{:.2f}/{:.2f}]".format(route_score, infractions_score),
draw_shadow=False, color=carla.Color(255, 255, 255),
life_time=0.01)
if self.route_visible:
turn_positions_and_labels = clean_route(trajectory)
self.draw_waypoints(trajectory, turn_positions_and_labels,
vertical_shift=1.0, persistency=50000.0)
self.route_visible = False
# time continues
attempts = 0
while attempts < self.MAX_CONNECTION_ATTEMPTS:
try:
self.world.tick()
break
except Exception:
attempts += 1
def show_tl_count_down(duration=30, indefinite=False):
end_time = time.time() + duration
color_dict = {
'Red':carla.Color(255, 0, 0),
'Yellow':carla.Color(255, 255, 0),
'Green':carla.Color(0, 255, 0)
}
while time.time() < end_time or indefinite:
for tl_group in list_of_all_groups:
for tl in tl_group:
debug.draw_string(tl.get_location() + carla.Location(0, 0, 5),
str(tl.get_elapsed_time())[:4], False,
color_dict[tl.get_state().name], 0.01)
time.sleep(0.002)
try:
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass
import carla
import argparse
import math
import random
import time
red = carla.Color(255, 0, 0)
green = carla.Color(0, 255, 0)
blue = carla.Color(47, 210, 231)
cyan = carla.Color(0, 255, 255)
yellow = carla.Color(255, 255, 0)
orange = carla.Color(255, 162, 0)
white = carla.Color(255, 255, 255)
trail_life_time = 10
waypoint_separation = 4
def draw_transform(debug, trans, col=carla.Color(255, 0, 0), lt=-1):
yaw_in_rad = math.radians(trans.rotation.yaw)
pitch_in_rad = math.radians(trans.rotation.pitch)
p1 = carla.Location(
x=trans.location.x + math.cos(pitch_in_rad) * math.cos(yaw_in_rad),