MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / restart

Method restart

PythonAPI/examples/manual_control.py:185–233  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

183 self.recording_start = 0
184
185 def restart(self):
186 self.player_max_speed = 1.589
187 self.player_max_speed_fast = 3.713
188 # Keep same camera config if the camera manager exists.
189 cam_index = self.camera_manager.index if self.camera_manager is not None else 0
190 cam_pos_index = self.camera_manager.transform_index if self.camera_manager is not None else 0
191 # Get a random blueprint.
192 blueprint = random.choice(self.world.get_blueprint_library().filter(self._actor_filter))
193 blueprint.set_attribute('role_name', self.actor_role_name)
194 if blueprint.has_attribute('color'):
195 color = random.choice(blueprint.get_attribute('color').recommended_values)
196 blueprint.set_attribute('color', color)
197 if blueprint.has_attribute('driver_id'):
198 driver_id = random.choice(blueprint.get_attribute('driver_id').recommended_values)
199 blueprint.set_attribute('driver_id', driver_id)
200 if blueprint.has_attribute('is_invincible'):
201 blueprint.set_attribute('is_invincible', 'true')
202 # set the max speed
203 if blueprint.has_attribute('speed'):
204 self.player_max_speed = float(blueprint.get_attribute('speed').recommended_values[1])
205 self.player_max_speed_fast = float(blueprint.get_attribute('speed').recommended_values[2])
206 else:
207 print("No recommended values for 'speed' attribute")
208 # Spawn the player.
209 if self.player is not None:
210 spawn_point = self.player.get_transform()
211 spawn_point.location.z += 2.0
212 spawn_point.rotation.roll = 0.0
213 spawn_point.rotation.pitch = 0.0
214 self.destroy()
215 self.player = self.world.try_spawn_actor(blueprint, spawn_point)
216 while self.player is None:
217 if not self.map.get_spawn_points():
218 print('There are no spawn points available in your map/town.')
219 print('Please add some Vehicle Spawn Point to your UE4 scene.')
220 sys.exit(1)
221 spawn_points = self.map.get_spawn_points()
222 spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()
223 self.player = self.world.try_spawn_actor(blueprint, spawn_point)
224 # Set up the sensors.
225 self.collision_sensor = CollisionSensor(self.player, self.hud)
226 self.lane_invasion_sensor = LaneInvasionSensor(self.player, self.hud)
227 self.gnss_sensor = GnssSensor(self.player)
228 self.imu_sensor = IMUSensor(self.player)
229 self.camera_manager = CameraManager(self.player, self.hud, self._gamma)
230 self.camera_manager.transform_index = cam_pos_index
231 self.camera_manager.set_sensor(cam_index, notify=False)
232 actor_type = get_actor_display_name(self.player)
233 self.hud.notification(actor_type)
234
235 def next_weather(self, reverse=False):
236 self._weather_index += -1 if reverse else 1

Callers 2

__init__Method · 0.95
parse_eventsMethod · 0.45

Calls 10

destroyMethod · 0.95
IMUSensorClass · 0.85
CollisionSensorClass · 0.70
LaneInvasionSensorClass · 0.70
GnssSensorClass · 0.70
CameraManagerClass · 0.70
get_actor_display_nameFunction · 0.70
TransformMethod · 0.45
set_sensorMethod · 0.45
notificationMethod · 0.45

Tested by

no test coverage detected