Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.collision_cnt += 1
else:
self.collision_cnt = 0
# self.collision_cnt = (self.collision_cnt + info['collision']) * info['collision']
self.ignite = self.ignite or info['speed'] > 1
stuck = int(info['speed'] < 1)
self.stuck_cnt = (self.stuck_cnt + stuck) * stuck * int(bool(self.ignite) or self.testing)
if info['offroad'] > 0.5:
self.offroad_cnt += 1
return (self.stuck_cnt > 30) or self.offroad_cnt > 30 or self.collision_cnt > 20
if __name__ == '__main__':
with make_carla_client('localhost', 2018) as client:
print('CarlaClient connected')
env = carla_env(client)
env.reset()
for i in range(20):
obs, seg, reward, done, info = env.step([1, 0])
print(info)
env.reset()
for i in range(20):
obs, seg, reward, done, info = env.step([1, 0])
print(info)
self.collision_cnt += 1
else:
self.collision_cnt = 0
# self.collision_cnt = (self.collision_cnt + info['collision']) * info['collision']
self.ignite = self.ignite or info['speed'] > 1
stuck = int(info['speed'] < 1)
self.stuck_cnt = (self.stuck_cnt + stuck) * stuck * int(bool(self.ignite) or self.testing)
if info['offroad'] > 0.5:
self.offroad_cnt += 1
return (self.stuck_cnt > 30 and self.ignite) or self.offroad_cnt > 30 or self.collision_cnt > 20
if __name__ == '__main__':
with make_carla_client('localhost', 2018) as client:
print('CarlaClient connected')
env = carla_env(client)
env.reset()
for i in range(20):
obs, seg, reward, done, info = env.step([1, 0])
print(info)
env.reset()
for i in range(20):
obs, seg, reward, done, info = env.step([1, 0])
print(info)
def run_carla_client(args):
# Here we will run 3 episodes with 300 frames each.
number_of_episodes = 3
frames_per_episode = 300
# We assume the CARLA server is already waiting for a client to connect at
# host:port. To create a connection we can use the `make_carla_client`
# context manager, it creates a CARLA client object and starts the
# connection. It will throw an exception if something goes wrong. The
# context manager makes sure the connection is always cleaned up on exit.
with make_carla_client(args.host, args.port) as client:
print('CarlaClient connected')
for episode in range(0, number_of_episodes):
# Start a new episode.
if args.settings_filepath is None:
# Create a CarlaSettings object. This object is a wrapper around
# the CarlaSettings.ini file. Here we set the configuration we
# want for the new episode.
settings = CarlaSettings()
settings.set(
SynchronousMode=True,
SendNonPlayerAgentsInfo=True,
NumberOfVehicles=20,
NumberOfPedestrians=40,
help='plot the map of the current city (needs to match active map in '
'server, options: Town01 or Town02)')
args = argparser.parse_args()
log_level = logging.DEBUG if args.debug else logging.INFO
logging.basicConfig(format='%(levelname)s: %(message)s', level=log_level)
logging.info('listening to server %s:%s', args.host, args.port)
print(__doc__)
wrapper = Carla_Wrapper()
while True:
try:
with make_carla_client(args.host, args.port, timeout=1000) as client:
game = CarlaGame(client, args, wrapper)
game.execute()
break
except TCPConnectionError as error:
logging.error(error)
time.sleep(1)
def run_carla_client(host, port):
global frame
with make_carla_client(host, port) as client:
print('CarlaClient connected')
settings = CarlaSettings()
settings.set(
SynchronousMode=True,
SendNonPlayerAgentsInfo=True,
NumberOfVehicles=0,
NumberOfPedestrians=0,
WeatherId=1) # random.choice([1, 3, 7, 8, 14]))
settings.randomize_seeds()
camera0 = Camera('CameraRGB')
camera0.set_image_size(800, 600)
camera0.set_position(30, 0, 130)
settings.add_sensor(camera0)
camera1 = Camera('CameraDepth', PostProcessing='Depth')
def run_carla_client(host, port, far):
# Here we will run a single episode with 300 frames.
number_of_frames = 3000
frame_step = 100 # Save one image every 100 frames
output_folder = '_out'
image_size = [800, 600]
camera_local_pos = [0.3, 0.0, 1.3] # [X, Y, Z]
camera_local_rotation = [0, 0, 0] # [pitch(Y), yaw(Z), roll(X)]
fov = 70
# Connect with the server
with make_carla_client(host, port) as client:
print('CarlaClient connected')
# Here we load the settings.
settings = CarlaSettings()
settings.set(
SynchronousMode=True,
SendNonPlayerAgentsInfo=False,
NumberOfVehicles=20,
NumberOfPedestrians=40,
WeatherId=random.choice([1, 3, 7, 8, 14]))
settings.randomize_seeds()
camera1 = Camera('CameraDepth', PostProcessing='Depth', FOV=fov)
camera1.set_image_size(*image_size)
camera1.set_position(*camera_local_pos)
camera1.set_rotation(*camera_local_rotation)
def run_carla_client(host, port, autopilot_on, save_images_to_disk, image_filename_format, settings_filepath):
# Here we will run 3 episodes with 300 frames each.
number_of_episodes = 3
frames_per_episode = 300
# We assume the CARLA server is already waiting for a client to connect at
# host:port. To create a connection we can use the `make_carla_client`
# context manager, it creates a CARLA client object and starts the
# connection. It will throw an exception if something goes wrong. The
# context manager makes sure the connection is always cleaned up on exit.
with make_carla_client(host, port) as client:
print('CarlaClient connected')
for episode in range(0, number_of_episodes):
# Start a new episode.
if settings_filepath is None:
# Create a CarlaSettings object. This object is a wrapper around
# the CarlaSettings.ini file. Here we set the configuration we
# want for the new episode.
settings = CarlaSettings()
settings.set(
SynchronousMode=True,
NumberOfVehicles=20,
NumberOfPedestrians=40,
WeatherId=random.choice([1, 3, 7, 8, 14]))