MockDS
MockDS is a simple internal UDP packet loop that WPILib created for use on the test bench. We have modified its original code for use with the VMX.
MockDS Overview
MockDS’ lowest level is a C++ real-time thread that runs in the background with the user code. The thread runs a specific UDP message in a loop that will either enable or disable the robot in autonomous mode. Depending on the user code project type, the thread is accessed by either the Studica C++ Lib or the Studica Java Lib.
While a specific user hardware interface, such as a button, is not required, it is recommended. The start button is good for enabling the robot, while the e-stop is good for disabling the robot. The e-stop is preferred as it is latching.
Important
With the layout of MockDS, if the user code gets bogged down or stuck, the robot will stay enabled. This can be potentially dangerous as there will be no way to disable the robot if this happens.
Adding MockDS
MockDS can be added to the robot code by first upgrading the Studica.json to version 1.1.26 or higher.
To upgrade:
Open the Command Pallete in VSCode.
Select: WPILib: Manage Vendor Libraries
Select: Check for updates (online)
Select: Studica.json
Hit yes to build and cache the new library.
MockDS Code
1// Import the MockDS Library 2import com.studica.frc.MockDS; 3 4public class Robot extends TimedRobot 5{ 6 7 private MockDS ds; // Create the object 8 private boolean active = false; // active flag prevents calling mockds more than once. 9 10 @Override 11 public void robotInit() 12 { 13 ds = new MockDS(); // Create the instance 14 } 15 16 @Override 17 public void robotPeriodic() 18 { 19 // If the start button is pushed and the system is not active 20 if (!RobotContainer.driveTrain.getStartButton() && !active) 21 { 22 ds.enable(); // enable the robot. 23 active = true; 24 } 25 // If the e-stop is pushed and the system is active 26 if (!RobotContainer.driveTrain.getEStopButton() && active) 27 { 28 ds.disable(); // disable the robot. 29 active = false; 30 } 31 } 32}Header
1#prama once 2 3// Include the MockDS Library 4#include "studica/MockDS.h" 5 6class Robot : public frc::TimedRobot 7{ 8 private: 9 studica::MockDS ds; // Create the object and the instance 10 bool active; // Active flag prevents calling mockds more than once 11};Source
1#include "Robot.h" 2 3void Robot::RobotInit() 4{ 5 active = false; // System should be default disabled 6} 7 8void Robot::RobotPeriodic() 9{ 10 // If the start button is pushed and the system is not active 11 if (!m_container.drive.GetStartButton() && !active) 12 { 13 ds.Enable(); // enable the robot 14 active = true; 15 } 16 // If the e-stop is pushed and the system is active 17 if (!m_container.drive.GetEStopButton() && active) 18 { 19 active = false; 20 ds.Disable(); // disable the robot 21 } 22}