mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add names to simulator components (#1268)
Makes configuration easier when you can associate the items with a name instead of just a port number. Important if there is a GUI added at some point.
This commit is contained in:
committed by
Peter Johnson
parent
8d8f120cc3
commit
de212a9dd0
@@ -15,17 +15,22 @@ TEST(AccelerometerTests, TestADXL345_I2CAccelerometerWrapper) {
|
||||
|
||||
frc::I2C::Port port = frc::I2C::kOnboard;
|
||||
|
||||
frc::ADXL345_I2C accel{port};
|
||||
|
||||
EXPECT_NEAR(0, accel.GetX(), EPSILON);
|
||||
EXPECT_NEAR(0, accel.GetY(), EPSILON);
|
||||
EXPECT_NEAR(0, accel.GetZ(), EPSILON);
|
||||
|
||||
hal::ADXL345_I2CData rawAdxSim(port);
|
||||
frc::sim::lowfi::ADXLThreeAxisAccelerometerSim accelerometerSim(rawAdxSim);
|
||||
frc::sim::lowfi::AccelerometerSim& xWrapper = accelerometerSim.GetXWrapper();
|
||||
frc::sim::lowfi::AccelerometerSim& yWrapper = accelerometerSim.GetYWrapper();
|
||||
frc::sim::lowfi::AccelerometerSim& zWrapper = accelerometerSim.GetZWrapper();
|
||||
EXPECT_FALSE(xWrapper.IsWrapperInitialized());
|
||||
EXPECT_FALSE(yWrapper.IsWrapperInitialized());
|
||||
EXPECT_FALSE(zWrapper.IsWrapperInitialized());
|
||||
|
||||
frc::ADXL345_I2C accel{port};
|
||||
EXPECT_NEAR(0, accel.GetX(), EPSILON);
|
||||
EXPECT_NEAR(0, accel.GetY(), EPSILON);
|
||||
EXPECT_NEAR(0, accel.GetZ(), EPSILON);
|
||||
EXPECT_TRUE(xWrapper.IsWrapperInitialized());
|
||||
EXPECT_TRUE(yWrapper.IsWrapperInitialized());
|
||||
EXPECT_TRUE(zWrapper.IsWrapperInitialized());
|
||||
|
||||
xWrapper.SetAcceleration(1.45);
|
||||
EXPECT_NEAR(1.45, accel.GetX(), EPSILON);
|
||||
|
||||
@@ -25,16 +25,23 @@ void TestGyro(frc::sim::lowfi::GyroSim& sim, frc::Gyro& gyro) {
|
||||
|
||||
TEST(GyroSimulatorTests, TestAnalogGyro) {
|
||||
int port = 1;
|
||||
frc::AnalogGyro gyro{port};
|
||||
frc::sim::lowfi::WpiAnalogGyroSim sim{port};
|
||||
EXPECT_FALSE(sim.IsWrapperInitialized());
|
||||
|
||||
frc::AnalogGyro gyro{port};
|
||||
EXPECT_TRUE(sim.IsWrapperInitialized());
|
||||
|
||||
TestGyro(sim, gyro);
|
||||
}
|
||||
|
||||
TEST(GyroSimulatorTests, TestSpiGyro) {
|
||||
frc::SPI::Port port = frc::SPI::kOnboardCS0;
|
||||
|
||||
frc::sim::lowfi::ADXRS450_SpiGyroSim sim{port};
|
||||
EXPECT_FALSE(sim.IsWrapperInitialized());
|
||||
|
||||
frc::ADXRS450_Gyro gyro{port};
|
||||
EXPECT_TRUE(sim.IsWrapperInitialized());
|
||||
|
||||
TestGyro(sim, gyro);
|
||||
}
|
||||
|
||||
@@ -14,14 +14,18 @@
|
||||
#include "lowfisim/wpisimulators/WpiMotorSim.h"
|
||||
|
||||
TEST(MotorEncoderConnectorTest, TestWithoutDistancePerPulseFullSpeed) {
|
||||
frc::Talon talon{3};
|
||||
frc::Encoder encoder{3, 1};
|
||||
|
||||
frc::sim::lowfi::SimpleMotorModel motorModelSim(6000);
|
||||
frc::sim::lowfi::WpiMotorSim motorSim(3, motorModelSim);
|
||||
frc::sim::lowfi::WpiEncoderSim encoderSim(0);
|
||||
frc::sim::lowfi::MotorEncoderConnector connector(motorSim, encoderSim);
|
||||
|
||||
EXPECT_FALSE(motorSim.IsWrapperInitialized());
|
||||
EXPECT_FALSE(encoderSim.IsWrapperInitialized());
|
||||
frc::Talon talon{3};
|
||||
frc::Encoder encoder{3, 1};
|
||||
EXPECT_TRUE(motorSim.IsWrapperInitialized());
|
||||
EXPECT_TRUE(encoderSim.IsWrapperInitialized());
|
||||
|
||||
talon.Set(-1);
|
||||
motorSim.Update(1);
|
||||
connector.Update();
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user