65 oc.
addDescription(
"device.btreceiver.range",
"Communication",
TL(
"The range of the bt receiver"));
68 oc.
addDescription(
"device.btreceiver.all-recognitions",
"Communication",
TL(
"Whether all recognition point shall be written"));
71 oc.
addDescription(
"device.btreceiver.offtime",
"Communication",
TL(
"The offtime used for calculating detection probability (in seconds)"));
83 into.push_back(device);
105 into.push_back(device);
128 vehicleInfo.second->amOnNet =
false;
129 vehicleInfo.second->haveArrived =
true;
132 vehicleInfo.second->amOnNet =
false;
133 vehicleInfo.second->haveArrived =
true;
170 b.
grow(POSITION_EPS);
171 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
172 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
173 rt.
Insert(cmin, cmax, vi);
178 bool allRecognitions = oc.
getBool(
"device.btreceiver.all-recognitions");
179 bool haveOutput = oc.
isSet(
"bt-output");
185 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
186 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
187 std::set<const Named*> surroundingVehicles;
189 rt.
Search(cmin, cmax, sv);
192 for (
const Named* vehicle : surroundingVehicles) {
193 if ((*i).first == vehicle->getID()) {
203 writeOutput((*i).first, vi->
seen, allRecognitions);
237 leaveRange(receiver, receiverData, sender, senderData, 0);
241 const Position& oldReceiverPosition = receiver.
updates.front().position;
249 std::vector<double> intersections;
251 switch (intersections.size()) {
262 leaveRange(receiver, receiverData, sender, senderData, 0.);
269 intersection1ReceiverData.
position = oldReceiverPosition + receiverDelta * intersections.front();
271 intersection1SenderData.
position = oldSenderPosition + senderDelta * intersections.front();
273 leaveRange(receiver, intersection1ReceiverData,
274 sender, intersection1SenderData, (intersections.front() - 1.) *
TS);
276 enterRange((intersections.front() - 1.) *
TS, intersection1ReceiverData,
285 intersectionReceiverData.
position = oldReceiverPosition + receiverDelta * intersections.front();
287 intersectionSenderData.
position = oldSenderPosition + senderDelta * intersections.front();
288 enterRange((intersections.front() - 1.) *
TS, intersectionReceiverData,
290 intersectionReceiverData.
position = oldReceiverPosition + receiverDelta * intersections.back();
291 intersectionSenderData.
position = oldSenderPosition + senderDelta * intersections.back();
292 leaveRange(receiver, intersectionReceiverData,
293 sender, intersectionSenderData, (intersections.back() - 1.) *
TS);
295 WRITE_WARNINGF(
TL(
"The vehicle '%' cannot be in the range of vehicle '%', leave, and enter it in one step."), sender.
getID(), receiver.
getID());
299 WRITE_WARNING(
"Nope, a circle cannot be crossed more often than twice by a line.");
308 std::map<std::string, SeenDevice*>& currentlySeen) {
311 currentlySeen[senderID] =
sd;
312 addRecognitionPoint(
SIMTIME, receiverState, senderState,
sd);
320 std::map<std::string, SeenDevice*>::iterator i = receiverInfo.
currentlySeen.find(senderInfo.
getID());
322 addRecognitionPoint(
SIMTIME + tOffset, receiverState, senderState, i->second);
325 ConstMSEdgeVector::const_iterator begin = receiverInfo.
route.begin() + i->second->meetingBegin.observerState.routePos;
326 ConstMSEdgeVector::const_iterator end = receiverInfo.
route.begin() + receiverState.
routePos + 1;
327 i->second->receiverRoute = toString<const MSEdge>(begin, end);
328 begin = senderInfo.
route.begin() + i->second->meetingBegin.seenState.routePos;
330 i->second->senderRoute = toString<const MSEdge>(begin, end);
331 receiverInfo.
seen[senderInfo.
getID()].push_back(i->second);
340 if (senderDevice->
nextView == -1.) {
343 if (tEnd > senderDevice->
nextView) {
356 for (std::map<std::string, std::vector<SeenDevice*> >::const_iterator j = seen.begin(); j != seen.end(); ++j) {
357 const std::vector<SeenDevice*>& sts = (*j).second;
358 for (std::vector<SeenDevice*>::const_iterator k = sts.begin(); k != sts.end(); ++k) {
362 os.
writeAttr(
"tBeg", (*k)->meetingBegin.t)
369 os.
writeAttr(
"tEnd", (*k)->meetingEnd->t)
374 .
writeAttr(
"observerRoute", (*k)->receiverRoute).
writeAttr(
"seenRoute", (*k)->senderRoute);
375 for (std::vector<MeetingPoint*>::iterator l = (*k)->recognitionPoints.begin(); l != (*k)->recognitionPoints.end(); ++l) {
377 .
writeAttr(
"observerPos", (*l)->observerState.position).
writeAttr(
"observerSpeed", (*l)->observerState.speed)
378 .
writeAttr(
"observerLaneID", (*l)->observerState.laneID).
writeAttr(
"observerLanePos", (*l)->observerState.lanePos)
379 .
writeAttr(
"seenPos", (*l)->seenState.position).
writeAttr(
"seenSpeed", (*l)->seenState.speed)
380 .
writeAttr(
"seenLaneID", (*l)->seenState.laneID).
writeAttr(
"seenLanePos", (*l)->seenState.lanePos)
382 if (!allRecognitions) {
421 WRITE_WARNINGF(
TL(
"btreceiver: Can not update position of vehicle '%' which is not on the road."), veh.
getID());
436 WRITE_WARNINGF(
TL(
"btreceiver: Can not update position of vehicle '%' which is not on the road."), veh.
getID());
463 return delaySlots + backoff;
467 return 2048 - phaseOffset + delaySlots + backoff;
471 if (2 * 2048 - phaseOffset + backoff < 4096) {
472 return 2 * 2048 - phaseOffset + delaySlots + backoff;
475 return 2 * 2048 - phaseOffset + delaySlots + backoff;
477 return 2 * 2048 + delaySlots + backoff;
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
A class that stores a 2D geometrical boundary.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
Boundary & grow(double by)
extends the boundary by the given amount
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
static void findLineCircleIntersections(const Position &c, double radius, const Position &p1, const Position &p2, std::vector< double > &into)
Returns the positions the given circle is crossed by the given line.
A global update performer.
~BTreceiverUpdate()
Destructor.
void leaveRange(VehicleInformation &receiverInfo, const MSDevice_BTsender::VehicleState &receiverState, MSDevice_BTsender::VehicleInformation &senderInfo, const MSDevice_BTsender::VehicleState &senderState, double tOffset)
Removes the sender from the currently seen devices to past episodes.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState &receiverState, const MSDevice_BTsender::VehicleState &senderState, SeenDevice *senderDevice) const
Adds a point of recognition.
void enterRange(double atOffset, const MSDevice_BTsender::VehicleState &receiverState, const std::string &senderID, const MSDevice_BTsender::VehicleState &senderState, std::map< std::string, SeenDevice * > ¤tlySeen)
Informs the receiver about a sender entering it's radius.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
BTreceiverUpdate()
Constructor.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
Class representing a single seen device.
double nextView
Next possible recognition point.
double lastView
Last recognition point.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
static bool myWasInitialised
Whether the bt-system was already initialised.
static double inquiryDelaySlots(const int backoffLimit)
static double myRange
The range of the device.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
~MSDevice_BTreceiver()
Destructor.
static SumoRNG sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
static bool myHasPersons
Whether the bt-system includes persons.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
static double myOffTime
The offtime of the device.
A single movement state of the vehicle.
int routePos
The position in the route of the vehicle.
double speed
The speed of the vehicle.
Position position
The position of the vehicle.
double lanePos
The position at the lane of the vehicle.
std::string laneID
The lane the vehicle was at.
static std::string getLocation(const SUMOTrafficObject &o)
return either lane or edge id (depending on availability)
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
virtual double getSpeed() const
the current speed of the transportable
double getPositionOnLane() const
Get the object's position along the lane.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or nullptr if not.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Allows to store the object; used as context while traveling the rtree in TraCI.
Base class for objects which have an id.
const std::string & getID() const
Returns the id.
A RT-tree for efficient storing of SUMO's Named objects.
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Representation of a vehicle, person, or container.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual int getRoutePosition() const =0
return index of edge within route
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.