LinearMobility.cc

00001 //
00002 // Author: Emin Ilker Cetinbas (niw3_at_yahoo_d0t_com)
00003 // Copyright (C) 2005 Emin Ilker Cetinbas
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 
00020 #include "LinearMobility.h"
00021 
00022 #include <FWMath.h>
00023 
00024 
00025 Define_Module(LinearMobility);
00026 
00027 void LinearMobility::initialize(int stage)
00028 {
00029     BaseMobility::initialize(stage);
00030 
00031     debugEV << "initializing LinearMobility stage " << stage << endl;
00032 
00033     if (stage == 0){
00034 
00035         move.setSpeed(par("speed"));
00036         acceleration = par("acceleration");
00037         angle = par("angle");
00038         angle = fmod(angle,360);
00039     }
00040     else if(stage == 1){
00041       stepTarget = move.getStartPos();
00042 
00043     if(!world->use2D()) {
00044       opp_warning("This mobility module does not yet support 3 dimensional movement."\
00045             "Movements will probably be incorrect.");
00046     }
00047     if(!world->useTorus()) {
00048       opp_warning("You are not using a torus (parameter \"useTorus\" in"\
00049             "BaseWorldUtility module) playground but this mobility"\
00050             "module uses WRAP as border policy.");
00051     }
00052     }
00053 }
00054 
00055 
00056 void LinearMobility::fixIfHostGetsOutside()
00057 {
00058     Coord dummy(world->use2D());
00059     handleIfOutside(WRAP, stepTarget, dummy, dummy, angle);
00060 }
00061 
00062 
00067 void LinearMobility::makeMove()
00068 {
00069   debugEV << "start makeMove " << move.info() << endl;
00070 
00071     move.setStart(stepTarget, simTime());
00072 
00073     stepTarget.setX(move.getStartPos().getX() + move.getSpeed() * cos(PI * angle / 180) * updateInterval.dbl());
00074     stepTarget.setY(move.getStartPos().getY() + move.getSpeed() * sin(PI * angle / 180) * updateInterval.dbl());
00075 
00076     move.setDirectionByTarget(stepTarget);
00077 
00078     debugEV << "new stepTarget: " << stepTarget.info() << endl;
00079 
00080     // accelerate
00081     move.setSpeed(move.getSpeed() + acceleration * updateInterval.dbl());
00082 
00083     fixIfHostGetsOutside();
00084 }