|
INET Framework for OMNeT++/OMNEST
|
LOGO-style movement model, with the script coming from XML.
More...
#include <TurtleMobility.h>
|
| virtual int | numInitStages () const override |
| | Returns the required number of initialize stages. More...
|
| |
| virtual void | initialize (int stage) override |
| | Initializes mobility model parameters. More...
|
| |
| virtual void | setInitialPosition () override |
| | Initializes the position according to the mobility model. More...
|
| |
| virtual void | setTargetPosition () override |
| | Overridden from LineSegmentsMobilityBase. More...
|
| |
| virtual void | move () override |
| | Overridden from LineSegmentsMobilityBase. More...
|
| |
| virtual void | resumeScript () |
| | Process next statements from script. More...
|
| |
| virtual void | executeStatement (cXMLElement *nextStatement) |
| | Execute the given statement. More...
|
| |
| virtual double | getValue (const char *s) |
| | Parse attrs in the script – accepts things like "uniform(10,50) as well. More...
|
| |
| virtual void | gotoNextStatement () |
| | Advance nextStatement pointer. More...
|
| |
| virtual void | computeMaxSpeed (cXMLElement *nodes) |
| |
| virtual void | initializePosition () override |
| | Initializes mobility position. More...
|
| |
| | MovingMobilityBase () |
| |
| virtual | ~MovingMobilityBase () |
| |
| virtual void | handleSelfMessage (cMessage *message) override |
| | Called upon arrival of a self messages, subclasses must override. More...
|
| |
| void | scheduleUpdate () |
| | Schedules the move timer that will update the mobility state. More...
|
| |
| void | moveAndUpdate () |
| | Moves and notifies listeners. More...
|
| |
| virtual void | orient () |
| |
| | MobilityBase () |
| |
| virtual int | getId () const override |
| |
| virtual void | checkPosition () |
| | Checks whether the position is valid or not. More...
|
| |
| virtual void | initializeOrientation () |
| | Initializes the orientation from module parameters. More...
|
| |
| virtual void | refreshDisplay () const override |
| | Moves the visual representation module's icon to the new position on the screen. More...
|
| |
| virtual void | updateDisplayStringFromMobilityState () const |
| |
| virtual void | handleParameterChange (const char *name) override |
| | Allows changing parameters from the GUI. More...
|
| |
| virtual void | handleMessage (cMessage *msg) override |
| | This modules should only receive self-messages. More...
|
| |
| virtual void | emitMobilityStateChangedSignal () |
| | Emits a signal with the updated mobility state. More...
|
| |
| virtual Coord | getRandomPosition () |
| | Returns a new random position satisfying the constraint area. More...
|
| |
| virtual cModule * | findSubjectModule () |
| | Returns the module that represents the object moved by this mobility module. More...
|
| |
| virtual bool | isOutside () |
| | Returns true if the mobility is outside of the constraint area. More...
|
| |
| virtual void | reflectIfOutside (Coord &targetPosition, Coord &velocity, rad &angle, rad &elevation, Quaternion &quaternion) |
| | Utility function to reflect the node if it goes outside the constraint area. More...
|
| |
| virtual void | wrapIfOutside (Coord &targetPosition) |
| | Utility function to wrap the node to the opposite edge (torus) if it goes outside the constraint area. More...
|
| |
| virtual void | placeRandomlyIfOutside (Coord &targetPosition) |
| | Utility function to place the node randomly if it goes outside the constraint area. More...
|
| |
| virtual void | raiseErrorIfOutside () |
| | Utility function to raise an error if the node gets outside the constraint area. More...
|
| |
| virtual void | handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity) |
| | Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy. More...
|
| |
| virtual void | handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading) |
| |
| virtual void | handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading, rad &elevation) |
| |
| virtual void | handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading, rad &elevation, Quaternion &quaternion) |
| |
LOGO-style movement model, with the script coming from XML.
See NED file for more info.
◆ TurtleMobility()
| inet::TurtleMobility::TurtleMobility |
( |
| ) |
|
◆ computeMaxSpeed()
| void inet::TurtleMobility::computeMaxSpeed |
( |
cXMLElement * |
nodes | ) |
|
|
protectedvirtual |
368 cXMLElementList childs = nodes->getChildren();
369 for (
auto& child : childs) {
370 const char *speedAttr = child->getAttribute(
"speed");
372 double speed = atof(speedAttr);
Referenced by initialize().
◆ executeStatement()
| void inet::TurtleMobility::executeStatement |
( |
cXMLElement * |
nextStatement | ) |
|
|
protectedvirtual |
Execute the given statement.
100 const char *tag = stmt->getTagName();
102 EV_DEBUG <<
"doing <" << tag <<
">\n";
104 if (!strcmp(tag,
"repeat")) {
105 const char *nAttr = stmt->getAttribute(
"n");
112 throw cRuntimeError(
"<repeat>: negative repeat count at %s", stmt->getSourceLocation());
117 else if (!strcmp(tag,
"set")) {
118 const char *speedAttr = stmt->getAttribute(
"speed");
119 const char *headingAttr = stmt->getAttribute(
"heading");
120 if (headingAttr ==
nullptr)
121 headingAttr = stmt->getAttribute(
"angle");
122 const char *elevationAttr = stmt->getAttribute(
"elevation");
123 const char *xAttr = stmt->getAttribute(
"x");
124 const char *yAttr = stmt->getAttribute(
"y");
125 const char *zAttr = stmt->getAttribute(
"z");
126 const char *bpAttr = stmt->getAttribute(
"borderPolicy");
147 throw cRuntimeError(
"<set>: speed is negative or zero at %s", stmt->getSourceLocation());
150 if (!strcmp(bpAttr,
"reflect"))
152 else if (!strcmp(bpAttr,
"wrap"))
154 else if (!strcmp(bpAttr,
"placerandomly"))
156 else if (!strcmp(bpAttr,
"error"))
159 throw cRuntimeError(
"<set>: value for attribute borderPolicy is invalid, should be "
160 "'reflect', 'wrap', 'placerandomly' or 'error' at %s",
161 stmt->getSourceLocation());
164 else if (!strcmp(tag,
"forward")) {
165 const char *dAttr = stmt->getAttribute(
"d");
166 const char *tAttr = stmt->getAttribute(
"t");
168 if (!dAttr && !tAttr)
169 throw cRuntimeError(
"<forward>: must have at least attribute 't' or 'd' (or both) at %s", stmt->getSourceLocation());
173 if (tAttr && dAttr) {
190 throw cRuntimeError(
"<forward>: time (attribute t) is negative at %s", stmt->getSourceLocation());
193 throw cRuntimeError(
"<forward>: distance (attribute d) is negative at %s", stmt->getSourceLocation());
200 else if (!strcmp(tag,
"turn")) {
201 const char *headingAttr = stmt->getAttribute(
"heading");
202 if (headingAttr ==
nullptr)
203 headingAttr = stmt->getAttribute(
"angle");
204 const char *elevationAttr = stmt->getAttribute(
"elevation");
212 else if (!strcmp(tag,
"wait")) {
213 const char *tAttr = stmt->getAttribute(
"t");
216 throw cRuntimeError(
"<wait>: required attribute 't' missing at %s", stmt->getSourceLocation());
221 throw cRuntimeError(
"<wait>: time (attribute t) is negative (%g) at %s", t, stmt->getSourceLocation());
225 else if (!strcmp(tag,
"moveto")) {
226 const char *xAttr = stmt->getAttribute(
"x");
227 const char *yAttr = stmt->getAttribute(
"y");
228 const char *zAttr = stmt->getAttribute(
"z");
229 const char *tAttr = stmt->getAttribute(
"t");
244 throw cRuntimeError(
"<wait>: time (attribute t) is negative at %s", stmt->getSourceLocation());
248 else if (!strcmp(tag,
"moveby")) {
249 const char *xAttr = stmt->getAttribute(
"x");
250 const char *yAttr = stmt->getAttribute(
"y");
251 const char *zAttr = stmt->getAttribute(
"z");
252 const char *tAttr = stmt->getAttribute(
"t");
267 throw cRuntimeError(
"<wait>: time (attribute t) is negative at %s", stmt->getSourceLocation());
Referenced by resumeScript().
◆ getMaxSpeed()
| virtual double inet::TurtleMobility::getMaxSpeed |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the maximum possible speed at any future time.
Reimplemented from inet::MobilityBase.
◆ getValue()
| double inet::TurtleMobility::getValue |
( |
const char * |
s | ) |
|
|
protectedvirtual |
Parse attrs in the script – accepts things like "uniform(10,50) as well.
277 if (strchr(
s,
'$')) {
278 char strMinX[32], strMinY[32], strMinZ[32];
279 char strMaxX[32], strMaxY[32], strMaxZ[32];
288 std::string::size_type pos;
290 while ((pos = str.find(
"$MINX")) != std::string::npos)
291 str.replace(pos,
sizeof(
"$MINX") - 1, strMinX);
293 while ((pos = str.find(
"$MINY")) != std::string::npos)
294 str.replace(pos,
sizeof(
"$MINY") - 1, strMinY);
296 while ((pos = str.find(
"$MINZ")) != std::string::npos)
297 str.replace(pos,
sizeof(
"$MINZ") - 1, strMinZ);
299 while ((pos = str.find(
"$MAXX")) != std::string::npos)
300 str.replace(pos,
sizeof(
"$MAXX") - 1, strMaxX);
302 while ((pos = str.find(
"$MAXY")) != std::string::npos)
303 str.replace(pos,
sizeof(
"$MAXY") - 1, strMaxY);
305 while ((pos = str.find(
"$MAXZ")) != std::string::npos)
306 str.replace(pos,
sizeof(
"$MAXZ") - 1, strMaxZ);
313 cDynamicExpression expr;
315 return expr.doubleValue(
this);
317 catch (std::exception&
e) {
318 throw cRuntimeError(
"Wrong value '%s' around %s: %s",
s,
Referenced by executeStatement().
◆ gotoNextStatement()
| void inet::TurtleMobility::gotoNextStatement |
( |
| ) |
|
|
protectedvirtual |
◆ initialize()
| void inet::TurtleMobility::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
Initializes mobility model parameters.
Reimplemented from inet::MovingMobilityBase.
31 EV_TRACE <<
"initializing TurtleMobility stage " << stage << endl;
◆ move()
| void inet::TurtleMobility::move |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ numInitStages()
| virtual int inet::TurtleMobility::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ resumeScript()
| void inet::TurtleMobility::resumeScript |
( |
| ) |
|
|
protectedvirtual |
◆ setInitialPosition()
| void inet::TurtleMobility::setInitialPosition |
( |
| ) |
|
|
overrideprotectedvirtual |
Initializes the position according to the mobility model.
Reimplemented from inet::MobilityBase.
◆ setTargetPosition()
| void inet::TurtleMobility::setTargetPosition |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ borderPolicy
◆ elevation
| rad inet::TurtleMobility::elevation |
|
protected |
◆ heading
| rad inet::TurtleMobility::heading |
|
protected |
◆ loopVars
| std::stack<long> inet::TurtleMobility::loopVars |
|
protected |
◆ maxSpeed
| double inet::TurtleMobility::maxSpeed |
|
protected |
◆ nextStatement
| cXMLElement* inet::TurtleMobility::nextStatement |
|
protected |
◆ speed
| double inet::TurtleMobility::speed |
|
protected |
◆ turtleScript
| cXMLElement* inet::TurtleMobility::turtleScript |
|
protected |
The documentation for this class was generated from the following files:
@ REFLECT
reflect off the wall
Definition: MobilityBase.h:56
@ WRAP
reappear at the opposite edge (torus)
Definition: MobilityBase.h:57
cXMLElement * turtleScript
Definition: TurtleMobility.h:27
Coord lastPosition
The last position that was reported.
Definition: MobilityBase.h:73
fscale< rad, rad2degScale > deg
Definition: Units.h:1158
@ PLACERANDOMLY
placed at a randomly chosen position within the constraint area
Definition: MobilityBase.h:58
rad heading
Definition: TurtleMobility.h:32
Coord targetPosition
End position of current linear movement.
Definition: LineSegmentsMobilityBase.h:28
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:32
const value< double, units::C > e(1.602176487e-19)
double x
Definition: Coord.h:36
virtual void computeMaxSpeed(cXMLElement *nodes)
Definition: TurtleMobility.cc:364
std::stack< long > loopVars
Definition: TurtleMobility.h:35
virtual double getValue(const char *s)
Parse attrs in the script – accepts things like "uniform(10,50) as well.
Definition: TurtleMobility.cc:273
double speed
Definition: TurtleMobility.h:31
virtual void move() override
Moves according to the mobility model to the current simulation time.
Definition: LineSegmentsMobilityBase.cc:31
value< double, units::s > s
Definition: Units.h:1235
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MovingMobilityBase.cc:26
virtual void handleIfOutside(BorderPolicy policy, Coord &targetPosition, Coord &velocity)
Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the giv...
Definition: MobilityBase.cc:353
double maxSpeed
Definition: TurtleMobility.h:36
Coord constraintAreaMax
Definition: MobilityBase.h:70
simtime_t nextChange
The next simulation time when the mobility module needs to update its internal state.
Definition: MovingMobilityBase.h:46
virtual void executeStatement(cXMLElement *nextStatement)
Execute the given statement.
Definition: TurtleMobility.cc:97
cXMLElement * nextStatement
Definition: TurtleMobility.h:30
double z
Definition: Coord.h:38
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
static const Coord X_AXIS
Definition: Coord.h:29
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
virtual void resumeScript()
Process next statements from script.
Definition: TurtleMobility.cc:80
virtual void setInitialPosition()
Initializes the position from the display string or from module parameters.
Definition: MobilityBase.cc:122
Coord constraintAreaMin
3 dimensional position and size of the constraint area (in meters).
Definition: MobilityBase.h:70
rad elevation
Definition: TurtleMobility.h:33
value< double, units::rad > rad
Definition: Units.h:1245
double y
Definition: Coord.h:37
virtual void gotoNextStatement()
Advance nextStatement pointer.
Definition: TurtleMobility.cc:323
@ RAISEERROR
stop the simulation with error
Definition: MobilityBase.h:59
BorderPolicy borderPolicy
Definition: TurtleMobility.h:34