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-sim.org/
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 
78 
79 public:
82 
83 
84 
87 
96  bool notifyEnter(SUMOVehicle& veh, Notification reason);
97 
98 
112  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
113 
114 
125  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, Notification reason);
127 
128 
129 
133  class MeetingPoint {
134  public:
146  MeetingPoint(SUMOReal _t, const Position& _observerPos, SUMOReal _observerSpeed,
147  const std::string& _observerLaneID, SUMOReal _observerLanePos,
148  const Position& _seenPos, SUMOReal _seenSpeed,
149  const std::string& _seenLaneID, SUMOReal _seenLanePos)
150  : t(_t), observerPos(_observerPos), observerSpeed(_observerSpeed), observerLaneID(_observerLaneID), observerLanePos(_observerLanePos),
151  seenPos(_seenPos), seenSpeed(_seenSpeed), seenLaneID(_seenLaneID), seenLanePos(_seenLanePos) {}
152 
155 
156  public:
164  std::string observerLaneID;
172  std::string seenLaneID;
175 
176  };
177 
178 
179 
183  class SeenDevice {
184  public:
188  SeenDevice(const MeetingPoint& meetingBegin_)
189  : meetingBegin(meetingBegin_), meetingEnd(meetingBegin_), lastView(meetingBegin_.t) {}
190 
193  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
194  delete *i;
195  }
196  recognitionPoints.clear();
197  }
198 
199 
200  public:
208  std::vector<MeetingPoint*> recognitionPoints;
209 
210  };
211 
212 
213 
218  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
219 
220 
221 
222 protected:
228  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id, SUMOReal range);
229 
230 
231 
232 private:
235 
237  static bool myWasInitialised;
238 
239 
240 
244  class VehicleState {
245  public:
254  VehicleState(SUMOReal _time, SUMOReal _speed, SUMOReal _angle, const Position& _position, const std::string& _laneID, SUMOReal _lanePos)
255  : time(_time), speed(_speed), angle(_angle), position(_position), laneID(_laneID), lanePos(_lanePos) {}
256 
259 
269  std::string laneID;
272 
273  };
274 
275 
276 
280  class VehicleInformation : public Named {
281  public:
286  VehicleInformation(const std::string& id, const SUMOReal _range) : Named(id), range(_range), amOnNet(true), haveArrived(false) {}
287 
290 
291 
296  Boundary ret;
297  for (std::vector<VehicleState>::const_iterator i = updates.begin(); i != updates.end(); ++i) {
298  ret.add((*i).position);
299  }
300  return ret;
301  }
302 
305 
307  std::vector<VehicleState> updates;
308 
310  bool amOnNet;
311 
314 
316  std::map<std::string, SeenDevice*> currentlySeen;
317 
319  std::map<std::string, std::vector<SeenDevice*> > seen;
320 
321  private:
324 
327 
328  };
329 
330 
331 
335  class BTreceiverUpdate : public Command {
336  public:
339 
342 
347  SUMOTime execute(SUMOTime currentTime);
348 
349 
357  const Position& receiverPos, const Position& receiverD);
358 
359 
373  void enterRange(SUMOReal atOffset, const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
374  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
375  std::map<std::string, SeenDevice*>& currentlySeen);
376 
377 
393  void leaveRange(std::map<std::string, SeenDevice*>& currentlySeen, std::map<std::string, std::vector<SeenDevice*> >& seen,
394  const Position& thisPos, SUMOReal thisSpeed, const std::string& thisLaneID, SUMOReal thisLanePos,
395  const std::string& otherID, const Position& otherPos, SUMOReal otherSpeed, const std::string& otherLaneID, SUMOReal otherLanePos,
396  SUMOReal tOffset);
397 
398 
399 
400 
413  void addRecognitionPoint(const SUMOReal tEnd, const Position& thisPos, const SUMOReal thisSpeed, const std::string& thisLaneID, const SUMOReal thisLanePos,
414  const Position& otherPos, const SUMOReal otherSpeed, const std::string& otherLaneID, const SUMOReal otherLanePos,
415  SeenDevice* otherDevice) const;
416 
417 
423  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
424  bool allRecognitions);
425 
426 
427 
428 
429  };
430 
431 
434 
436  static std::map<std::string, VehicleInformation*> sVehicles;
437 
438 
439 
440 private:
443 
446 
447 
448 };
449 
450 #endif
451 
452 /****************************************************************************/
453