SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_BTreceiver.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A BT receiver
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef MSDevice_BTreceiver_h
22 #define MSDevice_BTreceiver_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSDevice.h"
35 #include "MSDevice_BTsender.h"
36 #include <microsim/MSNet.h>
37 #include <utils/common/SUMOTime.h>
38 #include <utils/common/Command.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class SUMOVehicle;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
57 class MSDevice_BTreceiver : public MSDevice {
58 public:
62  static void insertOptions(OptionsCont& oc);
63 
64 
75  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
76 
77 
81  static SUMOReal getRange() {
82  return myRange;
83  }
84 
85 
86 
87 public:
90 
91 
92 
95 
104  bool notifyEnter(SUMOVehicle& veh, Notification reason);
105 
106 
120  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
121 
122 
133  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, Notification reason);
135 
136 
137 
141  class MeetingPoint {
142  public:
154  MeetingPoint(SUMOReal _t, const Position& _observerPos, SUMOReal _observerSpeed,
155  const std::string& _observerLaneID, SUMOReal _observerLanePos,
156  const Position& _seenPos, SUMOReal _seenSpeed,
157  const std::string& _seenLaneID, SUMOReal _seenLanePos)
158  : t(_t), observerPos(_observerPos), observerSpeed(_observerSpeed), observerLaneID(_observerLaneID), observerLanePos(_observerLanePos),
159  seenPos(_seenPos), seenSpeed(_seenSpeed), seenLaneID(_seenLaneID), seenLanePos(_seenLanePos) {}
160 
163 
164  public:
172  std::string observerLaneID;
180  std::string seenLaneID;
183 
184  };
185 
186 
187 
191  class SeenDevice {
192  public:
196  SeenDevice(const MeetingPoint& meetingBegin_)
197  : meetingBegin(meetingBegin_), meetingEnd(meetingBegin_), lastView(meetingBegin_.t) {}
198 
201  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
202  delete *i;
203  }
204  recognitionPoints.clear();
205  }
206 
207 
208  public:
216  std::vector<MeetingPoint*> recognitionPoints;
217 
218  };
219 
220 
221 
226  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
227 
228 
229 
230 protected:
236  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
237 
238 
239 
240 private:
242  static bool myWasInitialised;
243 
246 
249 
250 
255  public:
260  VehicleInformation(const std::string& id, const SUMOReal _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
261 
264 
267 
269  std::map<std::string, SeenDevice*> currentlySeen;
270 
272  std::map<std::string, std::vector<SeenDevice*> > seen;
273 
274  private:
277 
280 
281  };
282 
283 
284 
288  class BTreceiverUpdate : public Command {
289  public:
292 
295 
300  SUMOTime execute(SUMOTime currentTime);
301 
302 
308 
309 
323  void enterRange(SUMOReal atOffset, const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
324  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
325  std::map<std::string, SeenDevice*>& currentlySeen);
326 
327 
343  void leaveRange(std::map<std::string, SeenDevice*>& currentlySeen, std::map<std::string, std::vector<SeenDevice*> >& seen,
344  const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
345  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
346  SUMOReal tOffset);
347 
348 
349 
350 
363  void addRecognitionPoint(const SUMOReal tEnd, const Position& thisPos, const SUMOReal thisSpeed, const std::string& thisLaneID, const SUMOReal thisLanePos,
364  const Position& otherPos, const SUMOReal otherSpeed, const std::string& otherLaneID, const SUMOReal otherLanePos,
365  SeenDevice* otherDevice) const;
366 
367 
373  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
374  bool allRecognitions);
375 
376 
377 
378 
379  };
380 
381 
384 
386  static std::map<std::string, VehicleInformation*> sVehicles;
387 
388 
389 
390 private:
393 
396 
397 
398 };
399 
400 #endif
401 
402 /****************************************************************************/
403 
Position observerPos
The position the observer had at the time.
VehicleInformation(const std::string &id, const SUMOReal _range)
Constructor.
std::string seenLaneID
The lane the vehicle was at.
SUMOReal seenSpeed
The speed the vehicle had at the time.
SeenDevice(const MeetingPoint &meetingBegin_)
Constructor.
Notification
Definition of a vehicle state.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
static MTRand sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
SUMOReal observerLanePos
The position at the lane of the observer.
VehicleInformation & operator=(const VehicleInformation &)
Invalidated assignment operator.
MSDevice_BTreceiver & operator=(const MSDevice_BTreceiver &)
Invalidated assignment operator.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, Notification reason)
Moves (the known) vehicle from running to arrived vehicles&#39; list.
SUMOReal lastView
Last recognition point.
MeetingPoint meetingEnd
Description of the meeting&#39;s end.
Base (microsim) event class.
Definition: Command.h:61
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
SUMOReal t
The time of the meeting.
std::string observerLaneID
The lane the observer was at.
Position seenPos
The position the seen vehicle had at the time.
static SUMOReal myRange
The range of the device.
Class representing a single seen device.
Representation of a vehicle.
Definition: SUMOVehicle.h:64
static bool myWasInitialised
Whether the bt-system was already initialised.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
static void cleanUp(std::map< std::string, SeenDevice * > &c, std::map< std::string, std::vector< SeenDevice * > > &s)
Clears the given containers deleting the stored items.
bool notifyEnter(SUMOVehicle &veh, Notification reason)
Adds the vehicle to running vehicles if it (re-) enters the network.
~MSDevice_BTreceiver()
Destructor.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
Stores the information of a vehicle.
Abstract in-vehicle device.
Definition: MSDevice.h:69
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
void addRecognitionPoint(const SUMOReal tEnd, const Position &thisPos, const SUMOReal thisSpeed, const std::string &thisLaneID, const SUMOReal thisLanePos, const Position &otherPos, const SUMOReal otherSpeed, const std::string &otherLaneID, const SUMOReal otherLanePos, SeenDevice *otherDevice) const
Adds a point of recognition.
void enterRange(SUMOReal atOffset, const Position &thisPos, SUMOReal thisSpeed, const std::string &thisLaneID, SUMOReal thisLanePos, const std::string &otherID, const Position &otherPos, SUMOReal otherSpeed, const std::string &otherLaneID, SUMOReal otherLanePos, std::map< std::string, SeenDevice * > &currentlySeen)
Informs the receiver about a sender entering it&#39;s radius.
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
static SUMOReal myOffTime
The offtime of the device.
A storage for options typed value containers)
Definition: OptionsCont.h:108
int SUMOTime
Definition: SUMOTime.h:43
const SUMOReal range
Recognition range of the vehicle.
SUMOReal seenLanePos
The position at the lane of the vehicle.
MeetingPoint meetingBegin
Description of the meeting&#39;s begin.
#define SUMOReal
Definition: config.h:218
Stores the information of a vehicle.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
static SUMOReal getRange()
Returns the configured range.
MeetingPoint(SUMOReal _t, const Position &_observerPos, SUMOReal _observerSpeed, const std::string &_observerLaneID, SUMOReal _observerLanePos, const Position &_seenPos, SUMOReal _seenSpeed, const std::string &_seenLaneID, SUMOReal _seenLanePos)
Constructor.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
void leaveRange(std::map< std::string, SeenDevice * > &currentlySeen, std::map< std::string, std::vector< SeenDevice * > > &seen, const Position &thisPos, SUMOReal thisSpeed, const std::string &thisLaneID, SUMOReal thisLanePos, const std::string &otherID, const Position &otherPos, SUMOReal otherSpeed, const std::string &otherLaneID, SUMOReal otherLanePos, SUMOReal tOffset)
Removes the sender from the currently seen devices to past episodes.
SUMOReal observerSpeed
The speed the observer had at the time.