2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2025-11-07 19:55:43 -05:00
|
|
|
package org.wpilib.simulation;
|
2020-07-04 00:44:37 -07:00
|
|
|
|
2025-12-12 21:25:57 -07:00
|
|
|
import org.wpilib.hardware.hal.ControlWord;
|
2025-11-07 19:55:43 -05:00
|
|
|
import org.wpilib.hardware.hal.simulation.SimulatorJNI;
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2024-01-04 08:38:06 -08:00
|
|
|
/** Simulation hooks. */
|
2018-06-03 10:00:53 -07:00
|
|
|
public final class SimHooks {
|
2020-12-29 22:45:16 -08:00
|
|
|
private SimHooks() {}
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Override the HAL runtime type (simulated/real).
|
|
|
|
|
*
|
|
|
|
|
* @param type runtime type
|
|
|
|
|
*/
|
2020-06-26 20:46:13 -07:00
|
|
|
public static void setHALRuntimeType(int type) {
|
|
|
|
|
SimulatorJNI.setRuntimeType(type);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-05 07:35:59 -08:00
|
|
|
/** Waits until the user program has started. */
|
2018-05-11 12:38:23 -07:00
|
|
|
public static void waitForProgramStart() {
|
|
|
|
|
SimulatorJNI.waitForProgramStart();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-29 10:10:01 -08:00
|
|
|
/**
|
|
|
|
|
* Sets flag that indicates if the user program has started.
|
|
|
|
|
*
|
|
|
|
|
* @param started true if started
|
|
|
|
|
*/
|
|
|
|
|
public static void setProgramStarted(boolean started) {
|
|
|
|
|
SimulatorJNI.setProgramStarted(started);
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
2024-01-05 07:35:59 -08:00
|
|
|
/**
|
|
|
|
|
* Returns true if the user program has started.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the user program has started.
|
|
|
|
|
*/
|
2020-07-04 00:44:37 -07:00
|
|
|
public static boolean getProgramStarted() {
|
|
|
|
|
return SimulatorJNI.getProgramStarted();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 21:25:57 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the user program state (control word).
|
|
|
|
|
*
|
|
|
|
|
* @param controlWord control word
|
|
|
|
|
*/
|
|
|
|
|
public static void setProgramState(ControlWord controlWord) {
|
|
|
|
|
SimulatorJNI.setProgramState(controlWord.getNative());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the user program state (control word).
|
|
|
|
|
*
|
|
|
|
|
* @param controlWord control word (output)
|
|
|
|
|
*/
|
|
|
|
|
public static void getProgramState(ControlWord controlWord) {
|
|
|
|
|
SimulatorJNI.getProgramState(controlWord);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/** Restart the simulator time. */
|
2018-05-11 12:38:23 -07:00
|
|
|
public static void restartTiming() {
|
|
|
|
|
SimulatorJNI.restartTiming();
|
|
|
|
|
}
|
2019-11-10 20:54:25 -08:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/** Pause the simulator time. */
|
2019-11-10 20:54:25 -08:00
|
|
|
public static void pauseTiming() {
|
|
|
|
|
SimulatorJNI.pauseTiming();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/** Resume the simulator time. */
|
2019-11-10 20:54:25 -08:00
|
|
|
public static void resumeTiming() {
|
|
|
|
|
SimulatorJNI.resumeTiming();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Check if the simulator time is paused.
|
|
|
|
|
*
|
|
|
|
|
* @return true if paused
|
|
|
|
|
*/
|
2019-11-10 20:54:25 -08:00
|
|
|
public static boolean isTimingPaused() {
|
|
|
|
|
return SimulatorJNI.isTimingPaused();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Advance the simulator time and wait for all notifiers to run.
|
|
|
|
|
*
|
2025-02-10 07:23:04 -08:00
|
|
|
* @param delta the amount to advance in seconds
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-02-10 07:23:04 -08:00
|
|
|
public static void stepTiming(double delta) {
|
|
|
|
|
SimulatorJNI.stepTiming((long) (delta * 1e6));
|
2019-11-10 20:54:25 -08:00
|
|
|
}
|
2020-09-27 13:27:53 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Advance the simulator time and return immediately.
|
|
|
|
|
*
|
2025-02-10 07:23:04 -08:00
|
|
|
* @param delta the amount to advance in seconds
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-02-10 07:23:04 -08:00
|
|
|
public static void stepTimingAsync(double delta) {
|
|
|
|
|
SimulatorJNI.stepTimingAsync((long) (delta * 1e6));
|
2020-09-27 13:27:53 -07:00
|
|
|
}
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|