Files
allwpilib/wpilibc/wpilibC++IntegrationTests/src/CANTalonTest.cpp
Tyler Veness 2bf3b6bed4 Replaced WPILib.h includes in integration tests with the minimum required subheaders to improve compilation times
I ran the benchmark in a tmpfs with an Intel Core i5-2430M. I ran it three times for each combination of build invokation and source tree.

First, I tested "make". For master (eb7d55f), I measured an average of 42.751s with a standard deviation of 0.372s. For this commit, I measured an average of 33.394s with a standard deviation of 0.140s. There was a 9.356s, or 22%, improvement with a total error of 1.3%.

Second, I tested "make -j4". For master (eb7d55f), I measured an average of 21.723s with a standard deviation of 0.158s. For this commit, I measured an average of 16.823s with a standard deviation of 0.340s. There was a 4.900s, or 23%, improvement with a total error of 2.7%.

Change-Id: Idb3adce62ed8ef449360c6583896b6da3565cf58
2015-08-13 11:31:46 -07:00

70 lines
2.0 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2014. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#include <CANTalon.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
const int deviceId = 0;
TEST(CANTalonTest, QuickTest) {
double throttle = 0.1;
CANTalon talon(deviceId);
talon.SetControlMode(CANSpeedController::kPercentVbus);
talon.EnableControl();
talon.Set(throttle);
Wait(0.25);
EXPECT_NEAR(talon.Get(), throttle, 5e-3);
talon.Set(-throttle);
Wait(0.25);
EXPECT_NEAR(talon.Get(), -throttle, 5e-3);
talon.Disable();
Wait(0.1);
EXPECT_FLOAT_EQ(talon.Get(), 0.0);
}
TEST(CANTalonTest, SetGetPID) {
// Tests that we can actually set and get PID values as intended.
CANTalon talon(deviceId);
double p = 0.05, i = 0.098, d = 1.23;
talon.SetPID(p, i, d);
// Wait(0.03);
EXPECT_NEAR(p, talon.GetP(), 1e-5);
EXPECT_NEAR(i, talon.GetI(), 1e-5);
EXPECT_NEAR(d, talon.GetD(), 1e-5);
// Test with new values in case the talon was already set to the previous
// ones.
p = 0.15;
i = 0.198;
d = 1.03;
talon.SetPID(p, i, d);
// Wait(0.03);
EXPECT_NEAR(p, talon.GetP(), 1e-5);
EXPECT_NEAR(i, talon.GetI(), 1e-5);
EXPECT_NEAR(d, talon.GetD(), 1e-5);
}
TEST(CANTalonTest, DISABLED_PositionModeWorks) {
CANTalon talon(deviceId);
talon.SetFeedbackDevice(CANTalon::AnalogPot);
talon.SetControlMode(CANSpeedController::kPosition);
Wait(0.1);
double p = 2;
double i = 0.00;
double d = 0.00;
Wait(0.2);
talon.SetControlMode(CANSpeedController::kPosition);
talon.SetFeedbackDevice(CANTalon::AnalogPot);
talon.SetPID(p, i, d);
Wait(0.2);
talon.Set(100);
Wait(100);
talon.Disable();
EXPECT_NEAR(talon.Get(), 500, 1000);
}