Added shut_down function to TM.
This commit is contained in:
parent
c5fe20ab60
commit
7d135da9c6
|
@ -66,6 +66,19 @@ void TrafficManager::Tick() {
|
|||
}
|
||||
}
|
||||
|
||||
void TrafficManager::ShutDown() {
|
||||
TrafficManagerBase* tm_ptr = GetTM(_port);
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
auto it = _tm_map.find(_port);
|
||||
if (it != _tm_map.end()) {
|
||||
_tm_map.erase(it);
|
||||
}
|
||||
if(tm_ptr != nullptr) {
|
||||
tm_ptr->ShutDown();
|
||||
delete tm_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TrafficManager::CreateTrafficManagerServer(
|
||||
carla::client::detail::EpisodeProxy episode_proxy,
|
||||
uint16_t port) {
|
||||
|
|
|
@ -230,6 +230,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void ShutDown();
|
||||
|
||||
private:
|
||||
|
||||
void CreateTrafficManagerServer(
|
||||
|
|
|
@ -106,6 +106,8 @@ public:
|
|||
/// Method to set Open Street Map mode.
|
||||
virtual void SetOSMMode(const bool mode_switch) = 0;
|
||||
|
||||
virtual void ShutDown() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
|
|
@ -199,6 +199,11 @@ public:
|
|||
_client->call("set_osm_mode", mode_switch);
|
||||
}
|
||||
|
||||
void ShutDown() {
|
||||
DEBUG_ASSERT(_client != nullptr);
|
||||
_client->call("shut_down");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// RPC client.
|
||||
|
|
|
@ -151,11 +151,6 @@ void TrafficManagerLocal::Run() {
|
|||
|
||||
// Stop TM from processing the same frame more than once
|
||||
if (!synchronous_mode) {
|
||||
try {
|
||||
episode_proxy.Lock()->WaitForTick(
|
||||
carla::time_duration::milliseconds(
|
||||
TM_WAIT_FOR_TICK_TIMEOUT));
|
||||
} catch (const std::exception &e) {}
|
||||
carla::client::Timestamp timestamp = world.GetSnapshot().GetTimestamp();
|
||||
if (timestamp.frame == last_frame) {
|
||||
continue;
|
||||
|
|
|
@ -226,6 +226,8 @@ public:
|
|||
|
||||
/// Method to set Open Street Map mode.
|
||||
void SetOSMMode(const bool mode_switch);
|
||||
|
||||
void ShutDown() {};
|
||||
};
|
||||
|
||||
} // namespace traffic_manager
|
||||
|
|
|
@ -185,6 +185,10 @@ void TrafficManagerRemote::SetOSMMode(const bool mode_switch) {
|
|||
client.SetOSMMode(mode_switch);
|
||||
}
|
||||
|
||||
void TrafficManagerRemote::ShutDown() {
|
||||
client.ShutDown();
|
||||
}
|
||||
|
||||
void TrafficManagerRemote::SetSynchronousMode(bool mode) {
|
||||
client.SetSynchronousMode(mode);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,8 @@ public:
|
|||
/// Method to set Open Street Map mode.
|
||||
void SetOSMMode(const bool mode_switch);
|
||||
|
||||
virtual void ShutDown();
|
||||
|
||||
/// Method to provide synchronous tick
|
||||
bool SynchronousTick();
|
||||
|
||||
|
|
|
@ -168,6 +168,10 @@ public:
|
|||
tm->SetHybridPhysicsRadius(mode_switch);
|
||||
});
|
||||
|
||||
server->bind("shut_down", [=]() {
|
||||
tm->Release();
|
||||
});
|
||||
|
||||
/// Method to set synchronous mode.
|
||||
server->bind("set_synchronous_mode", [=](const bool mode) {
|
||||
tm->SetSynchronousMode(mode);
|
||||
|
|
|
@ -35,5 +35,6 @@ void export_trafficmanager() {
|
|||
.def("set_hybrid_physics_mode", &ctm::TrafficManager::SetHybridPhysicsMode)
|
||||
.def("set_hybrid_physics_radius", &ctm::TrafficManager::SetHybridPhysicsRadius)
|
||||
.def("set_random_device_seed", &ctm::TrafficManager::SetRandomDeviceSeed)
|
||||
.def("set_osm_mode", &carla::traffic_manager::TrafficManager::SetOSMMode);
|
||||
.def("set_osm_mode", &carla::traffic_manager::TrafficManager::SetOSMMode)
|
||||
.def("shut_down", &ctm::TrafficManager::ShutDown);
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@ class TestDeterminism(SmokeTest):
|
|||
# run simulation 1
|
||||
vehicle_actor_list = self.spawn_vehicles(world, blueprint_transform_list)
|
||||
record_run1 = self.run_simulation(world, vehicle_actor_list)
|
||||
traffic_manager.shut_down()
|
||||
|
||||
# reset for simulation 2
|
||||
self.client.reload_world(False)
|
||||
|
@ -128,9 +129,9 @@ class TestDeterminism(SmokeTest):
|
|||
#run simulation 2
|
||||
vehicle_actor_list = self.spawn_vehicles(world, blueprint_transform_list)
|
||||
record_run2 = self.run_simulation(world, vehicle_actor_list)
|
||||
traffic_manager.shut_down()
|
||||
|
||||
self.client.reload_world()
|
||||
traffic_manager.set_synchronous_mode(False)
|
||||
world.apply_settings(old_settings)
|
||||
|
||||
self.compare_records(record_run1, record_run2)
|
||||
|
|
Loading…
Reference in New Issue