Eclipse SUMO - Simulation of Urban MObility
MSDevice_BTreceiver.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A BT Receiver
21 /****************************************************************************/
22 #include <config.h>
23 
28 #include <utils/geom/Position.h>
29 #include <utils/geom/GeomHelper.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSVehicle.h>
37 #include "MSDevice_Tripinfo.h"
38 #include "MSDevice_BTreceiver.h"
39 #include "MSDevice_BTsender.h"
40 
41 
42 // ===========================================================================
43 // static members
44 // ===========================================================================
47 double MSDevice_BTreceiver::myRange = -1.;
50 std::map<std::string, MSDevice_BTreceiver::VehicleInformation*> MSDevice_BTreceiver::sVehicles;
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 // ---------------------------------------------------------------------------
57 // static initialisation methods
58 // ---------------------------------------------------------------------------
59 
60 void
62  insertDefaultAssignmentOptions("btreceiver", "Communication", oc);
63 
64  oc.doRegister("device.btreceiver.range", new Option_Float(300));
65  oc.addDescription("device.btreceiver.range", "Communication", TL("The range of the bt receiver"));
66 
67  oc.doRegister("device.btreceiver.all-recognitions", new Option_Bool(false));
68  oc.addDescription("device.btreceiver.all-recognitions", "Communication", TL("Whether all recognition point shall be written"));
69 
70  oc.doRegister("device.btreceiver.offtime", new Option_Float(0.64));
71  oc.addDescription("device.btreceiver.offtime", "Communication", TL("The offtime used for calculating detection probability (in seconds)"));
72 
73  myWasInitialised = false;
74  myHasPersons = false;
75 }
76 
77 
78 void
79 MSVehicleDevice_BTreceiver::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
81  if (equippedByDefaultAssignmentOptions(oc, "btreceiver", v, false)) {
82  MSVehicleDevice_BTreceiver* device = new MSVehicleDevice_BTreceiver(v, "btreceiver_" + v.getID());
83  into.push_back(device);
84  if (!myWasInitialised) {
85  new BTreceiverUpdate();
86  myWasInitialised = true;
87  myRange = oc.getFloat("device.btreceiver.range");
88  myOffTime = oc.getFloat("device.btreceiver.offtime");
89  sRecognitionRNG.seed(oc.getInt("seed"));
90  }
91  }
92 }
93 
94 void
96  insertDefaultAssignmentOptions("btreceiver", "Communication", oc, true);
97 }
98 
99 
100 void
101 MSTransportableDevice_BTreceiver::buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into) {
103  if (equippedByDefaultAssignmentOptions(oc, "btreceiver", t, false, true)) {
104  MSTransportableDevice_BTreceiver* device = new MSTransportableDevice_BTreceiver(t, "btreceiver_" + t.getID());
105  into.push_back(device);
106  myHasPersons = true;
107  if (!myWasInitialised) {
108  new BTreceiverUpdate();
109  myWasInitialised = true;
110  myRange = oc.getFloat("device.btreceiver.range");
111  myOffTime = oc.getFloat("device.btreceiver.offtime");
112  sRecognitionRNG.seed(oc.getInt("seed"));
113  }
114  }
115 }
116 
117 
118 // ---------------------------------------------------------------------------
119 // MSDevice_BTreceiver::BTreceiverUpdate-methods
120 // ---------------------------------------------------------------------------
123 }
124 
125 
127  for (const auto& vehicleInfo : MSDevice_BTsender::sVehicles) {
128  vehicleInfo.second->amOnNet = false;
129  vehicleInfo.second->haveArrived = true;
130  }
131  for (const auto& vehicleInfo : MSDevice_BTreceiver::sVehicles) {
132  vehicleInfo.second->amOnNet = false;
133  vehicleInfo.second->haveArrived = true;
134  }
135  execute(MSNet::getInstance()->getCurrentTimeStep());
136 }
137 
138 
139 SUMOTime
141  // loop over equipped persons to update their positions
142  if (myHasPersons && MSNet::getInstance()->hasPersons()) { // the check whether the net has persons is only important in the final cleanup
144  for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
145  MSTransportable* t = i->second;
149  if (snd) {
150  snd->notifyMove(*t, t->getPositionOnLane(), t->getPositionOnLane(), t->getSpeed());
151  if (MSDevice_BTsender::sVehicles[t->getID()]->route.back() != t->getEdge()) {
152  MSDevice_BTsender::sVehicles[t->getID()]->route.push_back(t->getEdge());
153  }
154  }
155  if (rec) {
156  rec->notifyMove(*t, t->getPositionOnLane(), t->getPositionOnLane(), t->getSpeed());
157  if (sVehicles[t->getID()]->route.back() != t->getEdge()) {
158  sVehicles[t->getID()]->route.push_back(t->getEdge());
159  }
160  }
161  }
162  }
163  }
164 
165  // build rtree with senders
166  NamedRTree rt;
167  for (std::map<std::string, MSDevice_BTsender::VehicleInformation*>::const_iterator i = MSDevice_BTsender::sVehicles.begin(); i != MSDevice_BTsender::sVehicles.end(); ++i) {
168  MSDevice_BTsender::VehicleInformation* vi = (*i).second;
169  Boundary b = vi->getBoxBoundary();
170  b.grow(POSITION_EPS);
171  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
172  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
173  rt.Insert(cmin, cmax, vi);
174  }
175 
176  // check visibility for all receivers
178  bool allRecognitions = oc.getBool("device.btreceiver.all-recognitions");
179  bool haveOutput = oc.isSet("bt-output");
180  for (std::map<std::string, MSDevice_BTreceiver::VehicleInformation*>::iterator i = MSDevice_BTreceiver::sVehicles.begin(); i != MSDevice_BTreceiver::sVehicles.end();) {
181  // collect surrounding vehicles
182  MSDevice_BTreceiver::VehicleInformation* vi = (*i).second;
183  Boundary b = vi->getBoxBoundary();
184  b.grow(vi->range);
185  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
186  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
187  std::set<const Named*> surroundingVehicles;
188  Named::StoringVisitor sv(surroundingVehicles);
189  rt.Search(cmin, cmax, sv);
190 
191  // loop over surrounding vehicles, check visibility status
192  for (const Named* vehicle : surroundingVehicles) {
193  if ((*i).first == vehicle->getID()) {
194  // seeing oneself? skip
195  continue;
196  }
197  updateVisibility(*vi, *MSDevice_BTsender::sVehicles.find(vehicle->getID())->second);
198  }
199 
200  if (vi->haveArrived) {
201  // vehicle has left the simulation; remove
202  if (haveOutput) {
203  writeOutput((*i).first, vi->seen, allRecognitions);
204  }
205  delete vi;
207  } else {
208  // vehicle is still in the simulation; reset state
209  vi->updates.erase(vi->updates.begin(), vi->updates.end() - 1);
210  ++i;
211  }
212  }
213 
214  // remove arrived senders / reset state
215  for (std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i = MSDevice_BTsender::sVehicles.begin(); i != MSDevice_BTsender::sVehicles.end();) {
216  MSDevice_BTsender::VehicleInformation* vi = (*i).second;
217  if (vi->haveArrived) {
218  delete vi;
219  MSDevice_BTsender::sVehicles.erase(i++);
220  } else {
221  vi->updates.erase(vi->updates.begin(), vi->updates.end() - 1);
222  ++i;
223  }
224  }
225  return DELTA_T;
226 }
227 
228 
229 void
232  const MSDevice_BTsender::VehicleState& receiverData = receiver.updates.back();
233  const MSDevice_BTsender::VehicleState& senderData = sender.updates.back();
234  if (!receiver.amOnNet || !sender.amOnNet) {
235  // at least one of the vehicles has left the simulation area for any reason
236  if (receiver.currentlySeen.find(sender.getID()) != receiver.currentlySeen.end()) {
237  leaveRange(receiver, receiverData, sender, senderData, 0);
238  }
239  }
240 
241  const Position& oldReceiverPosition = receiver.updates.front().position;
242  const Position& oldSenderPosition = sender.updates.front().position;
243 
244  // let the other's current position be the one obtained by applying the relative direction vector to the initial position
245  const Position senderDelta = senderData.position - oldSenderPosition;
246  const Position receiverDelta = receiverData.position - oldReceiverPosition;
247  const Position translatedSender = senderData.position - receiverDelta;
248  // find crossing points
249  std::vector<double> intersections;
250  GeomHelper::findLineCircleIntersections(oldReceiverPosition, receiver.range, oldSenderPosition, translatedSender, intersections);
251  switch (intersections.size()) {
252  case 0:
253  // no intersections -> other vehicle either stays within or beyond range
254  if (receiver.amOnNet && sender.amOnNet && receiverData.position.distanceTo(senderData.position) < receiver.range) {
255  if (receiver.currentlySeen.find(sender.getID()) == receiver.currentlySeen.end()) {
256  enterRange(0., receiverData, sender.getID(), senderData, receiver.currentlySeen);
257  } else {
258  addRecognitionPoint(SIMTIME, receiverData, senderData, receiver.currentlySeen[sender.getID()]);
259  }
260  } else {
261  if (receiver.currentlySeen.find(sender.getID()) != receiver.currentlySeen.end()) {
262  leaveRange(receiver, receiverData, sender, senderData, 0.);
263  }
264  }
265  break;
266  case 1: {
267  // one intersection -> other vehicle either enters or leaves the range
268  MSDevice_BTsender::VehicleState intersection1ReceiverData(receiverData);
269  intersection1ReceiverData.position = oldReceiverPosition + receiverDelta * intersections.front();
270  MSDevice_BTsender::VehicleState intersection1SenderData(senderData);
271  intersection1SenderData.position = oldSenderPosition + senderDelta * intersections.front();
272  if (receiver.currentlySeen.find(sender.getID()) != receiver.currentlySeen.end()) {
273  leaveRange(receiver, intersection1ReceiverData,
274  sender, intersection1SenderData, (intersections.front() - 1.) * TS);
275  } else {
276  enterRange((intersections.front() - 1.) * TS, intersection1ReceiverData,
277  sender.getID(), intersection1SenderData, receiver.currentlySeen);
278  }
279  }
280  break;
281  case 2:
282  // two intersections -> other vehicle enters and leaves the range
283  if (receiver.currentlySeen.find(sender.getID()) == receiver.currentlySeen.end()) {
284  MSDevice_BTsender::VehicleState intersectionReceiverData(receiverData);
285  intersectionReceiverData.position = oldReceiverPosition + receiverDelta * intersections.front();
286  MSDevice_BTsender::VehicleState intersectionSenderData(senderData);
287  intersectionSenderData.position = oldSenderPosition + senderDelta * intersections.front();
288  enterRange((intersections.front() - 1.) * TS, intersectionReceiverData,
289  sender.getID(), intersectionSenderData, receiver.currentlySeen);
290  intersectionReceiverData.position = oldReceiverPosition + receiverDelta * intersections.back();
291  intersectionSenderData.position = oldSenderPosition + senderDelta * intersections.back();
292  leaveRange(receiver, intersectionReceiverData,
293  sender, intersectionSenderData, (intersections.back() - 1.) * TS);
294  } else {
295  WRITE_WARNINGF(TL("The vehicle '%' cannot be in the range of vehicle '%', leave, and enter it in one step."), sender.getID(), receiver.getID());
296  }
297  break;
298  default:
299  WRITE_WARNING("Nope, a circle cannot be crossed more often than twice by a line.");
300  break;
301  }
302 }
303 
304 
305 void
307  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
308  std::map<std::string, SeenDevice*>& currentlySeen) {
309  MeetingPoint mp(SIMTIME + atOffset, receiverState, senderState);
310  SeenDevice* sd = new SeenDevice(mp);
311  currentlySeen[senderID] = sd;
312  addRecognitionPoint(SIMTIME, receiverState, senderState, sd);
313 }
314 
315 
316 void
319  double tOffset) {
320  std::map<std::string, SeenDevice*>::iterator i = receiverInfo.currentlySeen.find(senderInfo.getID());
321  // check whether the other was recognized
322  addRecognitionPoint(SIMTIME + tOffset, receiverState, senderState, i->second);
323  // build leaving point
324  i->second->meetingEnd = new MeetingPoint(STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()) + tOffset, receiverState, senderState);
325  ConstMSEdgeVector::const_iterator begin = receiverInfo.route.begin() + i->second->meetingBegin.observerState.routePos;
326  ConstMSEdgeVector::const_iterator end = receiverInfo.route.begin() + receiverState.routePos + 1;
327  i->second->receiverRoute = toString<const MSEdge>(begin, end);
328  begin = senderInfo.route.begin() + i->second->meetingBegin.seenState.routePos;
329  end = senderInfo.route.begin() + senderState.routePos + 1;
330  i->second->senderRoute = toString<const MSEdge>(begin, end);
331  receiverInfo.seen[senderInfo.getID()].push_back(i->second);
332  receiverInfo.currentlySeen.erase(i);
333 }
334 
335 
336 void
338  const MSDevice_BTsender::VehicleState& senderState,
339  SeenDevice* senderDevice) const {
340  if (senderDevice->nextView == -1.) {
341  senderDevice->nextView = senderDevice->lastView + inquiryDelaySlots(int(myOffTime / 0.000625 + .5)) * 0.000625;
342  }
343  if (tEnd > senderDevice->nextView) {
344  senderDevice->lastView = senderDevice->nextView;
345  MeetingPoint* mp = new MeetingPoint(tEnd, receiverState, senderState);
346  senderDevice->recognitionPoints.push_back(mp);
347  senderDevice->nextView = senderDevice->lastView + inquiryDelaySlots(int(myOffTime / 0.000625 + .5)) * 0.000625;
348  }
349 }
350 
351 
352 void
353 MSDevice_BTreceiver::BTreceiverUpdate::writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen, bool allRecognitions) {
355  os.openTag("bt").writeAttr("id", id);
356  for (std::map<std::string, std::vector<SeenDevice*> >::const_iterator j = seen.begin(); j != seen.end(); ++j) {
357  const std::vector<SeenDevice*>& sts = (*j).second;
358  for (std::vector<SeenDevice*>::const_iterator k = sts.begin(); k != sts.end(); ++k) {
359  os.openTag("seen").writeAttr("id", (*j).first);
360  const MSDevice_BTsender::VehicleState& obsBeg = (*k)->meetingBegin.observerState;
361  const MSDevice_BTsender::VehicleState& seenBeg = (*k)->meetingBegin.seenState;
362  os.writeAttr("tBeg", (*k)->meetingBegin.t)
363  .writeAttr("observerPosBeg", obsBeg.position).writeAttr("observerSpeedBeg", obsBeg.speed)
364  .writeAttr("observerLaneIDBeg", obsBeg.laneID).writeAttr("observerLanePosBeg", obsBeg.lanePos)
365  .writeAttr("seenPosBeg", seenBeg.position).writeAttr("seenSpeedBeg", seenBeg.speed)
366  .writeAttr("seenLaneIDBeg", seenBeg.laneID).writeAttr("seenLanePosBeg", seenBeg.lanePos);
367  const MSDevice_BTsender::VehicleState& obsEnd = (*k)->meetingEnd->observerState;
368  const MSDevice_BTsender::VehicleState& seenEnd = (*k)->meetingEnd->seenState;
369  os.writeAttr("tEnd", (*k)->meetingEnd->t)
370  .writeAttr("observerPosEnd", obsEnd.position).writeAttr("observerSpeedEnd", obsEnd.speed)
371  .writeAttr("observerLaneIDEnd", obsEnd.laneID).writeAttr("observerLanePosEnd", obsEnd.lanePos)
372  .writeAttr("seenPosEnd", seenEnd.position).writeAttr("seenSpeedEnd", seenEnd.speed)
373  .writeAttr("seenLaneIDEnd", seenEnd.laneID).writeAttr("seenLanePosEnd", seenEnd.lanePos)
374  .writeAttr("observerRoute", (*k)->receiverRoute).writeAttr("seenRoute", (*k)->senderRoute);
375  for (std::vector<MeetingPoint*>::iterator l = (*k)->recognitionPoints.begin(); l != (*k)->recognitionPoints.end(); ++l) {
376  os.openTag("recognitionPoint").writeAttr("t", (*l)->t)
377  .writeAttr("observerPos", (*l)->observerState.position).writeAttr("observerSpeed", (*l)->observerState.speed)
378  .writeAttr("observerLaneID", (*l)->observerState.laneID).writeAttr("observerLanePos", (*l)->observerState.lanePos)
379  .writeAttr("seenPos", (*l)->seenState.position).writeAttr("seenSpeed", (*l)->seenState.speed)
380  .writeAttr("seenLaneID", (*l)->seenState.laneID).writeAttr("seenLanePos", (*l)->seenState.lanePos)
381  .closeTag();
382  if (!allRecognitions) {
383  break;
384  }
385  }
386  os.closeTag();
387  }
388  }
389  os.closeTag();
390 }
391 
392 
393 // ---------------------------------------------------------------------------
394 // MSDevice_BTreceiver-methods
395 // ---------------------------------------------------------------------------
397 }
398 
399 
400 bool
402  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
403  sVehicles[veh.getID()] = new VehicleInformation(veh.getID(), myRange);
404  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
405  }
406  if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
407  sVehicles[veh.getID()]->amOnNet = true;
408  }
410  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
411  }
412  const std::string location = MSDevice_BTsender::getLocation(veh);
413  sVehicles[veh.getID()]->updates.push_back(MSDevice_BTsender::VehicleState(veh.getSpeed(), veh.getPosition(), location, veh.getPositionOnLane(), veh.getRoutePosition()));
414  return true;
415 }
416 
417 
418 bool
419 MSDevice_BTreceiver::notifyMove(SUMOTrafficObject& veh, double /* oldPos */, double newPos, double newSpeed) {
420  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
421  WRITE_WARNINGF(TL("btreceiver: Can not update position of vehicle '%' which is not on the road."), veh.getID());
422  return true;
423  }
424  const std::string location = MSDevice_BTsender::getLocation(veh);
425  sVehicles[veh.getID()]->updates.push_back(MSDevice_BTsender::VehicleState(newSpeed, veh.getPosition(), location, newPos, veh.getRoutePosition()));
426  return true;
427 }
428 
429 
430 bool
431 MSDevice_BTreceiver::notifyLeave(SUMOTrafficObject& veh, double /* lastPos */, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
433  return true;
434  }
435  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
436  WRITE_WARNINGF(TL("btreceiver: Can not update position of vehicle '%' which is not on the road."), veh.getID());
437  return true;
438  }
439  const std::string location = MSDevice_BTsender::getLocation(veh);
440  sVehicles[veh.getID()]->updates.push_back(MSDevice_BTsender::VehicleState(veh.getSpeed(), veh.getPosition(), location, veh.getPositionOnLane(), veh.getRoutePosition()));
442  sVehicles[veh.getID()]->amOnNet = false;
443  }
444  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
445  sVehicles[veh.getID()]->amOnNet = false;
446  sVehicles[veh.getID()]->haveArrived = true;
447  }
448  return true;
449 }
450 
451 
452 double
453 MSDevice_BTreceiver::inquiryDelaySlots(const int backoffLimit) {
454  const int phaseOffset = RandHelper::rand(2047, &sRecognitionRNG);
455  const bool interlaced = RandHelper::rand(&sRecognitionRNG) < 0.7;
456  const double delaySlots = RandHelper::rand(&sRecognitionRNG) * 15;
457  const int backoff = RandHelper::rand(backoffLimit, &sRecognitionRNG);
458  if (interlaced) {
459  return RandHelper::rand(&sRecognitionRNG) * 31 + backoff;
460  }
461  if (RandHelper::rand(31, &sRecognitionRNG) < 16) {
462  // correct train for f0
463  return delaySlots + backoff;
464  }
465  if (RandHelper::rand(30, &sRecognitionRNG) < 16) {
466  // correct train for f1
467  return 2048 - phaseOffset + delaySlots + backoff;
468  }
469  if (RandHelper::rand(29, &sRecognitionRNG) < 16) {
470  // f2 is in train A but has overlap with both trains
471  if (2 * 2048 - phaseOffset + backoff < 4096) {
472  return 2 * 2048 - phaseOffset + delaySlots + backoff;
473  }
474  // the following is wrong but should only happen in about 3% of the non-interlaced cases
475  return 2 * 2048 - phaseOffset + delaySlots + backoff;
476  }
477  return 2 * 2048 + delaySlots + backoff;
478 }
479 
480 
481 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TL(string)
Definition: MsgHandler.h:315
SUMOTime DELTA_T
Definition: SUMOTime.cpp:38
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
#define TS
Definition: SUMOTime.h:42
#define SIMTIME
Definition: SUMOTime.h:62
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:118
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:124
static void findLineCircleIntersections(const Position &c, double radius, const Position &p1, const Position &p2, std::vector< double > &into)
Returns the positions the given circle is crossed by the given line.
Definition: GeomHelper.cpp:46
void leaveRange(VehicleInformation &receiverInfo, const MSDevice_BTsender::VehicleState &receiverState, MSDevice_BTsender::VehicleInformation &senderInfo, const MSDevice_BTsender::VehicleState &senderState, double tOffset)
Removes the sender from the currently seen devices to past episodes.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState &receiverState, const MSDevice_BTsender::VehicleState &senderState, SeenDevice *senderDevice) const
Adds a point of recognition.
void enterRange(double atOffset, const MSDevice_BTsender::VehicleState &receiverState, const std::string &senderID, const MSDevice_BTsender::VehicleState &senderState, std::map< std::string, SeenDevice * > &currentlySeen)
Informs the receiver about a sender entering it's radius.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
Class representing a single seen device.
double nextView
Next possible recognition point.
double lastView
Last recognition point.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
Stores the information of a vehicle.
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
const double range
Recognition range of the vehicle.
static bool myWasInitialised
Whether the bt-system was already initialised.
static double inquiryDelaySlots(const int backoffLimit)
static double myRange
The range of the device.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static SumoRNG sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
static bool myHasPersons
Whether the bt-system includes persons.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
static double myOffTime
The offtime of the device.
Stores the information of a vehicle.
bool amOnNet
Whether the vehicle is within the simulated network.
bool haveArrived
Whether the vehicle was removed from the simulation.
ConstMSEdgeVector route
List of edges travelled.
Boundary getBoxBoundary() const
Returns the boundary of passed positions.
std::vector< VehicleState > updates
List of position updates during last step.
A single movement state of the vehicle.
int routePos
The position in the route of the vehicle.
double speed
The speed of the vehicle.
Position position
The position of the vehicle.
double lanePos
The position at the lane of the vehicle.
std::string laneID
The lane the vehicle was at.
static std::string getLocation(const SUMOTrafficObject &o)
return either lane or edge id (depending on availability)
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:203
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:481
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1173
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
MSTransportableDevice_BTreceiver(MSTransportable &holder, const std::string &id)
Constructor.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
virtual double getSpeed() const
the current speed of the transportable
double getPositionOnLane() const
Get the object's position along the lane.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or nullptr if not.
MSVehicleDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:90
Base class for objects which have an id.
Definition: Named.h:54
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:61
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:79
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
Definition: NamedRTree.h:112
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition: Position.h:261
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94
Representation of a vehicle, person, or container.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual int getRoutePosition() const =0
return index of edge within route
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static double sd[6]
Definition: odrSpiral.cpp:57