|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2005 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include "CircleMobility.h" 00019 #include "FWMath.h" 00020 00021 00022 Define_Module(CircleMobility); 00023 00024 00025 void CircleMobility::initialize(int stage) 00026 { 00027 BasicMobility::initialize(stage); 00028 00029 EV << "initializing CircleMobility stage " << stage << endl; 00030 00031 if (stage == 1) 00032 { 00033 // read parameters 00034 cx = par("cx"); 00035 cy = par("cy"); 00036 r = par("r"); 00037 ASSERT(r>0); 00038 angle = par("startAngle").doubleValue()/180.0*PI; 00039 updateInterval = par("updateInterval"); 00040 double speed = par("speed"); 00041 omega = speed/r; 00042 00043 // calculate initial position 00044 pos.x = cx + r * cos(angle); 00045 pos.y = cy + r * sin(angle); 00046 updatePosition(); 00047 00048 // if the initial speed is lower than 0, the node is stationary 00049 stationary = (speed == 0); 00050 00051 // host moves the first time after some random delay to avoid synchronized movements 00052 if (!stationary) 00053 scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move")); 00054 } 00055 } 00056 00057 00058 void CircleMobility::handleSelfMsg(cMessage * msg) 00059 { 00060 move(); 00061 updatePosition(); 00062 scheduleAt(simTime() + updateInterval, msg); 00063 } 00064 00065 void CircleMobility::move() 00066 { 00067 angle += omega * updateInterval; 00068 pos.x = cx + r * cos(angle); 00069 pos.y = cy + r * sin(angle); 00070 00071 EV << " xpos= " << pos.x << " ypos=" << pos.y << endl; 00072 }