Added timeout to World Tick (#2556)
* Added timeout to World Tick * Updated Changelog * Fixed timeout on SetEpisodeSettings Co-authored-by: bernat <bernatx@gmail.com> Co-authored-by: Jacopo Bartiromo <32928804+jackbart94@users.noreply.github.com> Co-authored-by: Marc Garcia Puig <marcgpuig@gmail.com>
This commit is contained in:
parent
ac32aee647
commit
94affd9b79
|
@ -14,6 +14,7 @@
|
||||||
* Added landmark class for signal-related queries.
|
* Added landmark class for signal-related queries.
|
||||||
* Added support to parse OpenDRIVE signals.
|
* Added support to parse OpenDRIVE signals.
|
||||||
* Added junction class as queryable object from waypoint
|
* Added junction class as queryable object from waypoint
|
||||||
|
* Added timeout to World Tick
|
||||||
* Added simple physical map generation from standalone OpenDRIVE data
|
* Added simple physical map generation from standalone OpenDRIVE data
|
||||||
* Added support for generating walker navigation on server-side
|
* Added support for generating walker navigation on server-side
|
||||||
* Added support for new geometry: `spiral`, `poly3`, and `paramPoly3`
|
* Added support for new geometry: `spiral`, `poly3`, and `paramPoly3`
|
||||||
|
|
|
@ -105,8 +105,8 @@ namespace client {
|
||||||
_episode.Lock()->RemoveOnTickEvent(callback_id);
|
_episode.Lock()->RemoveOnTickEvent(callback_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t World::Tick() {
|
uint64_t World::Tick(time_duration timeout) {
|
||||||
return _episode.Lock()->Tick();
|
return _episode.Lock()->Tick(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::SetPedestriansCrossFactor(float percentage) {
|
void World::SetPedestriansCrossFactor(float percentage) {
|
||||||
|
|
|
@ -117,7 +117,7 @@ namespace client {
|
||||||
/// synchronous mode).
|
/// synchronous mode).
|
||||||
///
|
///
|
||||||
/// @return The id of the frame that this call started.
|
/// @return The id of the frame that this call started.
|
||||||
uint64_t Tick();
|
uint64_t Tick(time_duration timeout);
|
||||||
|
|
||||||
/// set the probability that an agent could cross the roads in its path following
|
/// set the probability that an agent could cross the roads in its path following
|
||||||
/// percentage of 0.0f means no pedestrian can cross roads
|
/// percentage of 0.0f means no pedestrian can cross roads
|
||||||
|
|
|
@ -44,13 +44,25 @@ namespace detail {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SynchronizeFrame(uint64_t frame, const Episode &episode) {
|
static bool SynchronizeFrame(uint64_t frame, const Episode &episode, time_duration timeout) {
|
||||||
|
bool result = true;
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
while (frame > episode.GetState()->GetTimestamp().frame) {
|
while (frame > episode.GetState()->GetTimestamp().frame) {
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end-start);
|
||||||
|
if(timeout.to_chrono() < diff) {
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(result) {
|
||||||
carla::traffic_manager::TrafficManager::Tick();
|
carla::traffic_manager::TrafficManager::Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
// -- Constructor ------------------------------------------------------------
|
// -- Constructor ------------------------------------------------------------
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
@ -126,10 +138,13 @@ namespace detail {
|
||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Simulator::Tick() {
|
uint64_t Simulator::Tick(time_duration timeout) {
|
||||||
DEBUG_ASSERT(_episode != nullptr);
|
DEBUG_ASSERT(_episode != nullptr);
|
||||||
const auto frame = _client.SendTickCue();
|
const auto frame = _client.SendTickCue();
|
||||||
SynchronizeFrame(frame, *_episode);
|
bool result = SynchronizeFrame(frame, *_episode, timeout);
|
||||||
|
if (!result) {
|
||||||
|
throw_exception(TimeoutException(_client.GetEndpoint(), timeout));
|
||||||
|
}
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +168,8 @@ namespace detail {
|
||||||
"recommended to set 'fixed_delta_seconds' when running on synchronous mode.");
|
"recommended to set 'fixed_delta_seconds' when running on synchronous mode.");
|
||||||
}
|
}
|
||||||
const auto frame = _client.SetEpisodeSettings(settings);
|
const auto frame = _client.SetEpisodeSettings(settings);
|
||||||
SynchronizeFrame(frame, *_episode);
|
using namespace std::literals::chrono_literals;
|
||||||
|
SynchronizeFrame(frame, *_episode, 10s);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ namespace detail {
|
||||||
_episode->RemoveOnTickEvent(id);
|
_episode->RemoveOnTickEvent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Tick();
|
uint64_t Tick(time_duration timeout);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
|
@ -56,6 +56,11 @@ static size_t OnTick(carla::client::World &self, boost::python::object callback)
|
||||||
return self.OnTick(MakeCallback(std::move(callback)));
|
return self.OnTick(MakeCallback(std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static auto Tick(carla::client::World &world, double seconds) {
|
||||||
|
carla::PythonUtil::ReleaseGIL unlock;
|
||||||
|
return world.Tick(TimeDurationFromSeconds(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
static auto GetActorsById(carla::client::World &self, const boost::python::list &actor_ids) {
|
static auto GetActorsById(carla::client::World &self, const boost::python::list &actor_ids) {
|
||||||
std::vector<carla::ActorId> ids{
|
std::vector<carla::ActorId> ids{
|
||||||
boost::python::stl_input_iterator<carla::ActorId>(actor_ids),
|
boost::python::stl_input_iterator<carla::ActorId>(actor_ids),
|
||||||
|
@ -155,7 +160,7 @@ void export_world() {
|
||||||
.def("wait_for_tick", &WaitForTick, (arg("seconds")=10.0))
|
.def("wait_for_tick", &WaitForTick, (arg("seconds")=10.0))
|
||||||
.def("on_tick", &OnTick, (arg("callback")))
|
.def("on_tick", &OnTick, (arg("callback")))
|
||||||
.def("remove_on_tick", &cc::World::RemoveOnTick, (arg("callback_id")))
|
.def("remove_on_tick", &cc::World::RemoveOnTick, (arg("callback_id")))
|
||||||
.def("tick", CALL_WITHOUT_GIL(cc::World, Tick))
|
.def("tick", &Tick, (arg("seconds")=10.0))
|
||||||
.def("set_pedestrians_cross_factor", CALL_WITHOUT_GIL_1(cc::World, SetPedestriansCrossFactor, float), (arg("percentage")))
|
.def("set_pedestrians_cross_factor", CALL_WITHOUT_GIL_1(cc::World, SetPedestriansCrossFactor, float), (arg("percentage")))
|
||||||
.def(self_ns::str(self_ns::self))
|
.def(self_ns::str(self_ns::self))
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue