[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] getSubscriptionResults in libtraci / C++
|
Hi Ruud,
Thank you very much for the snippets. Very useful for my next
step to extract vehicle information.
As the first step i would like to get a list of the vehicle ids
that just departed from the simulation (or newly arrived) to
manage my internal list of active vehicles. From your first
example it seems the results cannot be filtered to only the VAR_ARRIVED_VEHICLES_IDS or VAR_DEPARTED_VEHICLES_IDS Instead all subscribed results are returned
in the sub_results map. The first element of the map is the
variable ID, correct? Then i would expect the second element is a
list of vehicle ids:
auto sub_results =
Vehicle::getSubscriptionResults(name.c_str());
for (auto r : sub_results) {
int var_id = r.first();
if (var_id == libsumo::VAR_ARRIVED_VEHICLES_IDS) {
char const* vehicle_ids =
r.second()->getString().c_str();
}
}
However, the vehicle_ids string does seems to contain any vehicle
ids, list or ...
Is it possible to get just the list of vehicle ids in the C++ lib
(like in Python), and if so how, or do i need to determine that
from the individual vehicles results like in your second example?
Thanks,
Bart
On 05-12-2023 10:12, Ruud van Gaal
wrote:
Hi
Bart,
Here
are some snippets. For getSubscriptionResults():
auto sub_results =
Vehicle::getSubscriptionResults(name.c_str());
for (auto r : sub_results) {
pt_LogDbg("- Ego subscr result type 0x%x: '%s'",
r.first, r.second->getString().c_str());
}
I'm
using a context subscription really (only report within a
specific radius):
libsumo::SubscriptionResults subscriptionResults;
if (prefLogSumoCalls)
pt_Log("SUMO call:
Vehicle::getContextSubscriptionResults(%s)", name.c_str());
subscriptionResults =
Vehicle::getContextSubscriptionResults(name.c_str());
// Go through results (parse)
std::string entity_id;
for (auto e : subscriptionResults) {
entity_id = e.first;
//pt_LogDbg("- Ego ctx subscr result type '%s'",
entity_id.c_str());
auto res = e.second;
for (auto r : res) {
//pt_LogDbg(" - subscr result var 0x%x value '%s''",
r.first, r.second->getString().c_str());
switch (r.first) {
case libsumo::VAR_ANGLE:
vehicle->angle =
ParseDouble(r.second->getString());
break;
case libsumo::VAR_POSITION3D:
// Convert string to Vector3-like struct
ParsePosition(r.second->getString(),
vehicle->position);
break;
case libsumo::VAR_TYPE:
//pt_LogDbg("VAR_TYPE='%s'",
r.second->getString().c_str());
vehicle->type_sumo = r.second->getString();
break;
//////////////// etc
default:
pt_LogWarn("Var 0x%x is not parsed; fix the
source", r.first);
break;
}
}
}
Hope
that helps,
Ruud
Dear All,
Does anyone have
experience, or can send a link to documentation, on how to
process results from a subscription in C++ using libtraci?
I need to convert the following from Python into C++. The
subscription is for multiple types of variables. (not only
VAR_ARRIVED_VEHICLES_IDS).
In Python the
implementation is rather straightforward with the
documentation (e.g. in https://sumo.dlr.de/docs/TraCI/Interfacing_TraCI_from_Python.html).
results = traci.simulation.getSubscriptionResults()
for vehicle_id in results[tc.VAR_ARRIVED_VEHICLES_IDS]:
# process vehicle_id
This can be converted to C++ like this:
libsumo::TraCIResults results = libtraci::Simulation::getSubscriptionResults();
//std::map<int, std::shared_ptr<libsumo::TraCIResult> > libsumo::TraCIResults
for (auto entry : results) {
int i = entry.first;
shared_ptr<libsumo::TraCIResult> result = entry.second;
How can the TraCIResults be filtered for ' libsumo::VAR_ARRIVED_VEHICLES_ID' values, and
how to get the id values from the result?
Thanks for the help,
Bart Netten
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user