Skip to content

Commit

Permalink
fixup! vtd: Enable VTD dynamics models
Browse files Browse the repository at this point in the history
  • Loading branch information
clssn committed Feb 4, 2021
1 parent 5fcc085 commit 256d635
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
26 changes: 21 additions & 5 deletions plugins/vtd/src/vtd_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,24 @@ class VtdBinding : public cloe::Simulator {

// Wait for creation of TaskControl client
logger()->info("Wait for task control...");
scp_try_read_until([this]() { return static_cast<bool>(task_control_); });
// Expect task_control_ to be initialized in VtdBinding::apply_scp_rdb
scp_try_read_until([this]() { return task_control_ != nullptr; });

// Wait for selection of scenario (by GUI if not configured)
if (!config_.scenario.size()) {
logger()->info("Wait for scenario...");
scp_try_read_until([this]() { return config_.scenario.size(); });
// Stop to neutralize GUI's Init command sendt along with LoadScenario
// Expect the scenario to be initialized in VtdBinding::apply_scenario_filename()
scp_try_read_until([this]() { return config_.scenario != ""; });
// Stop to neutralize GUI's Init command sent along with LoadScenario
scp_client_->send(scp::Stop);
}

// Get agents from scenario (works only before LoadScenario!)
scp::QueryScenario query;
query.scenario = config_.scenario;
scp_client_->send(query);
// Expect the agents_expected_ array to be initialized in
// VtdBinding::apply_scp_scenario_response()
scp_try_read_until([this]() { return !agents_expected_.empty(); });

// Load the scenario
Expand All @@ -241,6 +245,7 @@ class VtdBinding : public cloe::Simulator {
scp_client_->send(scp::InitOperation);

// Wait for all agents' initialization
// Expect vehicles_ to be initialized in VtdBinding::apply_scp_set()
scp_try_read_until([this]() { return agents_expected_.size() == vehicles_.size(); });

// Start the simulation
Expand All @@ -250,7 +255,9 @@ class VtdBinding : public cloe::Simulator {
scp_client_->send(scp::AckInit);

// Continue reading until VTD is running
// Expect init_done_ to be set to true in VtdBinding::apply_scp_init_done()
scp_try_read_until([this]() { return init_done_; });
// Expect the operational_ flag to be set to true in VtdBinding::apply_scp_run()
scp_try_read_until([this]() { return is_operational(); });

logger()->info("VTD Started.");
Expand Down Expand Up @@ -461,7 +468,7 @@ class VtdBinding : public cloe::Simulator {
* Waiting is limited to a number of retries until timeout.
*/
void scp_try_read_until(std::function<bool(void)> pred) {
int tries_left = VTD_INIT_WAIT_RETRIES;
int tries_left = config_.connection.retry_attempts;
while (!pred()) {
this->readall_scp();
std::this_thread::sleep_for(cloe::Milliseconds{VTD_INIT_WAIT_SLEEP_MS});
Expand Down Expand Up @@ -619,7 +626,16 @@ class VtdBinding : public cloe::Simulator {
fmt::format("Can't derive VTD Scenario directory from path: {}", p.generic_string()));
}
fs::path r;
for (auto it = ++s; it != p.end(); ++it) r /= *it;
for (auto it = ++s; it != p.end(); ++it) {
r /= *it;
}
if (std::find(s, p.end(), "Scenarios") != p.end()) {
logger()->warn(
"Cannot determine the scenario directory unambiguously because "
"the chosen scenario path contains multiple 'Scenario/' elements: "
"{}",
p.native());
}
return r;
}
return p;
Expand Down
5 changes: 1 addition & 4 deletions plugins/vtd/src/vtd_conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
#include <cloe/utility/tcp_transceiver_config.hpp> // for TcpTransceiverConfiguration, ...
#include "osi_omni_sensor.hpp" // for SensorMockLevel

// Connection
// Connection / Initialization
#define VTD_DEFAULT_SCP_PORT 48179
#define VTD_PARAMSERVER_PORT 54345
#define VTD_INIT_SYNC_SLEEP_MS 3000

// Scenario Loading
#define VTD_INIT_WAIT_SLEEP_MS 200
#define VTD_INIT_WAIT_RETRIES 300

namespace vtd {

Expand Down

0 comments on commit 256d635

Please sign in to comment.