MockDS
MockDS provides a simple internal UDP packet loop that WPILib created for use on the test bench. Studica modified the original code for VMX support.
MockDS Overview​
At the lowest level, MockDS uses a C++ real-time thread that runs in the background alongside the user code. The thread continuously sends a specific UDP message that either enables or disables the robot in autonomous mode. Depending on the user code project type, either the Studica C++ Lib or the Studica Java Lib accesses the thread.
While MockDS does not require a specific user hardware interface, such as a button, Studica recommends one. Use the start button to enable the robot, and use the e-stop to disable the robot. Prefer the e-stop because it latches.
With the layout of MockDS, if the user code gets bogged down or stuck, the robot will stay enabled. This can create a dangerous condition because the user may have no way to disable the robot.
Adding MockDS​
Add MockDS to the robot code by first upgrading Studica.json to version 2.0.0 or higher.
To Upgrade:
- Open the Command Palette in VS Code.
- Select: WPILib: Manage Vendor Libraries
- Select: Check for updates (online)
- Select: Studica.json
- Hit yes to build and cache the new library.
MockDS Code​
- Java
- C++
// Import the MockDS Library
import com.studica.frc.MockDS;
public class Robot extends TimedRobot
{
private MockDS ds; // Create the object
private boolean active = false; // active flag prevents calling mockds more than once.
@Override
public void robotInit()
{
ds = new MockDS(); // Create the instance
}
@Override
public void robotPeriodic()
{
// If the start button is pushed and the system is not active
if (!RobotContainer.driveTrain.getStartButton() && !active)
{
ds.enable(); // enable the robot.
active = true;
}
// If the e-stop is pushed and the system is active
if (!RobotContainer.driveTrain.getEStopButton() && active)
{
ds.disable(); // disable the robot.
active = false;
}
}
}
Header
#prama once
// Include the MockDS Library
#include "studica/MockDS.h"
class Robot : public frc::TimedRobot
{
private:
studica::MockDS ds; // Create the object and the instance
bool active; // Active flag prevents calling mockds more than once
};
Source
#include "Robot.h"
void Robot::RobotInit()
{
active = false; // System should be default disabled
}
void Robot::RobotPeriodic()
{
// If the start button is pushed and the system is not active
if (!m_container.drive.GetStartButton() && !active)
{
ds.Enable(); // enable the robot
active = true;
}
// If the e-stop is pushed and the system is active
if (!m_container.drive.GetEStopButton() && active)
{
active = false;
ds.Disable(); // disable the robot
}
}