mrcl_tworayground.cc

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 /* tworayground.cc
00035    $Id: tworayground.cc,v 1.7 2005/02/03 20:15:00 haldar Exp $
00036  */
00037 
00038 #include <math.h>
00039 
00040 #include <delay.h>
00041 #include <packet.h>
00042 #include <node-core.h>
00043 
00044 #include <packet-stamp.h>
00045 #include <antenna.h>
00046 #include <mobilenode.h>
00047 #include <mrcl_propagation.h>
00048 #include <mrcl_wireless-phy.h>
00049 #include <mrcl_tworayground.h>
00050 #include "wirelessphy-module.h"
00051 
00052 
00053 static class MrclTwoRayGroundClass: public TclClass {
00054 public:
00055         MrclTwoRayGroundClass() : TclClass("Propagation/MrclTwoRayGround") {}
00056         TclObject* create(int, const char*const*) {
00057                 return (new MrclTwoRayGround);
00058         }
00059 } class_tworayground;
00060 
00061 MrclTwoRayGround::MrclTwoRayGround()
00062 {
00063   last_hr = last_ht = 0.0;
00064   crossover_dist = 0.0;
00065 }
00066 
00067 // use Friis at less than crossover distance
00068 // use two-ray at more than crossover distance
00069 //static double
00070 double MrclTwoRayGround::TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L, double d)
00071 {
00072         /*
00073          *  Two-ray ground reflection model.
00074          *
00075          *           Pt * Gt * Gr * (ht^2 * hr^2)
00076          *  Pr = ----------------------------
00077          *           d^4 * L
00078          *
00079          * The original equation in Rappaport's book assumes L = 1.
00080          * To be consistant with the free space equation, L is added here.
00081          */
00082   return Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L);
00083 }
00084 
00085 double
00086 MrclTwoRayGround::Pr(Packet *p, PacketStamp *t, PacketStamp *r, double L, double lambda)
00087 {
00088   Position *sourcePos;
00089   Position *destPos;
00090   double rX, rY, rZ;            // location of receiver
00091   double tX, tY, tZ;            // location of transmitter
00092   double d;                             // distance
00093   double hr, ht;                // height of recv and xmit antennas
00094   double Pr;                    // received signal power
00095 
00096 
00097   // old position parameters obtained from MobileNode
00098   //r->getNode()->getLoc(&rX, &rY, &rZ);
00099   //t->getNode()->getLoc(&tX, &tY, &tZ);
00100   
00101   // new position Parameters
00102   hdr_MrclWrlPhy *wph = HDR_MRCLWRLPHY(p);
00103   sourcePos = wph->sourcePos_;
00104   destPos = wph->destPos_;
00105   
00106   rX = destPos->getX();
00107   rY = destPos->getY();
00108   rZ = 0.;
00109   tX = sourcePos->getX();
00110   tY = sourcePos->getY();
00111   tZ = 0.;
00112 
00113   rX += r->getAntenna()->getX();
00114   rY += r->getAntenna()->getY();
00115   tX += t->getAntenna()->getX();
00116   tY += t->getAntenna()->getY();
00117 
00118   d = sqrt((rX - tX) * (rX - tX) 
00119            + (rY - tY) * (rY - tY) 
00120            + (rZ - tZ) * (rZ - tZ));
00121 
00122   //fprintf(stderr,"MrclTwoRayGround::Pr source(%f,%f,%f) dest(%f,%f,%f) dx: %f\n",tX,tY,tZ,rX,rY,rZ,d);
00123     
00124   /* We're going to assume the ground is essentially flat.
00125      This empirical two ground ray reflection model doesn't make 
00126      any sense if the ground is not a plane. */
00127 
00128   if (rZ != tZ) {
00129     printf("%s: MrclTwoRayGround propagation model assume flat ground\n",
00130            __FILE__);
00131   }
00132 
00133   hr = rZ + r->getAntenna()->getZ();
00134   ht = tZ + t->getAntenna()->getZ();
00135 
00136   if (hr != last_hr || ht != last_ht)
00137     { // recalc the cross-over distance
00138       /* 
00139                  4 * PI * hr * ht
00140          d = ----------------------------
00141                      lambda
00142            * At the crossover distance, the received power predicted by the two-ray
00143            * ground model equals to that predicted by the Friis equation.
00144        */
00145 
00146       crossover_dist = (4 * PI * ht * hr) / lambda;
00147       last_hr = hr; last_ht = ht;
00148 #if DEBUG > 3
00149       printf("TRG: xover %e.10 hr %f ht %f\n",
00150               crossover_dist, hr, ht);
00151 #endif
00152     }
00153 
00154   /*
00155    *  If the transmitter is within the cross-over range , use the
00156    *  Friis equation.  Otherwise, use the two-ray
00157    *  ground reflection model.
00158    */
00159 
00160   double Gt = t->getAntenna()->getTxGain(rX - tX, rY - tY, rZ - tZ, 
00161                                          t->getLambda());
00162   double Gr = r->getAntenna()->getRxGain(tX - rX, tY - rY, tZ - rZ,
00163                                          r->getLambda());
00164 
00165 #if DEBUG > 5
00166   printf("TRG %.9f %d(%d,%d)@%d(%d,%d) d=%f xo=%f :",
00167          Scheduler::instance().clock(), 
00168          t->getNode()->index(), (int)tX, (int)tY,
00169          r->getNode()->index(), (int)rX, (int)rY,
00170          d, crossover_dist);
00171   //  printf("\n\t Pt %e Gt %e Gr %e lambda %e L %e :",
00172   //         t->getTxPr(), Gt, Gr, lambda, L);
00173 #endif
00174 
00175   if(d <= crossover_dist) {
00176     Pr = Friis(t->getTxPr(), Gt, Gr, lambda, L, d);
00177 #if DEBUG > 3
00178     printf("Friis %e\n",Pr);
00179 #endif
00180     return Pr;
00181   }
00182   else {
00183     Pr = TwoRay(t->getTxPr(), Gt, Gr, ht, hr, L, d);
00184 #if DEBUG > 3
00185     printf("TwoRay %e\n",Pr);
00186 #endif    
00187     return Pr;
00188   }
00189 }
00190 
00191 double MrclTwoRayGround::getDist(double Pr, double Pt, double Gt, double Gr, double hr, double ht, double L, double lambda)
00192 {
00193        /* Get quartic root */
00194        return sqrt(sqrt(Pt * Gt * Gr * (hr * hr * ht * ht) / Pr));
00195 }

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2