Adds JNI Simulator interface and updated Sim API (#1002)

The simulator was generated by https://github.com/ThadHouse/SimulatorGenerator
This commit is contained in:
Thad House
2018-05-11 12:38:23 -07:00
committed by Peter Johnson
parent 1046371349
commit 337e89cf6e
96 changed files with 8204 additions and 26 deletions

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.sim;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.hal.HAL;
public class AnalogInputSimTest {
static class DoubleStore {
public boolean wasTriggered = false;
public boolean wasCorrectType = false;
public double setValue = 0;
}
@Test
public void testSetCallback() {
HAL.initialize(500, 0);
AnalogInput input = new AnalogInput(5);
AnalogInSim inputSim = input.getSimObject();
for (double i = 0; i < 5.0; i+=0.1) {
inputSim.setVoltage(0);
assertEquals(input.getVoltage(), 0, 0.001);
inputSim.setVoltage(i);
assertEquals(input.getVoltage(), i, 0.001);
}
}
}

View File

@@ -0,0 +1,69 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.sim;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import edu.wpi.first.wpilibj.AnalogOutput;
import edu.wpi.first.wpilibj.hal.HAL;
public class AnalogOutputSimTest {
static class DoubleStore {
public boolean wasTriggered = false;
public boolean wasCorrectType = false;
public double setValue = -1;
public void reset() {
wasCorrectType = false;
wasTriggered = false;
setValue = -1;
}
}
@Test
public void testSetCallback() {
HAL.initialize(500, 0);
AnalogOutput output = new AnalogOutput(0);
output.setVoltage(0.5);
AnalogOutSim outputSim = output.getSimObject();
DoubleStore store = new DoubleStore();
try (CallbackStore cb = outputSim.registerVoltageCallback((s, v) -> {
store.wasTriggered = true;
store.wasCorrectType = true;
store.setValue = v.getDouble();
}, false)) {
assertFalse(store.wasTriggered);
for (double i = 0.1; i < 5.0; i+=0.1) {
store.reset();
output.setVoltage(0);
assertTrue(store.wasTriggered);
assertEquals(store.setValue, 0, 0.001);
store.reset();
output.setVoltage(i);
assertTrue(store.wasTriggered);
assertEquals(store.setValue, i, 0.001);
}
}
}
}