Navx MXP Gyro Simulation in Java

Trying to simulate a Navx gyro and am not having any luck even though the documentation here Java | navX-MXP

states that it is possible.

How do I create the simulation gyro in Java code?

From the documentation:

int dev = SimDeviceDataJNI.getSimDeviceHandle(“navX-Sensor[0]”);
SimDouble angle = new SimDouble(SimDeviceDataJNI.getSimValueHandle(dev, “Yaw”));

so your simulationPeriodic would look something like:

public void simulationPeriodic() {
  // Set the inputs to the system. Note that we need to convert
  // the [-1, 1] PWM signal to voltage by multiplying it by the
  // robot controller voltage.
  m_driveSim.setInputs(m_leftMotor.get() * RobotController.getInputVoltage(),
                       m_rightMotor.get() * RobotController.getInputVoltage());

  // Advance the model by 20 ms. Note that if you are running this
  // subsystem in a separate thread or have changed the nominal timestep
  // of TimedRobot, this value needs to match it.

  // Update all of our sensors.
  int dev = SimDeviceDataJNI.getSimDeviceHandle(“navX-Sensor[0]”);
  SimDouble gyroSimAngle = new SimDouble(SimDeviceDataJNI.getSimValueHandle(dev, “Yaw”));

I think you could also have gyroSimAngle as a global variable in your drive class so you are not redeclaring it every time

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.