[wpilib] Use IsSimulation() consistently (#3534)

This commit is contained in:
Tyler Veness
2023-09-15 20:05:16 -07:00
committed by GitHub
parent 12e2043b77
commit 575348b81c
5 changed files with 21 additions and 15 deletions

View File

@@ -13,7 +13,7 @@ std::string frc::filesystem::GetLaunchDirectory() {
}
std::string frc::filesystem::GetOperatingDirectory() {
if constexpr (RobotBase::IsReal()) {
if constexpr (!RobotBase::IsSimulation()) {
return "/home/lvuser";
} else {
return frc::filesystem::GetLaunchDirectory();
@@ -21,7 +21,7 @@ std::string frc::filesystem::GetOperatingDirectory() {
}
std::string frc::filesystem::GetDeployDirectory() {
if constexpr (RobotBase::IsReal()) {
if constexpr (!RobotBase::IsSimulation()) {
return "/home/lvuser/deploy";
} else {
return (fs::current_path() / "src" / "main" / "deploy").string();

View File

@@ -231,11 +231,11 @@ RobotBase::RobotBase() {
auto inst = nt::NetworkTableInstance::GetDefault();
// subscribe to "" to force persistent values to propagate to local
nt::SubscribeMultiple(inst.GetHandle(), {{std::string_view{}}});
#ifdef __FRC_ROBORIO__
inst.StartServer("/home/lvuser/networktables.json");
#else
inst.StartServer();
#endif
if constexpr (!IsSimulation()) {
inst.StartServer("/home/lvuser/networktables.json");
} else {
inst.StartServer();
}
// wait for the NT server to actually start
int count = 0;
@@ -251,7 +251,7 @@ RobotBase::RobotBase() {
SmartDashboard::init();
if (IsReal()) {
if constexpr (!IsSimulation()) {
std::FILE* file = nullptr;
file = std::fopen("/tmp/frc_versions/FRC_Lib_Version.ini", "w");

View File

@@ -227,7 +227,13 @@ class RobotBase {
*
* @return If the robot is running in simulation.
*/
static constexpr bool IsSimulation() { return !IsReal(); }
static constexpr bool IsSimulation() {
#ifdef __FRC_ROBORIO__
return false;
#else
return true;
#endif
}
/**
* Constructor for a generic robot program.

View File

@@ -39,7 +39,7 @@ public final class Filesystem {
* @return The operating directory
*/
public static File getOperatingDirectory() {
if (RobotBase.isReal()) {
if (!RobotBase.isSimulation()) {
return new File("/home/lvuser");
} else {
return getLaunchDirectory();
@@ -54,7 +54,7 @@ public final class Filesystem {
* @return The 'deploy' directory
*/
public static File getDeployDirectory() {
if (RobotBase.isReal()) {
if (!RobotBase.isSimulation()) {
return new File(getOperatingDirectory(), "deploy");
} else {
return new File(

View File

@@ -74,7 +74,7 @@ public abstract class RobotBase implements AutoCloseable {
@Override
public boolean isRoboRIO() {
return RobotBase.isReal();
return !RobotBase.isSimulation();
}
};
@@ -154,7 +154,7 @@ public abstract class RobotBase implements AutoCloseable {
setupMathShared();
// subscribe to "" to force persistent values to propagate to local
m_suball = new MultiSubscriber(inst, new String[] {""});
if (isReal()) {
if (!isSimulation()) {
inst.startServer("/home/lvuser/networktables.json");
} else {
inst.startServer();
@@ -202,7 +202,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return If the robot is running in simulation.
*/
public static boolean isSimulation() {
return !isReal();
return HALUtil.getHALRuntimeType() != 0;
}
/**
@@ -337,7 +337,7 @@ public abstract class RobotBase implements AutoCloseable {
m_robotCopy = robot;
m_runMutex.unlock();
if (isReal()) {
if (!isSimulation()) {
final File file = new File("/tmp/frc_versions/FRC_Lib_Version.ini");
try {
if (file.exists() && !file.delete()) {