47 #ifdef CHECK_MEMORY_LEAKS
49 #endif // CHECK_MEMORY_LEAKS
73 oc.
addDescription(
"device.btreceiver.range",
"Communication",
"The range of the bt receiver");
76 oc.
addDescription(
"device.btreceiver.all-recognitions",
"Communication",
"Whether all recognition point shall be written");
79 oc.
addDescription(
"device.btreceiver.offtime",
"Communication",
"The offtime used for calculating detection probability (in seconds)");
90 into.push_back(device);
112 (*i).second->amOnNet =
false;
113 (*i).second->haveArrived =
true;
116 (*i).second->amOnNet =
false;
117 (*i).second->haveArrived =
true;
131 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
132 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
133 rt.
Insert(cmin, cmax, vi);
138 bool allRecognitions = oc.
getBool(
"device.btreceiver.all-recognitions");
139 bool haveOutput = oc.
isSet(
"bt-output");
145 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
146 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
147 std::set<std::string> surroundingVehicles;
149 rt.
Search(cmin, cmax, sv);
152 for (std::set<std::string>::const_iterator j = surroundingVehicles.begin(); j != surroundingVehicles.end(); ++j) {
153 if ((*i).first == *j) {
163 writeOutput((*i).first, vi->
seen, allRecognitions);
202 const Position& oldReceiverPosition = receiver.
updates.front().position;
210 std::vector<SUMOReal> intersections;
212 switch (intersections.size()) {
232 const Position intersection1Sender = oldSenderPosition + senderDelta * intersections.front();
233 const Position intersection1Receiver = oldReceiverPosition + receiverDelta * intersections.front();
236 sender.
getID(), intersection1Sender, senderData.
speed, senderData.
laneID, senderData.
lanePos, (intersections.front() - 1.) *
TS);
238 enterRange((intersections.front() - 1.) *
TS, intersection1Receiver, receiverData.
speed, receiverData.
laneID, receiverData.
lanePos,
246 const Position intersection1Sender = oldSenderPosition + senderDelta * intersections.front();
247 const Position intersection1Receiver = oldReceiverPosition + receiverDelta * intersections.front();
248 enterRange((intersections.front() - 1.) *
TS, intersection1Receiver, receiverData.
speed, receiverData.
laneID, receiverData.
lanePos,
250 const Position intersection2Sender = oldSenderPosition + senderDelta * intersections.back();
251 const Position intersection2Receiver = oldReceiverPosition + receiverDelta * intersections.back();
253 sender.
getID(), intersection2Sender, senderData.
speed, senderData.
laneID, senderData.
lanePos, (intersections.back() - 1.) *
TS);
255 WRITE_WARNING(
"The vehicle '" + sender.
getID() +
"' cannot be in the range of '" + receiver.
getID() +
"', leave, and enter it in one step.");
259 WRITE_WARNING(
"Nope, a circle cannot be crossed more often than twice by a line.");
268 const std::string& otherID,
const Position& otherPos,
SUMOReal otherSpeed,
const std::string& otherLaneID,
SUMOReal otherLanePos,
269 std::map<std::string, SeenDevice*>& currentlySeen) {
270 MeetingPoint mp(
SIMTIME + atOffset, thisPos, thisSpeed, thisLaneID, thisLanePos, otherPos, otherSpeed, otherLaneID, otherLanePos);
272 currentlySeen[otherID] = sd;
273 addRecognitionPoint(
SIMTIME, thisPos, thisSpeed, thisLaneID, thisLanePos,
274 otherPos, otherSpeed, otherLaneID, otherLanePos, sd);
281 const std::string& otherID,
const Position& otherPos,
SUMOReal otherSpeed,
const std::string& otherLaneID,
SUMOReal otherLanePos,
283 std::map<std::string, SeenDevice*>::iterator i = currentlySeen.find(otherID);
285 addRecognitionPoint(
SIMTIME + tOffset, thisPos, thisSpeed, thisLaneID, thisLanePos,
286 otherPos, otherSpeed, otherLaneID, otherLanePos, (*i).second);
289 (*i).second->meetingEnd = mp;
290 if (seen.find(otherID) == seen.end()) {
291 seen[otherID] = std::vector<SeenDevice*>();
293 seen[otherID].push_back((*i).second);
294 currentlySeen.erase(i);
306 MeetingPoint* mp =
new MeetingPoint(tEnd, thisPos, thisSpeed, thisLaneID, thisLanePos, otherPos, otherSpeed, otherLaneID, otherLanePos);
316 for (std::map<std::string, std::vector<SeenDevice*> >::const_iterator j = seen.begin(); j != seen.end(); ++j) {
317 const std::vector<SeenDevice*>& sts = (*j).second;
318 for (std::vector<SeenDevice*>::const_iterator k = sts.begin(); k != sts.end(); ++k) {
320 os.
writeAttr(
"tBeg", (*k)->meetingBegin.t)
321 .
writeAttr(
"observerPosBeg", (*k)->meetingBegin.observerPos).
writeAttr(
"observerSpeedBeg", (*k)->meetingBegin.observerSpeed)
322 .
writeAttr(
"observerLaneIDBeg", (*k)->meetingBegin.observerLaneID).
writeAttr(
"observerLanePosBeg", (*k)->meetingBegin.observerLanePos)
323 .
writeAttr(
"seenPosBeg", (*k)->meetingBegin.seenPos).
writeAttr(
"seenSpeedBeg", (*k)->meetingBegin.seenSpeed)
324 .
writeAttr(
"seenLaneIDBeg", (*k)->meetingBegin.seenLaneID).
writeAttr(
"seenLanePosBeg", (*k)->meetingBegin.seenLanePos);
326 .
writeAttr(
"observerPosEnd", (*k)->meetingEnd.observerPos).
writeAttr(
"observerSpeedEnd", (*k)->meetingEnd.observerSpeed)
327 .
writeAttr(
"observerLaneIDEnd", (*k)->meetingEnd.observerLaneID).
writeAttr(
"observerLanePosEnd", (*k)->meetingEnd.observerLanePos)
328 .
writeAttr(
"seenPosEnd", (*k)->meetingEnd.seenPos).
writeAttr(
"seenSpeedEnd", (*k)->meetingEnd.seenSpeed)
329 .
writeAttr(
"seenLaneIDEnd", (*k)->meetingEnd.seenLaneID).
writeAttr(
"seenLanePosEnd", (*k)->meetingEnd.seenLanePos);
330 for (std::vector<MeetingPoint*>::iterator l = (*k)->recognitionPoints.begin(); l != (*k)->recognitionPoints.end(); ++l) {
332 .
writeAttr(
"observerPos", (*l)->observerPos).
writeAttr(
"observerSpeed", (*l)->observerSpeed)
333 .
writeAttr(
"observerLaneID", (*l)->observerLaneID).
writeAttr(
"observerLanePos", (*l)->observerLanePos)
335 .
writeAttr(
"seenLaneID", (*l)->seenLaneID).
writeAttr(
"seenLanePos", (*l)->seenLanePos)
337 if (!allRecognitions) {
378 WRITE_WARNING(
"btreceiver: Can not update position of a vehicle that is not within the road network (" + veh.
getID() +
").");
392 WRITE_WARNING(
"btreceiver: Can not update position of a vehicle that is not within the road network (" + veh.
getID() +
").");
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Position position
The position of the vehicle.
Representation of a vehicle in the micro simulation.
A global update performer.
SUMOReal lanePos
The position at the lane of the vehicle.
SUMOReal ymin() const
Returns minimum y-coordinate.
std::string laneID
The lane the vehicle was at.
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle's position along the lane.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SUMOReal xmin() const
Returns minimum x-coordinate.
Notification
Definition of a vehicle state.
A RT-tree for efficient storing of SUMO's Named objects.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static MTRand sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, Notification reason)
Moves (the known) vehicle from running to arrived vehicles' list.
SUMOReal lastView
Last recognition point.
static void FindLineCircleIntersections(const Position &c, SUMOReal radius, const Position &p1, const Position &p2, std::vector< SUMOReal > &into)
Returns the positions the given circle is crossed by the given line.
SUMOReal xmax() const
Returns maximum x-coordinate.
A class that stores a 2D geometrical boundary.
const MSLane * getLane() const
Returns the lane the reminder works on.
#define WRITE_WARNING(msg)
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
static OptionsCont & getOptions()
Retrieves the options.
static SUMOReal myRange
The range of the device.
const std::string & getID() const
Returns the id.
Class representing a single seen device.
~BTreceiverUpdate()
Destructor.
Representation of a vehicle.
static bool myWasInitialised
Whether the bt-system was already initialised.
A point in 2D or 3D with translation and scaling methods.
A single movement state of the vehicle.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
The vehicle arrived at its destination (is deleted)
SUMOReal speed
The speed of the vehicle.
bool notifyEnter(SUMOVehicle &veh, Notification reason)
Adds the vehicle to running vehicles if it (re-) enters the network.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
~MSDevice_BTreceiver()
Destructor.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Abstract in-vehicle device.
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Allows to store the object; used as context while traveling the rtree in TraCI.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
The vehicle has departed (was inserted into the network)
virtual SUMOReal getSpeed() const =0
Returns the vehicle's current speed.
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 * > ¤tlySeen)
Informs the receiver about a sender entering it's radius.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
void seed(const uint32 oneSeed)
static SUMOReal myOffTime
The offtime of the device.
A storage for options typed value containers)
Patch the time in a way that it is at least as high as the simulation begin time. ...
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
SUMOReal ymax() const
Returns maximum y-coordinate.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
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 * > ¤tlySeen, 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.
virtual const std::string & getID() const =0
Get the vehicle's ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
BTreceiverUpdate()
Constructor.
The vehicle is being teleported.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.