2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
|
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
#include "trilaterationalgorithm.hh"
|
2010-03-22 13:47:19 +01:00
|
|
|
#include "minmax.hh"
|
2010-06-09 12:11:26 +02:00
|
|
|
#include "mobile.hh"
|
2011-04-27 18:57:00 +02:00
|
|
|
#include "configuration.hh"
|
|
|
|
#include "posexcept.hh"
|
2010-03-22 13:47:19 +01:00
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
TrilaterationAlgorithm::TrilaterationAlgorithm():
|
2014-05-13 23:50:53 +02:00
|
|
|
request(nullptr)
|
2010-03-22 13:47:19 +01:00
|
|
|
{
|
2012-04-11 16:31:48 +02:00
|
|
|
// Will be changed when other trilateration methods will be
|
2011-04-27 18:57:00 +02:00
|
|
|
// implemented.
|
|
|
|
|
2011-07-30 14:21:37 +02:00
|
|
|
if (! Configuration::is_configured("positioning.area-start") ||
|
|
|
|
! Configuration::is_configured("positioning.area-stop"))
|
2011-04-27 18:57:00 +02:00
|
|
|
throw missing_configuration(
|
2011-07-30 14:21:37 +02:00
|
|
|
"You want to use MinMax, but either positioning.area-start or"
|
|
|
|
" positioning.area-stop is not defined!") ;
|
2011-04-27 18:57:00 +02:00
|
|
|
|
|
|
|
Point3D minmax_start(
|
2011-07-30 14:21:37 +02:00
|
|
|
Configuration::string_value("positioning.area-start")) ;
|
2011-04-27 18:57:00 +02:00
|
|
|
Point3D minmax_stop(
|
2011-07-30 14:21:37 +02:00
|
|
|
Configuration::string_value("positioning.area-stop")) ;
|
2011-04-27 18:57:00 +02:00
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
trilateration_method = new MinMax(minmax_start, minmax_stop) ;
|
2010-03-22 13:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
TrilaterationAlgorithm::~TrilaterationAlgorithm()
|
2010-03-22 13:47:19 +01:00
|
|
|
{
|
2012-04-11 16:31:48 +02:00
|
|
|
delete trilateration_method ;
|
2010-03-22 13:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
double TrilaterationAlgorithm::
|
2010-06-09 12:11:26 +02:00
|
|
|
make_constant_term(const Measurement &measurement)
|
|
|
|
{
|
|
|
|
assert(request) ;
|
2011-08-01 18:22:53 +02:00
|
|
|
const Mobile *mobile = request->get_mobile() ;
|
|
|
|
assert(mobile) ;
|
2013-06-14 21:54:26 +02:00
|
|
|
const CapturePoint *cp = measurement.get_cp() ;
|
|
|
|
assert(cp) ;
|
2010-06-09 12:11:26 +02:00
|
|
|
|
|
|
|
return
|
2013-06-14 21:54:26 +02:00
|
|
|
cp->friis_constant_term() +
|
2011-08-01 18:22:53 +02:00
|
|
|
mobile->get_antenna_gain() +
|
|
|
|
mobile->get_trx_power() ;
|
2010-06-09 12:11:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-11 16:31:48 +02:00
|
|
|
Result TrilaterationAlgorithm::compute(const Request &_request)
|
2010-03-22 13:47:19 +01:00
|
|
|
{
|
|
|
|
request = &_request ;
|
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
compute_cp_distance_circles() ;
|
2012-04-11 16:31:48 +02:00
|
|
|
Point3D position(trilaterate()) ;
|
2010-03-22 13:47:19 +01:00
|
|
|
|
2011-07-24 12:32:07 +02:00
|
|
|
return Result(request, name, position) ;
|
2010-03-22 13:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
void TrilaterationAlgorithm::compute_cp_distance_circles()
|
2010-03-22 13:47:19 +01:00
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
cp_distances.clear() ;
|
2010-03-22 13:47:19 +01:00
|
|
|
|
|
|
|
const unordered_map<string, Measurement> &measurements =
|
|
|
|
request->get_measurements() ;
|
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = measurements.begin() ; i != measurements.end() ; ++i)
|
2013-06-14 21:54:26 +02:00
|
|
|
cp_distances[i->second.get_cp()] = estimate_distance(i->second) ;
|
2010-03-22 13:47:19 +01:00
|
|
|
}
|