Skip to content

Commit

Permalink
ECL Unit Test Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilritz authored and bresch committed Dec 16, 2019
1 parent 6b25dbd commit 2d2edd9
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 179 deletions.
4 changes: 1 addition & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@

include(gtest.cmake)

add_library(SENSOR_SIMULATOR SensorSimulator.cpp)
target_link_libraries(SENSOR_SIMULATOR ecl_EKF)
add_subdirectory(SensorSimulator)

set(SRCS
main.cpp
test_EKF_basics.cpp
test_EKF_ringbuffer.cpp
test_EKF_imuSampling.cpp
test_AlphaFilter.cpp
test_SensorSimulator.cpp
)
add_executable(ECL_GTESTS ${SRCS})

Expand Down
89 changes: 0 additions & 89 deletions test/SensorSimulator.cpp

This file was deleted.

20 changes: 20 additions & 0 deletions test/SensorSimulator/Baro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Baro.h"

Baro::Baro(Ekf* ekf):Sensor(ekf)
{
}

Baro::~Baro()
{
}

void Baro::send(uint32_t time)
{
_ekf->setBaroData(time,_baro_data);
_time_last_data_sent = time;
}

void Baro::setData(float baro)
{
_baro_data = baro;
}
42 changes: 15 additions & 27 deletions test/test_SensorSimulator.cpp → test/SensorSimulator/Baro.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,26 @@
*
****************************************************************************/

#include <gtest/gtest.h>
#include <math.h>
#include "SensorSimulator.h"
#include "EKF/ekf.h"
/**
* Feeds Ekf with Mag data
* @author Kamil Ritz <ka.ritz@hotmail.com>
*/
#pragma once

using namespace simulator;
#include "Sensor.h"

class Baro: public Sensor
{
public:
Baro(Ekf* ekf);
~Baro();

class SensorSimulatorTest : public ::testing::Test {
public:
void setData(float baro);

// Ekf* _ekf;
// SensorSimulator* _sensor_simulator;
private:
float _baro_data;

void SetUp() override
{
// _ekf = new Ekf();
// _ekf->init(0);
}
void send(uint32_t time);

void TearDown() override
{
// delete _sensor_simulator;
// delete _ekf;
}
};

TEST_F(SensorSimulatorTest, greatestCommonDivider)
{
// Test gcd function with some example
EXPECT_EQ(gcd(uint32_t(3), uint32_t(402)), uint32_t(3));
EXPECT_EQ(gcd(uint32_t(3), uint32_t(401)), uint32_t(1));


}
45 changes: 45 additions & 0 deletions test/SensorSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
############################################################################
#
# Copyright (c) 2019 ECL Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name ECL nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################


set(SRCS
SensorSimulator.cpp
Sensor.cpp
Imu.cpp
Mag.cpp
Baro.cpp
Gps.cpp
)

add_library(SENSOR_SIMULATOR ${SRCS})
target_link_libraries(SENSOR_SIMULATOR ecl_EKF)
20 changes: 20 additions & 0 deletions test/SensorSimulator/Gps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Gps.h"

Gps::Gps(Ekf* ekf):Sensor(ekf)
{
}

Gps::~Gps()
{
}

void Gps::send(uint32_t time)
{
_gps_data.time_usec = time;
_ekf->setGpsData(time, _gps_data);
}

void Gps::setData(gps_message gps)
{
_gps_data = gps;
}
56 changes: 56 additions & 0 deletions test/SensorSimulator/Gps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/****************************************************************************
*
* Copyright (c) 2019 ECL Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/

/**
* Feeds Ekf with Gps data
* @author Kamil Ritz <ka.ritz@hotmail.com>
*/
#pragma once

#include "Sensor.h"

class Gps: public Sensor
{
public:
Gps(Ekf* ekf);
~Gps();

void setData(gps_message gps);

private:
gps_message _gps_data;

void send(uint32_t time);

};

39 changes: 39 additions & 0 deletions test/SensorSimulator/Imu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Imu.h"

Imu::Imu(Ekf* ekf):Sensor(ekf)
{
}

Imu::~Imu()
{
}

void Imu::send(uint32_t time)
{
// fill imu sample with stored data
imuSample imu_sample;
imu_sample.time_us = time;
imu_sample.delta_ang_dt = (time - _time_last_data_sent) * 1.e-6f;
imu_sample.delta_ang = _gyro_data * imu_sample.delta_ang_dt;
imu_sample.delta_vel_dt = (time - _time_last_data_sent) * 1.e-6f;
imu_sample.delta_vel = _accel_data * imu_sample.delta_vel_dt;

_ekf->setIMUData(imu_sample);
_time_last_data_sent = time;
}

void Imu::setData(Vector3f accel, Vector3f gyro)
{
setAccelData(accel);
setGyroData(gyro);
}

void Imu::setAccelData(Vector3f accel)
{
_accel_data = accel;
}

void Imu::setGyroData(Vector3f gyro)
{
_gyro_data = gyro;
}
Loading

0 comments on commit 2d2edd9

Please sign in to comment.