2014-11-17 16:02:41 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
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-07-22 02:34:12 -07:00
|
|
|
#include <CANTalon.h>
|
|
|
|
|
#include <Timer.h>
|
2014-11-17 16:02:41 -05:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "TestBench.h"
|
|
|
|
|
|
2014-11-26 15:15:52 -05:00
|
|
|
const int deviceId = 0;
|
|
|
|
|
|
2014-11-17 16:02:41 -05:00
|
|
|
TEST(CANTalonTest, QuickTest) {
|
2014-12-01 14:05:26 -05:00
|
|
|
double throttle = 0.1;
|
2015-06-25 15:07:55 -04:00
|
|
|
CANTalon talon(deviceId);
|
2014-11-17 16:02:41 -05:00
|
|
|
talon.SetControlMode(CANSpeedController::kPercentVbus);
|
|
|
|
|
talon.EnableControl();
|
2014-12-01 14:05:26 -05:00
|
|
|
talon.Set(throttle);
|
2014-11-26 15:15:52 -05:00
|
|
|
Wait(0.25);
|
2014-12-01 14:05:26 -05:00
|
|
|
EXPECT_NEAR(talon.Get(), throttle, 5e-3);
|
|
|
|
|
talon.Set(-throttle);
|
2014-11-17 16:02:41 -05:00
|
|
|
Wait(0.25);
|
2014-12-01 14:05:26 -05:00
|
|
|
EXPECT_NEAR(talon.Get(), -throttle, 5e-3);
|
2014-11-26 15:15:52 -05:00
|
|
|
|
|
|
|
|
talon.Disable();
|
2014-12-01 14:05:26 -05:00
|
|
|
Wait(0.1);
|
|
|
|
|
EXPECT_FLOAT_EQ(talon.Get(), 0.0);
|
2014-11-26 15:15:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2015-06-25 15:07:55 -04:00
|
|
|
talon.SetPID(p, i, d);
|
2014-12-01 14:05:26 -05:00
|
|
|
// Wait(0.03);
|
2014-11-26 15:15:52 -05:00
|
|
|
EXPECT_NEAR(p, talon.GetP(), 1e-5);
|
|
|
|
|
EXPECT_NEAR(i, talon.GetI(), 1e-5);
|
|
|
|
|
EXPECT_NEAR(d, talon.GetD(), 1e-5);
|
2015-06-25 15:07:55 -04:00
|
|
|
// Test with new values in case the talon was already set to the previous
|
|
|
|
|
// ones.
|
2014-11-26 15:15:52 -05:00
|
|
|
p = 0.15;
|
|
|
|
|
i = 0.198;
|
|
|
|
|
d = 1.03;
|
2015-06-25 15:07:55 -04:00
|
|
|
talon.SetPID(p, i, d);
|
2014-12-01 14:05:26 -05:00
|
|
|
// Wait(0.03);
|
2014-11-26 15:15:52 -05:00
|
|
|
EXPECT_NEAR(p, talon.GetP(), 1e-5);
|
|
|
|
|
EXPECT_NEAR(i, talon.GetI(), 1e-5);
|
|
|
|
|
EXPECT_NEAR(d, talon.GetD(), 1e-5);
|
|
|
|
|
}
|
2014-11-17 16:02:41 -05:00
|
|
|
|
2014-11-26 15:15:52 -05:00
|
|
|
TEST(CANTalonTest, DISABLED_PositionModeWorks) {
|
|
|
|
|
CANTalon talon(deviceId);
|
2014-12-01 14:05:26 -05:00
|
|
|
talon.SetFeedbackDevice(CANTalon::AnalogPot);
|
2014-11-26 15:15:52 -05:00
|
|
|
talon.SetControlMode(CANSpeedController::kPosition);
|
2014-12-01 14:05:26 -05:00
|
|
|
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);
|
2014-11-17 16:02:41 -05:00
|
|
|
talon.Disable();
|
2014-12-01 14:05:26 -05:00
|
|
|
EXPECT_NEAR(talon.Get(), 500, 1000);
|
2014-11-17 16:02:41 -05:00
|
|
|
}
|