forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix controller command examples, add tests
- Loading branch information
1 parent
a70e83a
commit 0a12197
Showing
9 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...mples/src/test/cpp/examples/MecanumControllerCommand/cpp/MecanumControllerCommandTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <thread> | ||
|
||
#include <frc/simulation/DriverStationSim.h> | ||
#include <frc/simulation/SimHooks.h> | ||
#include <gtest/gtest.h> | ||
#include <units/time.h> | ||
|
||
#include "Robot.h" | ||
|
||
class MecanumControllerCommandTest : public testing::Test { | ||
Robot m_robot; | ||
std::optional<std::thread> m_thread; | ||
bool joystickWarning; | ||
|
||
public: | ||
void SetUp() override { | ||
frc::sim::PauseTiming(); | ||
joystickWarning = frc::DriverStation::IsJoystickConnectionWarningSilenced(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(true); | ||
|
||
m_thread = std::thread([&] { m_robot.StartCompetition(); }); | ||
frc::sim::StepTiming(0.0_ms); // Wait for Notifiers | ||
} | ||
|
||
void TearDown() override { | ||
m_robot.EndCompetition(); | ||
m_thread->join(); | ||
|
||
frc::sim::DriverStationSim::ResetData(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(joystickWarning); | ||
} | ||
}; | ||
|
||
TEST_F(MecanumControllerCommandTest, Match) { | ||
// auto | ||
frc::sim::DriverStationSim::SetAutonomous(true); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(15_s); | ||
|
||
// brief disabled period- exact duration shouldn't matter | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(3_s); | ||
|
||
// teleop | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(135_s); | ||
|
||
// end of match | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
} |
16 changes: 16 additions & 0 deletions
16
wpilibcExamples/src/test/cpp/examples/MecanumControllerCommand/cpp/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <gtest/gtest.h> | ||
#include <hal/HALBase.h> | ||
|
||
/** | ||
* Runs all unit tests. | ||
*/ | ||
int main(int argc, char** argv) { | ||
HAL_Initialize(500, 0); | ||
::testing::InitGoogleTest(&argc, argv); | ||
int ret = RUN_ALL_TESTS(); | ||
return ret; | ||
} |
64 changes: 64 additions & 0 deletions
64
wpilibcExamples/src/test/cpp/examples/RamseteCommand/cpp/RamseteCommandTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <thread> | ||
|
||
#include <frc/simulation/DriverStationSim.h> | ||
#include <frc/simulation/SimHooks.h> | ||
#include <gtest/gtest.h> | ||
#include <units/time.h> | ||
|
||
#include "Robot.h" | ||
|
||
class MecanumControllerCommandTest : public testing::Test { | ||
Robot m_robot; | ||
std::optional<std::thread> m_thread; | ||
bool joystickWarning; | ||
|
||
public: | ||
void SetUp() override { | ||
frc::sim::PauseTiming(); | ||
joystickWarning = frc::DriverStation::IsJoystickConnectionWarningSilenced(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(true); | ||
|
||
m_thread = std::thread([&] { m_robot.StartCompetition(); }); | ||
frc::sim::StepTiming(0.0_ms); // Wait for Notifiers | ||
} | ||
|
||
void TearDown() override { | ||
m_robot.EndCompetition(); | ||
m_thread->join(); | ||
|
||
frc::sim::DriverStationSim::ResetData(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(joystickWarning); | ||
} | ||
}; | ||
|
||
TEST_F(MecanumControllerCommandTest, Match) { | ||
// auto | ||
frc::sim::DriverStationSim::SetAutonomous(true); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(15_s); | ||
|
||
// brief disabled period- exact duration shouldn't matter | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(3_s); | ||
|
||
// teleop | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(135_s); | ||
|
||
// end of match | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
} |
16 changes: 16 additions & 0 deletions
16
wpilibcExamples/src/test/cpp/examples/RamseteCommand/cpp/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <gtest/gtest.h> | ||
#include <hal/HALBase.h> | ||
|
||
/** | ||
* Runs all unit tests. | ||
*/ | ||
int main(int argc, char** argv) { | ||
HAL_Initialize(500, 0); | ||
::testing::InitGoogleTest(&argc, argv); | ||
int ret = RUN_ALL_TESTS(); | ||
return ret; | ||
} |
69 changes: 69 additions & 0 deletions
69
...xamples/src/test/cpp/examples/SwerveControllerCommand/cpp/SwerveControllerCommandTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
#include <frc/simulation/DriverStationSim.h> | ||
#include <frc/simulation/SimHooks.h> | ||
#include <gtest/gtest.h> | ||
#include <units/time.h> | ||
|
||
#include "Robot.h" | ||
|
||
class SwerveControllerCommandTest : public testing::Test { | ||
Robot m_robot; | ||
std::optional<std::thread> m_thread; | ||
bool joystickWarning; | ||
|
||
public: | ||
void SetUp() override { | ||
frc::sim::PauseTiming(); | ||
joystickWarning = frc::DriverStation::IsJoystickConnectionWarningSilenced(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(true); | ||
|
||
m_thread = std::thread([&] { m_robot.StartCompetition(); }); | ||
frc::sim::StepTiming(0.0_ms); // Wait for Notifiers | ||
} | ||
|
||
void TearDown() override { | ||
m_robot.EndCompetition(); | ||
m_thread->join(); | ||
|
||
frc::sim::DriverStationSim::ResetData(); | ||
frc::DriverStation::SilenceJoystickConnectionWarning(joystickWarning); | ||
} | ||
}; | ||
|
||
TEST_F(SwerveControllerCommandTest, Match) { | ||
std::cerr << "autonomous" << std::endl; | ||
// auto | ||
frc::sim::DriverStationSim::SetAutonomous(true); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(15_s); | ||
|
||
// brief disabled period- exact duration shouldn't matter | ||
std::cerr << "mid disabled" << std::endl; | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(3_s); | ||
|
||
// teleop | ||
std::cerr << "teleop" << std::endl; | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(true); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
|
||
frc::sim::StepTiming(135_s); | ||
|
||
// end of match | ||
std::cerr << "end of match" << std::endl; | ||
frc::sim::DriverStationSim::SetAutonomous(false); | ||
frc::sim::DriverStationSim::SetEnabled(false); | ||
frc::sim::DriverStationSim::NotifyNewData(); | ||
} |
16 changes: 16 additions & 0 deletions
16
wpilibcExamples/src/test/cpp/examples/SwerveControllerCommand/cpp/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#include <gtest/gtest.h> | ||
#include <hal/HALBase.h> | ||
|
||
/** | ||
* Runs all unit tests. | ||
*/ | ||
int main(int argc, char** argv) { | ||
HAL_Initialize(500, 0); | ||
::testing::InitGoogleTest(&argc, argv); | ||
int ret = RUN_ALL_TESTS(); | ||
return ret; | ||
} |