notation fixes
This commit is contained in:
parent
81b095b9ef
commit
e59f5ee2ef
|
@ -50,11 +50,13 @@ class CarlaClient(object):
|
|||
def connected(self):
|
||||
return self._world_client.connected()
|
||||
|
||||
def request_new_episode(self, carla_settings):
|
||||
"""Request a new episode. carla_settings object must be convertible to
|
||||
a str holding a CarlaSettings.ini.
|
||||
def _request_new_episode(self, carla_settings):
|
||||
"""Request a new episode. Internal function to
|
||||
request information about a new episode episode that
|
||||
is going to start. It also prepare the client for
|
||||
reset by disconnecting stream and control clients.
|
||||
|
||||
|
||||
Returns a protobuf object holding the scene description.
|
||||
"""
|
||||
# Disconnect agent clients.
|
||||
self._stream_client.disconnect()
|
||||
|
@ -73,20 +75,20 @@ class CarlaClient(object):
|
|||
raise RuntimeError("received 0 player start spots")
|
||||
self._is_episode_requested =True
|
||||
return pb_message
|
||||
def load_carla_settings(self, carla_settings):
|
||||
def load_settings(self, carla_settings):
|
||||
""" Abstraction to new episode request. carla_settings object must be convertible to
|
||||
a str holding a CarlaSettings.ini.
|
||||
a str holding a CarlaSettings.ini. Loads new settings to the server.
|
||||
|
||||
Returns a protobuf object holding the scene description.
|
||||
"""
|
||||
self._current_settings = carla_settings
|
||||
return self.request_new_episode(carla_settings)
|
||||
return self._request_new_episode(carla_settings)
|
||||
|
||||
|
||||
def start_episode(self, player_start_index):
|
||||
"""Start the new episode at the player start given by the
|
||||
player_start_index. The list of player starts is retrieved by
|
||||
request_new_episode().
|
||||
load_settings().
|
||||
|
||||
This function waits until the server answers with an EpisodeReady.
|
||||
"""
|
||||
|
@ -94,26 +96,28 @@ class CarlaClient(object):
|
|||
if self._current_settings == None:
|
||||
raise RuntimeError('no settings loaded, cannot start episode')
|
||||
|
||||
if not self._is_episode_requested:
|
||||
self.request_new_episode(self._current_settings)
|
||||
# if no new settings are loaded, request new episode with previous
|
||||
if not self._is_episode_requested:
|
||||
self._request_new_episode(self._current_settings)
|
||||
|
||||
|
||||
pb_message = carla_protocol.EpisodeStart()
|
||||
pb_message.player_start_spot_index = player_start_index
|
||||
self._world_client.write(pb_message.SerializeToString())
|
||||
# Wait for EpisodeReady.
|
||||
data = self._world_client.read()
|
||||
if not data:
|
||||
raise RuntimeError('failed to read data from server')
|
||||
pb_message = carla_protocol.EpisodeReady()
|
||||
pb_message.ParseFromString(data)
|
||||
if not pb_message.ready:
|
||||
raise RuntimeError('cannot start episode: server failed to start episode')
|
||||
# We can start the agent clients now.
|
||||
self._stream_client.connect()
|
||||
self._control_client.connect()
|
||||
# Set again the status for no episode requested
|
||||
self._is_episode_requested = False
|
||||
try:
|
||||
pb_message = carla_protocol.EpisodeStart()
|
||||
pb_message.player_start_spot_index = player_start_index
|
||||
self._world_client.write(pb_message.SerializeToString())
|
||||
# Wait for EpisodeReady.
|
||||
data = self._world_client.read()
|
||||
if not data:
|
||||
raise RuntimeError('failed to read data from server')
|
||||
pb_message = carla_protocol.EpisodeReady()
|
||||
pb_message.ParseFromString(data)
|
||||
if not pb_message.ready:
|
||||
raise RuntimeError('cannot start episode: server failed to start episode')
|
||||
# We can start the agent clients now.
|
||||
self._stream_client.connect()
|
||||
self._control_client.connect()
|
||||
# Set again the status for no episode requested
|
||||
finally:
|
||||
self._is_episode_requested = False
|
||||
|
||||
def read_measurements(self):
|
||||
"""Read measuremnts of current frame. The episode must be started.
|
||||
|
|
|
@ -75,7 +75,7 @@ def run_carla_client(host, port, autopilot_on, save_images_to_disk, image_filena
|
|||
# replies with a scene description containing the available start
|
||||
# spots for the player. Here instead of a CarlaSettings object we
|
||||
# can also provide a CarlaSettings.ini file as string.
|
||||
scene = client.load_carla_settings(settings)
|
||||
scene = client.load_settings(settings)
|
||||
|
||||
# Choose one player start at random.
|
||||
number_of_player_starts = len(scene.player_start_spots)
|
||||
|
|
|
@ -135,7 +135,7 @@ class CarlaGame(object):
|
|||
|
||||
def _on_new_episode(self):
|
||||
print('Requesting new episode...')
|
||||
scene = self.client.load_carla_settings(make_carla_settings())
|
||||
scene = self.client.load_settings(make_carla_settings())
|
||||
number_of_player_starts = len(scene.player_start_spots)
|
||||
player_start = np.random.randint(number_of_player_starts)
|
||||
self.client.start_episode(player_start)
|
||||
|
|
Loading…
Reference in New Issue