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 /****************************************************************************/
7 // A BT receiver
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MSDevice_BTreceiver_h
21 #define MSDevice_BTreceiver_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSDevice.h"
34 #include "MSDevice_BTsender.h"
35 #include <microsim/MSNet.h>
36 #include <utils/common/SUMOTime.h>
37 #include <utils/common/Command.h>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class SUMOVehicle;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
56 class MSDevice_BTreceiver : public MSDevice {
57 public:
61  static void insertOptions(OptionsCont& oc);
62 
63 
74  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
75 
76 
77 
78 public:
81 
82 
83 
86 
95  bool notifyEnter(SUMOVehicle& veh, Notification reason);
96 
97 
111  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
112 
113 
124  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, Notification reason);
126 
127 
128 
132  class MeetingPoint {
133  public:
145  MeetingPoint(SUMOReal _t, const Position& _observerPos, SUMOReal _observerSpeed,
146  const std::string& _observerLaneID, SUMOReal _observerLanePos,
147  const Position& _seenPos, SUMOReal _seenSpeed,
148  const std::string& _seenLaneID, SUMOReal _seenLanePos)
149  : t(_t), observerPos(_observerPos), observerSpeed(_observerSpeed), observerLaneID(_observerLaneID), observerLanePos(_observerLanePos),
150  seenPos(_seenPos), seenSpeed(_seenSpeed), seenLaneID(_seenLaneID), seenLanePos(_seenLanePos) {}
151 
154 
155  public:
163  std::string observerLaneID;
171  std::string seenLaneID;
174 
175  };
176 
177 
178 
182  class SeenDevice {
183  public:
187  SeenDevice(const MeetingPoint& meetingBegin_)
188  : meetingBegin(meetingBegin_), meetingEnd(meetingBegin_), lastView(meetingBegin_.t) {}
189 
192  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
193  delete *i;
194  }
195  recognitionPoints.clear();
196  }
197 
198 
199  public:
207  std::vector<MeetingPoint*> recognitionPoints;
208 
209  };
210 
211 
212 
217  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
218 
219 
220 
221 protected:
227  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id, SUMOReal range);
228 
229 
230 
231 private:
234 
236  static bool myWasInitialised;
237 
238 
239 
243  class VehicleState {
244  public:
253  VehicleState(SUMOReal _time, SUMOReal _speed, SUMOReal _angle, const Position& _position, const std::string& _laneID, SUMOReal _lanePos)
254  : time(_time), speed(_speed), angle(_angle), position(_position), laneID(_laneID), lanePos(_lanePos) {}
255 
258 
268  std::string laneID;
271 
272  };
273 
274 
275 
279  class VehicleInformation : public Named {
280  public:
285  VehicleInformation(const std::string& id, const SUMOReal _range) : Named(id), range(_range), amOnNet(true), haveArrived(false) {}
286 
289 
290 
295  Boundary ret;
296  for (std::vector<VehicleState>::const_iterator i = updates.begin(); i != updates.end(); ++i) {
297  ret.add((*i).position);
298  }
299  return ret;
300  }
301 
304 
306  std::vector<VehicleState> updates;
307 
309  bool amOnNet;
310 
313 
315  std::map<std::string, SeenDevice*> currentlySeen;
316 
318  std::map<std::string, std::vector<SeenDevice*> > seen;
319 
320  private:
323 
326 
327  };
328 
329 
330 
334  class BTreceiverUpdate : public Command {
335  public:
338 
341 
346  SUMOTime execute(SUMOTime currentTime);
347 
348 
356  const Position& receiverPos, const Position& receiverD);
357 
358 
372  void enterRange(SUMOReal atOffset, const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
373  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
374  std::map<std::string, SeenDevice*>& currentlySeen);
375 
376 
392  void leaveRange(std::map<std::string, SeenDevice*>& currentlySeen, std::map<std::string, std::vector<SeenDevice*> >& seen,
393  const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
394  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
395  SUMOReal tOffset);
396 
397 
398 
399 
406  //SUMOReal recognizedAt(const std::string &otherID, SUMOReal tEnd, std::map<std::string, SeenDevice*> &currentlySeen);
407 
408 
422  void addRecognitionPoint(SUMOReal tEnd, const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
423  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
424  std::map<std::string, SeenDevice*>& currentlySeen);
425 
426 
432  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
433  bool allRecognitions);
434 
435 
436 
437 
438  };
439 
440 
443 
445  static std::map<std::string, VehicleInformation*> sVehicles;
446 
447 
448 
449 private:
452 
455 
456 
457 };
458 
459 #endif
460 
461 /****************************************************************************/
462 
Position observerPos
The position the observer had at the time.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender, const Position &receiverPos, const Position &receiverD)
Rechecks the visibility for a given receiver/sender pair.
VehicleInformation(const std::string &id, const SUMOReal _range)
Constructor.
std::string seenLaneID
The lane the vehicle was at.
bool haveArrived
Whether the vehicle was removed from the simulation.
VehicleState(SUMOReal _time, SUMOReal _speed, SUMOReal _angle, const Position &_position, const std::string &_laneID, SUMOReal _lanePos)
Constructor.
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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
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.
SUMOReal myRange
The range of the device.
Class representing a single seen device.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
static bool myWasInitialised
Whether the bt-system was already initialised.
SUMOReal lanePos
The position at the lane of the vehicle.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal time
The current time.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
Position position
The position of the vehicle.
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.
Base class for objects which have an id.
Definition: Named.h:45
Stores the information of a vehicle.
Abstract in-vehicle device.
Definition: MSDevice.h:68
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
void addRecognitionPoint(SUMOReal tEnd, 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)
Determines whether the other vehicle got visible until the given time.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
Boundary getBoxBoundary() const
Returns the boundary of passed positions.
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.
std::vector< VehicleState > updates
List of position updates during last step.
A storage for options typed value containers)
Definition: OptionsCont.h:108
const SUMOReal range
Recognition range of the vehicle.
SUMOReal seenLanePos
The position at the lane of the vehicle.
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id, SUMOReal range)
Constructor.
MeetingPoint meetingBegin
Description of the meeting&#39;s begin.
#define SUMOReal
Definition: config.h:215
Stores the information of a vehicle.
SUMOReal speed
The speed of the vehicle.
bool amOnNet
Whether the vehicle is within the simulated network.
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.
SUMOReal angle
The angle of the vehicle.
std::string laneID
The lane the vehicle was at.