diff --git a/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_I2CAccelerometerTest.cpp b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_I2CAccelerometerTest.cpp new file mode 100644 index 0000000000..a432901fd6 --- /dev/null +++ b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_I2CAccelerometerTest.cpp @@ -0,0 +1,47 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "ADXL345_I2C.h" +#include "ADXL345_I2CAccelerometerData.h" +#include "Talon.h" +#include "gtest/gtest.h" + +class ADXL345_I2CAccelerometerTest + : public ::testing::TestWithParam {}; + +TEST_P(ADXL345_I2CAccelerometerTest, TestAccelerometer) { + const double EPSILON = 1 / 256.0; + + frc::I2C::Port port = GetParam(); + + hal::ADXL345_I2CData sim{port}; + frc::ADXL345_I2C accel{port}; + + EXPECT_NEAR(0, sim.GetX(), EPSILON); + EXPECT_NEAR(0, sim.GetY(), EPSILON); + EXPECT_NEAR(0, sim.GetZ(), EPSILON); + + EXPECT_NEAR(0, accel.GetX(), EPSILON); + EXPECT_NEAR(0, accel.GetY(), EPSILON); + EXPECT_NEAR(0, accel.GetZ(), EPSILON); + + sim.SetX(1.56); + sim.SetY(-.653); + sim.SetZ(0.11); + + EXPECT_NEAR(1.56, sim.GetX(), EPSILON); + EXPECT_NEAR(-.653, sim.GetY(), EPSILON); + EXPECT_NEAR(0.11, sim.GetZ(), EPSILON); + + EXPECT_NEAR(1.56, accel.GetX(), EPSILON); + EXPECT_NEAR(-.653, accel.GetY(), EPSILON); + EXPECT_NEAR(0.11, accel.GetZ(), EPSILON); +} + +INSTANTIATE_TEST_CASE_P(ADXL345_I2CAccelerometerTest, + ADXL345_I2CAccelerometerTest, + ::testing::Values(frc::I2C::kOnboard, frc::I2C::kMXP)); diff --git a/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_SpiAccelerometerTest.cpp b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_SpiAccelerometerTest.cpp new file mode 100644 index 0000000000..1a437d7527 --- /dev/null +++ b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL345_SpiAccelerometerTest.cpp @@ -0,0 +1,49 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "ADXL345_SPI.h" +#include "ADXL345_SpiAccelerometerData.h" +#include "Talon.h" +#include "gtest/gtest.h" + +class ADXL345_SpiAccelerometerTest + : public ::testing::TestWithParam {}; + +TEST_P(ADXL345_SpiAccelerometerTest, TestAccelerometer) { + const double EPSILON = 1 / 256.0; + + frc::SPI::Port port = GetParam(); + + hal::ADXL345_SpiAccelerometer sim{port}; + frc::ADXL345_SPI accel{port}; + + EXPECT_NEAR(0, sim.GetX(), EPSILON); + EXPECT_NEAR(0, sim.GetY(), EPSILON); + EXPECT_NEAR(0, sim.GetZ(), EPSILON); + + EXPECT_NEAR(0, accel.GetX(), EPSILON); + EXPECT_NEAR(0, accel.GetY(), EPSILON); + EXPECT_NEAR(0, accel.GetZ(), EPSILON); + + sim.SetX(1.56); + sim.SetY(-.653); + sim.SetZ(0.11); + + EXPECT_NEAR(1.56, sim.GetX(), EPSILON); + EXPECT_NEAR(-.653, sim.GetY(), EPSILON); + EXPECT_NEAR(0.11, sim.GetZ(), EPSILON); + + EXPECT_NEAR(1.56, accel.GetX(), EPSILON); + EXPECT_NEAR(-.653, accel.GetY(), EPSILON); + EXPECT_NEAR(0.11, accel.GetZ(), EPSILON); +} + +INSTANTIATE_TEST_CASE_P( + ADXL345_SpiAccelerometerTest, ADXL345_SpiAccelerometerTest, + ::testing::Values(frc::SPI::kOnboardCS0, frc::SPI::kOnboardCS1, + frc::SPI::kOnboardCS2, frc::SPI::kOnboardCS3, + frc::SPI::kMXP)); diff --git a/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL362_SpiAccelerometerTest.cpp b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL362_SpiAccelerometerTest.cpp new file mode 100644 index 0000000000..6e445ffc1f --- /dev/null +++ b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXL362_SpiAccelerometerTest.cpp @@ -0,0 +1,49 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "ADXL362.h" +#include "ADXL362_SpiAccelerometerData.h" +#include "Talon.h" +#include "gtest/gtest.h" + +class ADXL362_SpiAccelerometerTest + : public ::testing::TestWithParam {}; + +TEST_P(ADXL362_SpiAccelerometerTest, TestAccelerometer) { + const double EPSILON = 1 / 256.0; + + frc::SPI::Port port = GetParam(); + + hal::ADXL362_SpiAccelerometer sim{port}; + frc::ADXL362 accel{port}; + + EXPECT_NEAR(0, sim.GetX(), EPSILON); + EXPECT_NEAR(0, sim.GetY(), EPSILON); + EXPECT_NEAR(0, sim.GetZ(), EPSILON); + + EXPECT_NEAR(0, accel.GetX(), EPSILON); + EXPECT_NEAR(0, accel.GetY(), EPSILON); + EXPECT_NEAR(0, accel.GetZ(), EPSILON); + + sim.SetX(1.56); + sim.SetY(-.653); + sim.SetZ(0.11); + + EXPECT_NEAR(1.56, sim.GetX(), EPSILON); + EXPECT_NEAR(-.653, sim.GetY(), EPSILON); + EXPECT_NEAR(0.11, sim.GetZ(), EPSILON); + + EXPECT_NEAR(1.56, accel.GetX(), EPSILON); + EXPECT_NEAR(-.653, accel.GetY(), EPSILON); + EXPECT_NEAR(0.11, accel.GetZ(), EPSILON); +} + +INSTANTIATE_TEST_CASE_P( + ADXL362_SpiAccelerometerTest, ADXL362_SpiAccelerometerTest, + ::testing::Values(frc::SPI::kOnboardCS0, frc::SPI::kOnboardCS1, + frc::SPI::kOnboardCS2, frc::SPI::kOnboardCS3, + frc::SPI::kMXP)); diff --git a/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXRS450_SpiGyroWrapperTest.cpp b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXRS450_SpiGyroWrapperTest.cpp new file mode 100644 index 0000000000..ebb42fa297 --- /dev/null +++ b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/ADXRS450_SpiGyroWrapperTest.cpp @@ -0,0 +1,36 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "ADXRS450_Gyro.h" +#include "ADXRS450_SpiGyroWrapperData.h" +#include "Talon.h" +#include "gtest/gtest.h" + +class ADXRS450_SpiGyroWrapperTest + : public ::testing::TestWithParam {}; + +TEST_P(ADXRS450_SpiGyroWrapperTest, TestAccelerometer) { + const double EPSILON = .000001; + + frc::SPI::Port port = GetParam(); + + hal::ADXRS450_SpiGyroWrapper sim{port}; + frc::ADXRS450_Gyro gyro{port}; + + EXPECT_NEAR(0, sim.GetAngle(), EPSILON); + EXPECT_NEAR(0, gyro.GetAngle(), EPSILON); + + sim.SetAngle(32.56); + EXPECT_NEAR(32.56, sim.GetAngle(), EPSILON); + EXPECT_NEAR(32.56, gyro.GetAngle(), EPSILON); +} + +INSTANTIATE_TEST_CASE_P( + ADXRS450_SpiGyroWrapperTest, ADXRS450_SpiGyroWrapperTest, + ::testing::Values(frc::SPI::kOnboardCS0, frc::SPI::kOnboardCS1, + frc::SPI::kOnboardCS2, frc::SPI::kOnboardCS3, + frc::SPI::kMXP)); diff --git a/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/main.cpp b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/main.cpp new file mode 100644 index 0000000000..298f23c1f8 --- /dev/null +++ b/simulation/halsim_adx_gyro_accelerometer/src/test/native/cpp/main.cpp @@ -0,0 +1,17 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include + +#include "gtest/gtest.h" + +int main(int argc, char** argv) { + HAL_Initialize(500, 0); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +}