45 #ifdef CHECK_MEMORY_LEAKS
47 #endif // CHECK_MEMORY_LEAKS
69 oc.
addDescription(
"device.btreceiver.range",
"Communication",
"The range of the bt receiver");
72 oc.
addDescription(
"device.btreceiver.all-recognitions",
"Communication",
"Whether all recognition point shall be written");
81 into.push_back(device);
101 (*i).second->amOnNet =
false;
102 (*i).second->haveArrived =
true;
105 (*i).second->amOnNet =
false;
106 (*i).second->haveArrived =
true;
122 rt.
Insert(cmin, cmax, vi);
127 bool allRecognitions = oc.
getBool(
"device.btreceiver.all-recognitions");
128 bool haveOutput = oc.
isSet(
"bt-output");
137 Position egoP1(egoP2.
x() - sin(angle)*dist, egoP2.
y() + cos(angle)*dist);
146 std::set<std::string> surroundingVehicles;
148 rt.
Search(cmin, cmax, sv);
151 for (std::set<std::string>::const_iterator j = surroundingVehicles.begin(); j != surroundingVehicles.end(); ++j) {
152 if ((*i).first == *j) {
162 writeOutput((*i).first, vi->
seen, allRecognitions);
169 (*i).second->updates.clear();
170 (*i).second->updates.push_back(last);
177 if ((*i).second->haveArrived) {
182 (*i).second->updates.clear();
183 (*i).second->updates.push_back(last);
195 std::vector<SUMOReal> intersections;
212 Position otherP1(otherPosition.
x() - sin(angle)*dist, otherPosition.
y() + cos(angle)*dist);
213 Position otherD = otherP2 - otherP1;
214 otherP2 = otherP1 - receiverD + otherD;
217 int count = (
int) intersections.size();
224 enterRange(atOffset, receiverPos, receiver.
updates.back().speed, receiver.
updates.back().laneID, receiver.
updates.back().lanePos,
239 Position intersection1Other = otherP1 + otherD * intersections.front();
240 Position intersection1Ego = receiverStartPos + receiverD * intersections.front();
243 sender.
getID(), intersection1Other, sender.
updates.back().speed, sender.
updates.back().laneID, sender.
updates.back().lanePos, -1. + intersections.front());
245 enterRange(-1. + intersections.front(), intersection1Ego, receiver.
updates.back().speed, receiver.
updates.back().laneID, receiver.
updates.back().lanePos,
253 Position intersection1Other = otherP1 + otherD * intersections.front();
254 Position intersection1Ego = receiverStartPos + receiverD * intersections.front();
255 enterRange(-1. + intersections.front(), intersection1Ego, receiver.
updates.back().speed, receiver.
updates.back().laneID, receiver.
updates.back().lanePos,
257 Position intersection2Other = otherP1 + otherD * intersections[1];
258 Position intersection2Ego = receiverStartPos + receiverD * intersections[1];
260 sender.
getID(), intersection2Other, sender.
updates.back().speed, sender.
updates.back().laneID, sender.
updates.back().lanePos, -1. + intersections.front());
262 WRITE_WARNING(
"Nope, a vehicle cannot be in the range, leave, and enter it in one step.");
266 WRITE_WARNING(
"Nope, a circle cannot be crossed more often than twice by a line.");
275 const std::string& otherID,
const Position& otherPos,
SUMOReal otherSpeed,
const std::string& otherLaneID,
SUMOReal otherLanePos,
276 std::map<std::string, SeenDevice*>& currentlySeen) {
279 currentlySeen[otherID] = sd;
281 otherID, otherPos, otherSpeed, otherLaneID, otherLanePos, currentlySeen);
288 const std::string& otherID,
const Position& otherPos,
SUMOReal otherSpeed,
const std::string& otherLaneID,
SUMOReal otherLanePos,
292 otherID, otherPos, otherSpeed, otherLaneID, otherLanePos, currentlySeen);
295 std::map<std::string, SeenDevice*>::iterator i = currentlySeen.find(otherID);
296 (*i).second->meetingEnd = mp;
297 if (seen.find(otherID) == seen.end()) {
298 seen[otherID] = std::vector<SeenDevice*>();
300 seen[otherID].push_back((*i).second);
301 currentlySeen.erase(i);
307 const std::string& otherID,
const Position& otherPos,
SUMOReal otherSpeed,
const std::string& otherLaneID,
SUMOReal otherLanePos,
308 std::map<std::string, SeenDevice*>& currentlySeen) {
309 SUMOReal t = tEnd - currentlySeen.find(otherID)->second->lastView;
311 currentlySeen.find(otherID)->second->lastView = tEnd;
312 MeetingPoint* mp =
new MeetingPoint(tEnd, thisPos, thisSpeed, thisLaneID, thisLanePos, otherPos, otherSpeed, otherLaneID, otherLanePos);
313 std::map<std::string, SeenDevice*>::iterator i = currentlySeen.find(otherID);
314 if (i != currentlySeen.end()) {
315 (*i).second->recognitionPoints.push_back(mp);
317 WRITE_WARNING(
"Could not add a recognition point as the sender '" + otherID +
"' is not currently seen.");
327 for (std::map<std::string, std::vector<SeenDevice*> >::const_iterator j = seen.begin(); j != seen.end(); ++j) {
328 const std::vector<SeenDevice*>& sts = (*j).second;
329 for (std::vector<SeenDevice*>::const_iterator k = sts.begin(); k != sts.end(); ++k) {
331 os.
writeAttr(
"tBeg", (*k)->meetingBegin.t)
332 .
writeAttr(
"observerPosBeg", (*k)->meetingBegin.observerPos).
writeAttr(
"observerSpeedBeg", (*k)->meetingBegin.observerSpeed)
333 .
writeAttr(
"observerLaneIDBeg", (*k)->meetingBegin.observerLaneID).
writeAttr(
"observerLanePosBeg", (*k)->meetingBegin.observerLanePos)
334 .
writeAttr(
"seenPosBeg", (*k)->meetingBegin.seenPos).
writeAttr(
"seenSpeedBeg", (*k)->meetingBegin.seenSpeed)
335 .
writeAttr(
"seenLaneIDBeg", (*k)->meetingBegin.seenLaneID).
writeAttr(
"seenLanePosBeg", (*k)->meetingBegin.seenLanePos);
337 .
writeAttr(
"observerPosEnd", (*k)->meetingEnd.observerPos).
writeAttr(
"observerSpeedEnd", (*k)->meetingEnd.observerSpeed)
338 .
writeAttr(
"observerLaneIDEnd", (*k)->meetingEnd.observerLaneID).
writeAttr(
"observerLanePosEnd", (*k)->meetingEnd.observerLanePos)
339 .
writeAttr(
"seenPosEnd", (*k)->meetingEnd.seenPos).
writeAttr(
"seenSpeedEnd", (*k)->meetingEnd.seenSpeed)
340 .
writeAttr(
"seenLaneIDEnd", (*k)->meetingEnd.seenLaneID).
writeAttr(
"seenLanePosEnd", (*k)->meetingEnd.seenLanePos);
341 for (std::vector<MeetingPoint*>::iterator l = (*k)->recognitionPoints.begin(); l != (*k)->recognitionPoints.end(); ++l) {
343 .
writeAttr(
"observerPos", (*l)->observerPos).
writeAttr(
"observerSpeed", (*l)->observerSpeed)
344 .
writeAttr(
"observerLaneID", (*l)->observerLaneID).
writeAttr(
"observerLanePos", (*l)->observerLanePos)
346 .
writeAttr(
"seenLaneID", (*l)->seenLaneID).
writeAttr(
"seenLanePos", (*l)->seenLanePos)
348 if (!allRecognitions) {
388 WRITE_WARNING(
"btreceiver: Can not update position of a vehicle that is not within the road network (" + veh.
getID() +
").");
392 MSNet::getInstance()->getCurrentTimeStep(), newSpeed, static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).
getLane()->
getID(), newPos
404 WRITE_WARNING(
"btreceiver: Can not update position of a vehicle that is not within the road network (" + veh.
getID() +
").");
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
Representation of a vehicle in the micro simulation.
A global update performer.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender, const Position &receiverPos, const Position &receiverD)
Rechecks the visibility for a given receiver/sender pair.
void Insert(const float a_min[2], const float a_max[2], Named *a_data)
Insert entry.
MSEventControl & getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
SUMOReal ymin() const
Returns minimum y-coordinate.
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.
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.
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 x() const
Returns the x-position.
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)
static OptionsCont & getOptions()
Retrieves the options.
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.
Position position
The position of the vehicle.
The vehicle arrived at its destination (is deleted)
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.
Abstract in-vehicle device.
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 * > ¤tlySeen)
Determines whether the other vehicle got visible until the given time.
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 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)
SUMOReal y() const
Returns the y-position.
A storage for options typed value containers)
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id, SUMOReal range)
Constructor.
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 speed
The speed of the vehicle.
SUMOReal ymax() const
Returns maximum y-coordinate.
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.
SUMOReal angle
The angle of the vehicle.
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.