[Positioning] Add PositioningAlgorithm & RealPosition
PositioningAlgorithm is the super-class of all positioning algorithms. RealPosition is the first "positioning algorithm" (it actually computes nothing, but returns the position declared in a CalibrationRequest).
This commit is contained in:
parent
96808115bd
commit
9a334ad028
|
@ -52,6 +52,7 @@ OBJ_LIST = \
|
|||
request.o \
|
||||
calibrationrequest.o \
|
||||
result.o \
|
||||
realposition.o \
|
||||
configuration.o \
|
||||
userinterface.o \
|
||||
input.o \
|
||||
|
@ -60,7 +61,7 @@ OBJ_LIST = \
|
|||
OBJ_NOTEST_LIST = \
|
||||
posexcept.o \
|
||||
inputmedium.o
|
||||
INTERFACES_LIST = inputlogmedium.hh
|
||||
INTERFACES_LIST = inputlogmedium.hh positioningalgorithm.hh
|
||||
|
||||
OBJ = $(OBJ_LIST:%=$(OBJ_DIR)/%)
|
||||
OBJ_NOTEST = $(OBJ_NOTEST_LIST:%=$(OBJ_DIR)/%)
|
||||
|
@ -130,6 +131,11 @@ inputlogcsv.o: \
|
|||
$(OBJ_DIR)/request.o
|
||||
input.o: \
|
||||
$(OBJ_DIR)/posexcept.o
|
||||
realposition.o: \
|
||||
$(SRC_DIR)/positioningalgorithm.hh \
|
||||
$(OBJ_DIR)/result.o \
|
||||
$(OBJ_DIR)/calibrationrequest.o \
|
||||
$(OBJ_DIR)/referencepoint.o
|
||||
|
||||
# Specific targets
|
||||
$(TARGET): $(OBJ) $(OBJ_NOTEST) $(OBJ_TARGET)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef _OWLPS_POSITIONING_POSITIONINGALGORITHM_HH_
|
||||
#define _OWLPS_POSITIONING_POSITIONINGALGORITHM_HH_
|
||||
|
||||
#include "request.hh"
|
||||
#include "result.hh"
|
||||
|
||||
/// Super-class of all positioning algorithms
|
||||
class PositioningAlgorithm
|
||||
{
|
||||
public:
|
||||
PositioningAlgorithm(void) {}
|
||||
virtual ~PositioningAlgorithm(void) {}
|
||||
|
||||
virtual Result compute(const Request &request) = 0 ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_POSITIONINGALGORITHM_HH_
|
|
@ -0,0 +1,21 @@
|
|||
#include "realposition.hh"
|
||||
#include "calibrationrequest.hh"
|
||||
#include "referencepoint.hh"
|
||||
|
||||
|
||||
|
||||
Result RealPosition::compute(const Request &request)
|
||||
{
|
||||
const CalibrationRequest *calibration_request =
|
||||
dynamic_cast<const CalibrationRequest*>(&request) ;
|
||||
|
||||
if (calibration_request != NULL)
|
||||
{
|
||||
Point3D *coordinates =
|
||||
static_cast<Point3D*>(
|
||||
calibration_request->get_reference_point()) ;
|
||||
return Result(&request, *coordinates) ;
|
||||
}
|
||||
|
||||
return Result(&request) ;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef _OWLPS_POSITIONING_REALPOSITION_HH_
|
||||
#define _OWLPS_POSITIONING_REALPOSITION_HH_
|
||||
|
||||
#include "positioningalgorithm.hh"
|
||||
|
||||
/// Pseudo-algorithm that "computes" the real position
|
||||
/**
|
||||
* The real position is extracted from CalibrationRequests. If the
|
||||
* request is a simple Request, the computed position is (0;0;0).
|
||||
*/
|
||||
class RealPosition: public PositioningAlgorithm
|
||||
{
|
||||
public:
|
||||
Result compute(const Request &request) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_REALPOSITION_HH_
|
|
@ -0,0 +1,39 @@
|
|||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "realposition.hh"
|
||||
|
||||
class RealPosition_test: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
|
||||
void test_compute(void)
|
||||
{
|
||||
Point3D null_point(0,0,0) ;
|
||||
ReferencePoint reference_point(1,2,3) ;
|
||||
Direction direction(Direction::south) ;
|
||||
Request request ;
|
||||
CalibrationRequest calibration_request(request, &reference_point,
|
||||
direction) ;
|
||||
|
||||
PositioningAlgorithm *algo = new RealPosition() ;
|
||||
Result res ;
|
||||
|
||||
res = algo->compute(request) ;
|
||||
TS_ASSERT_EQUALS(res.get_position(), null_point) ;
|
||||
|
||||
res = algo->compute(calibration_request) ;
|
||||
TS_ASSERT_EQUALS(res.get_position(), reference_point) ;
|
||||
|
||||
Request *request_ptr ;
|
||||
request_ptr = &request ;
|
||||
res = algo->compute(*request_ptr) ;
|
||||
TS_ASSERT_EQUALS(res.get_position(), null_point) ;
|
||||
|
||||
request_ptr = static_cast<Request*>(&calibration_request) ;
|
||||
res = algo->compute(*request_ptr) ;
|
||||
TS_ASSERT_EQUALS(res.get_position(), reference_point) ;
|
||||
|
||||
delete algo ;
|
||||
}
|
||||
|
||||
} ;
|
Loading…
Reference in New Issue