mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Rename SimDevice constants to all caps
Also use enum class for SimDevice C++ wrapper.
This commit is contained in:
@@ -19,11 +19,11 @@ public class SimDevice implements AutoCloseable {
|
||||
/** Sim device direction. */
|
||||
public enum Direction {
|
||||
/** Input direction for simulation devices. */
|
||||
kInput(SimDeviceJNI.kInput),
|
||||
INPUT(SimDeviceJNI.VALUE_INPUT),
|
||||
/** Output direction for simulation devices. */
|
||||
kOutput(SimDeviceJNI.kOutput),
|
||||
OUTPUT(SimDeviceJNI.VALUE_OUTPUT),
|
||||
/** Bidirectional direction for simulation devices. */
|
||||
kBidir(SimDeviceJNI.kBidir);
|
||||
BIDIR(SimDeviceJNI.VALUE_BIDIR);
|
||||
|
||||
/** The native value of this Direction. */
|
||||
public final int m_value;
|
||||
|
||||
@@ -11,13 +11,13 @@ package org.wpilib.hardware.hal;
|
||||
*/
|
||||
public class SimDeviceJNI extends JNIWrapper {
|
||||
/** Input to user code from the simulator. */
|
||||
public static final int kInput = 0;
|
||||
public static final int VALUE_INPUT = 0;
|
||||
|
||||
/** Output from user code to the simulator. */
|
||||
public static final int kOutput = 1;
|
||||
public static final int VALUE_OUTPUT = 1;
|
||||
|
||||
/** Bidirectional between user code and simulator. */
|
||||
public static final int kBidir = 2;
|
||||
public static final int VALUE_BIDIR = 2;
|
||||
|
||||
/**
|
||||
* Creates a simulated device.
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
* Direction of a simulated value (from the perspective of user code).
|
||||
*/
|
||||
HAL_ENUM(HAL_SimValueDirection) {
|
||||
HAL_SimValueInput = 0, /**< input to user code from the simulator */
|
||||
HAL_SimValueOutput, /**< output from user code to the simulator */
|
||||
HAL_SimValueBidir /**< bidirectional between user code and simulator */
|
||||
HAL_SIM_VALUE_INPUT = 0, /**< input to user code from the simulator */
|
||||
HAL_SIM_VALUE_OUTPUT, /**< output from user code to the simulator */
|
||||
HAL_SIM_VALUE_BIDIR /**< bidirectional between user code and simulator */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -280,10 +280,10 @@ class SimDevice {
|
||||
/**
|
||||
* Direction of a simulated value (from the perspective of user code).
|
||||
*/
|
||||
enum Direction {
|
||||
kInput = HAL_SimValueInput,
|
||||
kOutput = HAL_SimValueOutput,
|
||||
kBidir = HAL_SimValueBidir
|
||||
enum class Direction {
|
||||
INPUT = HAL_SIM_VALUE_INPUT,
|
||||
OUTPUT = HAL_SIM_VALUE_OUTPUT,
|
||||
BIDIR = HAL_SIM_VALUE_BIDIR
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -403,9 +403,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated value object
|
||||
*/
|
||||
SimValue CreateValue(const char* name, int32_t direction,
|
||||
SimValue CreateValue(const char* name, Direction direction,
|
||||
const HAL_Value& initialValue) {
|
||||
return HAL_CreateSimValue(m_handle, name, direction, &initialValue);
|
||||
return HAL_CreateSimValue(m_handle, name, static_cast<int32_t>(direction),
|
||||
&initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,8 +420,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimInt CreateInt(const char* name, int32_t direction, int32_t initialValue) {
|
||||
return HAL_CreateSimValueInt(m_handle, name, direction, initialValue);
|
||||
SimInt CreateInt(const char* name, Direction direction,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueInt(m_handle, name,
|
||||
static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,9 +437,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimLong CreateLong(const char* name, int32_t direction,
|
||||
SimLong CreateLong(const char* name, Direction direction,
|
||||
int64_t initialValue) {
|
||||
return HAL_CreateSimValueLong(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueLong(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,9 +454,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimDouble CreateDouble(const char* name, int32_t direction,
|
||||
SimDouble CreateDouble(const char* name, Direction direction,
|
||||
double initialValue) {
|
||||
return HAL_CreateSimValueDouble(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueDouble(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,12 +474,12 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnum(const char* name, int32_t direction,
|
||||
SimEnum CreateEnum(const char* name, Direction direction,
|
||||
std::initializer_list<const char*> options,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
|
||||
const_cast<const char**>(options.begin()),
|
||||
initialValue);
|
||||
return HAL_CreateSimValueEnum(
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.begin()), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,12 +496,12 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnum(const char* name, int32_t direction,
|
||||
SimEnum CreateEnum(const char* name, Direction direction,
|
||||
std::span<const char* const> options,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
|
||||
const_cast<const char**>(options.data()),
|
||||
initialValue);
|
||||
return HAL_CreateSimValueEnum(
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.data()), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +520,7 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnumDouble(const char* name, int32_t direction,
|
||||
SimEnum CreateEnumDouble(const char* name, Direction direction,
|
||||
std::initializer_list<const char*> options,
|
||||
std::initializer_list<double> optionValues,
|
||||
int32_t initialValue) {
|
||||
@@ -523,7 +528,7 @@ class SimDevice {
|
||||
return {};
|
||||
}
|
||||
return HAL_CreateSimValueEnumDouble(
|
||||
m_handle, name, direction, options.size(),
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.begin()), optionValues.begin(),
|
||||
initialValue);
|
||||
}
|
||||
@@ -544,7 +549,7 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnumDouble(const char* name, int32_t direction,
|
||||
SimEnum CreateEnumDouble(const char* name, Direction direction,
|
||||
std::span<const char* const> options,
|
||||
std::span<const double> optionValues,
|
||||
int32_t initialValue) {
|
||||
@@ -552,7 +557,7 @@ class SimDevice {
|
||||
return {};
|
||||
}
|
||||
return HAL_CreateSimValueEnumDouble(
|
||||
m_handle, name, direction, options.size(),
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.data()), optionValues.data(),
|
||||
initialValue);
|
||||
}
|
||||
@@ -568,9 +573,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated boolean value object
|
||||
*/
|
||||
SimBoolean CreateBoolean(const char* name, int32_t direction,
|
||||
SimBoolean CreateBoolean(const char* name, Direction direction,
|
||||
bool initialValue) {
|
||||
return HAL_CreateSimValueBoolean(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueBoolean(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -148,11 +148,11 @@ classes:
|
||||
CreateDouble:
|
||||
CreateEnum:
|
||||
overloads:
|
||||
const char*, int32_t, std::initializer_list<const char *>, int32_t:
|
||||
const char*, Direction, std::initializer_list<const char *>, int32_t:
|
||||
ignore: true
|
||||
const char*, int32_t, std::span<const char * const>, int32_t:
|
||||
const char*, Direction, std::span<const char * const>, int32_t:
|
||||
cpp_code: |
|
||||
[](SimDevice &self, const char * name, int32_t direction, const wpi::util::SmallVector<std::string, 8> &options, int32_t initialValue) {
|
||||
[](SimDevice &self, const char * name, SimDevice::Direction direction, const wpi::util::SmallVector<std::string, 8> &options, int32_t initialValue) {
|
||||
wpi::util::SmallVector<const char *, 8> coptions;
|
||||
coptions.reserve(options.size());
|
||||
for (auto &s: options) {
|
||||
@@ -163,11 +163,11 @@ classes:
|
||||
|
||||
CreateEnumDouble:
|
||||
overloads:
|
||||
const char*, int32_t, std::initializer_list<const char *>, std::initializer_list<double>, int32_t:
|
||||
const char*, Direction, std::initializer_list<const char *>, std::initializer_list<double>, int32_t:
|
||||
ignore: true
|
||||
const char*, int32_t, std::span<const char * const>, std::span<const double>, int32_t:
|
||||
const char*, Direction, std::span<const char * const>, std::span<const double>, int32_t:
|
||||
cpp_code: |
|
||||
[](SimDevice &self, const char * name, int32_t direction, const wpi::util::SmallVector<std::string, 8> &options, const wpi::util::SmallVector<double, 8> &optionValues, int32_t initialValue) {
|
||||
[](SimDevice &self, const char * name, SimDevice::Direction direction, const wpi::util::SmallVector<std::string, 8> &options, const wpi::util::SmallVector<double, 8> &optionValues, int32_t initialValue) {
|
||||
wpi::util::SmallVector<const char *, 8> coptions;
|
||||
coptions.reserve(options.size());
|
||||
for (auto &s: options) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import hal
|
||||
|
||||
def test_hal_simdevice():
|
||||
device = hal.SimDevice("deviceName")
|
||||
v = device.createInt("i", 0, 1)
|
||||
v = device.createInt("i", hal.SimDevice.Direction.INPUT, 1)
|
||||
assert v.get() == 1
|
||||
assert v.type == hal.Type.INT
|
||||
|
||||
@@ -14,7 +14,7 @@ def test_hal_simdevice():
|
||||
def test_hal_simdevice_enum():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
v = device.createEnum("e", 0, names, 0)
|
||||
v = device.createEnum("e", hal.SimDevice.Direction.INPUT, names, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
@@ -28,7 +28,7 @@ def test_hal_simdevice_enum_double():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
values = [0.0, 1.0, 2.0]
|
||||
v = device.createEnumDouble("e", 0, names, values, 0)
|
||||
v = device.createEnumDouble("e", hal.SimDevice.Direction.INPUT, names, values, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_value_changed_callback():
|
||||
devunused = hal.simulation.registerSimValueCreatedCallback(dev, created_cb, True)
|
||||
assert recv is None
|
||||
|
||||
val = dev.createInt("answer", 0, 42)
|
||||
val = dev.createInt("answer", hal.SimDevice.Direction.INPUT, 42)
|
||||
|
||||
assert recv == (True, "answer", 42)
|
||||
recv = None
|
||||
|
||||
@@ -31,14 +31,14 @@ public class RomiGyro {
|
||||
public RomiGyro() {
|
||||
m_simDevice = SimDevice.create("Gyro:RomiGyro");
|
||||
if (m_simDevice != null) {
|
||||
m_simDevice.createBoolean("init", Direction.kOutput, true);
|
||||
m_simRateX = m_simDevice.createDouble("rate_x", Direction.kInput, 0.0);
|
||||
m_simRateY = m_simDevice.createDouble("rate_y", Direction.kInput, 0.0);
|
||||
m_simRateZ = m_simDevice.createDouble("rate_z", Direction.kInput, 0.0);
|
||||
m_simDevice.createBoolean("init", Direction.OUTPUT, true);
|
||||
m_simRateX = m_simDevice.createDouble("rate_x", Direction.INPUT, 0.0);
|
||||
m_simRateY = m_simDevice.createDouble("rate_y", Direction.INPUT, 0.0);
|
||||
m_simRateZ = m_simDevice.createDouble("rate_z", Direction.INPUT, 0.0);
|
||||
|
||||
m_simAngleX = m_simDevice.createDouble("angle_x", Direction.kInput, 0.0);
|
||||
m_simAngleY = m_simDevice.createDouble("angle_y", Direction.kInput, 0.0);
|
||||
m_simAngleZ = m_simDevice.createDouble("angle_z", Direction.kInput, 0.0);
|
||||
m_simAngleX = m_simDevice.createDouble("angle_x", Direction.INPUT, 0.0);
|
||||
m_simAngleY = m_simDevice.createDouble("angle_y", Direction.INPUT, 0.0);
|
||||
m_simAngleZ = m_simDevice.createDouble("angle_z", Direction.INPUT, 0.0);
|
||||
} else {
|
||||
m_simRateX = null;
|
||||
m_simRateY = null;
|
||||
|
||||
@@ -8,19 +8,19 @@ using namespace wpi::romi;
|
||||
|
||||
RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") {
|
||||
if (m_simDevice) {
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
|
||||
m_simRateX =
|
||||
m_simDevice.CreateDouble("rate_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateY =
|
||||
m_simDevice.CreateDouble("rate_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateZ =
|
||||
m_simDevice.CreateDouble("rate_z", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleX =
|
||||
m_simDevice.CreateDouble("angle_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleY =
|
||||
m_simDevice.CreateDouble("angle_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleZ =
|
||||
m_simDevice.CreateDouble("angle_z", hal::SimDevice::kInput, 0.0);
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::Direction::OUTPUT, true);
|
||||
m_simRateX = m_simDevice.CreateDouble(
|
||||
"rate_x", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simRateY = m_simDevice.CreateDouble(
|
||||
"rate_y", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simRateZ = m_simDevice.CreateDouble(
|
||||
"rate_z", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleX = m_simDevice.CreateDouble(
|
||||
"angle_x", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleY = m_simDevice.CreateDouble(
|
||||
"angle_y", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleZ = m_simDevice.CreateDouble(
|
||||
"angle_z", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ static void DisplaySimValue(const char* name, void* data,
|
||||
switch (value->type) {
|
||||
case HAL_BOOLEAN: {
|
||||
bool v = value->data.v_boolean;
|
||||
if (wpi::glass::DeviceBoolean(name, direction == HAL_SimValueOutput, &v,
|
||||
if (wpi::glass::DeviceBoolean(name, direction == HAL_SIM_VALUE_OUTPUT, &v,
|
||||
model->GetSource(handle))) {
|
||||
valueCopy.data.v_boolean = v ? 1 : 0;
|
||||
HAL_SetSimValue(handle, valueCopy);
|
||||
@@ -159,7 +159,7 @@ static void DisplaySimValue(const char* name, void* data,
|
||||
break;
|
||||
}
|
||||
case HAL_DOUBLE:
|
||||
if (wpi::glass::DeviceDouble(name, direction == HAL_SimValueOutput,
|
||||
if (wpi::glass::DeviceDouble(name, direction == HAL_SIM_VALUE_OUTPUT,
|
||||
&valueCopy.data.v_double,
|
||||
model->GetSource(handle))) {
|
||||
HAL_SetSimValue(handle, valueCopy);
|
||||
@@ -168,7 +168,7 @@ static void DisplaySimValue(const char* name, void* data,
|
||||
case HAL_ENUM: {
|
||||
int32_t numOptions = 0;
|
||||
const char** options = HALSIM_GetSimValueEnumOptions(handle, &numOptions);
|
||||
if (wpi::glass::DeviceEnum(name, direction == HAL_SimValueOutput,
|
||||
if (wpi::glass::DeviceEnum(name, direction == HAL_SIM_VALUE_OUTPUT,
|
||||
&valueCopy.data.v_enum, options, numOptions,
|
||||
model->GetSource(handle))) {
|
||||
HAL_SetSimValue(handle, valueCopy);
|
||||
@@ -176,14 +176,14 @@ static void DisplaySimValue(const char* name, void* data,
|
||||
break;
|
||||
}
|
||||
case HAL_INT:
|
||||
if (wpi::glass::DeviceInt(name, direction == HAL_SimValueOutput,
|
||||
if (wpi::glass::DeviceInt(name, direction == HAL_SIM_VALUE_OUTPUT,
|
||||
&valueCopy.data.v_int,
|
||||
model->GetSource(handle))) {
|
||||
HAL_SetSimValue(handle, valueCopy);
|
||||
}
|
||||
break;
|
||||
case HAL_LONG:
|
||||
if (wpi::glass::DeviceLong(name, direction == HAL_SimValueOutput,
|
||||
if (wpi::glass::DeviceLong(name, direction == HAL_SIM_VALUE_OUTPUT,
|
||||
&valueCopy.data.v_long,
|
||||
model->GetSource(handle))) {
|
||||
HAL_SetSimValue(handle, valueCopy);
|
||||
|
||||
@@ -133,13 +133,13 @@ void HALSimWSProviderSimDevice::OnValueCreated(const char* name,
|
||||
const char* prefix = "";
|
||||
if (name[0] != '<' && name[0] != '>') {
|
||||
switch (direction) {
|
||||
case HAL_SimValueInput:
|
||||
case HAL_SIM_VALUE_INPUT:
|
||||
prefix = ">";
|
||||
break;
|
||||
case HAL_SimValueOutput:
|
||||
case HAL_SIM_VALUE_OUTPUT:
|
||||
prefix = "<";
|
||||
break;
|
||||
case HAL_SimValueBidir:
|
||||
case HAL_SIM_VALUE_BIDIR:
|
||||
prefix = "<>";
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -16,11 +16,14 @@ ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
|
||||
m_simDevice("Accel:ADXL345_I2C", static_cast<int>(port), deviceAddress) {
|
||||
if (m_simDevice) {
|
||||
m_simRange = m_simDevice.CreateEnumDouble(
|
||||
"range", wpi::hal::SimDevice::kOutput, {"2G", "4G", "8G", "16G"},
|
||||
{2.0, 4.0, 8.0, 16.0}, 0);
|
||||
m_simX = m_simDevice.CreateDouble("x", wpi::hal::SimDevice::kInput, 0.0);
|
||||
m_simY = m_simDevice.CreateDouble("y", wpi::hal::SimDevice::kInput, 0.0);
|
||||
m_simZ = m_simDevice.CreateDouble("z", wpi::hal::SimDevice::kInput, 0.0);
|
||||
"range", wpi::hal::SimDevice::Direction::OUTPUT,
|
||||
{"2G", "4G", "8G", "16G"}, {2.0, 4.0, 8.0, 16.0}, 0);
|
||||
m_simX = m_simDevice.CreateDouble(
|
||||
"x", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simY = m_simDevice.CreateDouble(
|
||||
"y", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simZ = m_simDevice.CreateDouble(
|
||||
"z", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
}
|
||||
// Turn on the measurements
|
||||
m_i2c.Write(kPowerCtlRegister, kPowerCtl_Measure);
|
||||
|
||||
@@ -89,7 +89,8 @@ PWMMotorController::PWMMotorController(std::string_view name, int channel)
|
||||
|
||||
m_simDevice = wpi::hal::SimDevice{"PWMMotorController", channel};
|
||||
if (m_simDevice) {
|
||||
m_simDutyCycle = m_simDevice.CreateDouble("DutyCycle", true, 0.0);
|
||||
m_simDutyCycle = m_simDevice.CreateDouble(
|
||||
"DutyCycle", wpi::hal::SimDevice::Direction::OUTPUT, 0.0);
|
||||
m_pwm.SetSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ SharpIR::SharpIR(int channel, double a, double b, wpi::units::meter_t min,
|
||||
|
||||
m_simDevice = wpi::hal::SimDevice("SharpIR", m_sensor.GetChannel());
|
||||
if (m_simDevice) {
|
||||
m_simRange = m_simDevice.CreateDouble("Range (m)", false, 0.0);
|
||||
m_simRange = m_simDevice.CreateDouble(
|
||||
"Range (m)", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_sensor.SetSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ void AnalogEncoder::Init(double fullRange, double expectedZero) {
|
||||
wpi::hal::SimDevice{"AnalogEncoder", m_analogInput->GetChannel()};
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
|
||||
m_simPosition = m_simDevice.CreateDouble(
|
||||
"Position", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
}
|
||||
|
||||
m_fullRange = fullRange;
|
||||
|
||||
@@ -64,9 +64,10 @@ void DutyCycleEncoder::Init(double fullRange, double expectedZero) {
|
||||
m_dutyCycle->GetSourceChannel()};
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
|
||||
m_simPosition = m_simDevice.CreateDouble(
|
||||
"Position", wpi::hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simIsConnected = m_simDevice.CreateBoolean(
|
||||
"Connected", wpi::hal::SimDevice::kInput, true);
|
||||
"Connected", wpi::hal::SimDevice::Direction::INPUT, true);
|
||||
}
|
||||
|
||||
m_fullRange = fullRange;
|
||||
|
||||
@@ -14,7 +14,8 @@ using namespace wpi::sim;
|
||||
|
||||
TEST(SimDeviceSimTest, Basic) {
|
||||
wpi::hal::SimDevice dev{"test"};
|
||||
wpi::hal::SimBoolean devBool = dev.CreateBoolean("bool", false, false);
|
||||
wpi::hal::SimBoolean devBool =
|
||||
dev.CreateBoolean("bool", wpi::hal::SimDevice::Direction::INPUT, false);
|
||||
|
||||
SimDeviceSim sim{"test"};
|
||||
wpi::hal::SimBoolean simBool = sim.GetBoolean("bool");
|
||||
|
||||
@@ -119,13 +119,13 @@ public class ADXL345_I2C implements NTSendable, AutoCloseable {
|
||||
m_simRange =
|
||||
m_simDevice.createEnumDouble(
|
||||
"range",
|
||||
SimDevice.Direction.kOutput,
|
||||
SimDevice.Direction.OUTPUT,
|
||||
new String[] {"2G", "4G", "8G", "16G"},
|
||||
new double[] {2.0, 4.0, 8.0, 16.0},
|
||||
0);
|
||||
m_simX = m_simDevice.createDouble("x", SimDevice.Direction.kInput, 0.0);
|
||||
m_simY = m_simDevice.createDouble("y", SimDevice.Direction.kInput, 0.0);
|
||||
m_simZ = m_simDevice.createDouble("z", SimDevice.Direction.kInput, 0.0);
|
||||
m_simX = m_simDevice.createDouble("x", SimDevice.Direction.INPUT, 0.0);
|
||||
m_simY = m_simDevice.createDouble("y", SimDevice.Direction.INPUT, 0.0);
|
||||
m_simZ = m_simDevice.createDouble("z", SimDevice.Direction.INPUT, 0.0);
|
||||
}
|
||||
|
||||
// Turn on the measurements
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
|
||||
m_simDevice = SimDevice.create("PWMMotorController", channel);
|
||||
if (m_simDevice != null) {
|
||||
m_simDutyCycle = m_simDevice.createDouble("DutyCycle", Direction.kOutput, 0.0);
|
||||
m_simDutyCycle = m_simDevice.createDouble("DutyCycle", Direction.OUTPUT, 0.0);
|
||||
m_pwm.setSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class SharpIR implements Sendable, AutoCloseable {
|
||||
|
||||
m_simDevice = SimDevice.create("SharpIR", m_sensor.getChannel());
|
||||
if (m_simDevice != null) {
|
||||
m_simRange = m_simDevice.createDouble("Range (m)", Direction.kInput, 0.0);
|
||||
m_simRange = m_simDevice.createDouble("Range (m)", Direction.INPUT, 0.0);
|
||||
m_sensor.setSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class AnalogEncoder implements Sendable, AutoCloseable {
|
||||
m_simDevice = SimDevice.create("AnalogEncoder", m_analogInput.getChannel());
|
||||
|
||||
if (m_simDevice != null) {
|
||||
m_simPosition = m_simDevice.createDouble("Position", Direction.kInput, 0.0);
|
||||
m_simPosition = m_simDevice.createDouble("Position", Direction.INPUT, 0.0);
|
||||
}
|
||||
|
||||
m_fullRange = fullRange;
|
||||
|
||||
@@ -86,8 +86,8 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
m_simDevice = SimDevice.create("DutyCycle:DutyCycleEncoder", m_dutyCycle.getSourceChannel());
|
||||
|
||||
if (m_simDevice != null) {
|
||||
m_simPosition = m_simDevice.createDouble("Position", SimDevice.Direction.kInput, 0.0);
|
||||
m_simIsConnected = m_simDevice.createBoolean("Connected", SimDevice.Direction.kInput, true);
|
||||
m_simPosition = m_simDevice.createDouble("Position", SimDevice.Direction.INPUT, 0.0);
|
||||
m_simIsConnected = m_simDevice.createBoolean("Connected", SimDevice.Direction.INPUT, true);
|
||||
}
|
||||
|
||||
m_fullRange = fullRange;
|
||||
|
||||
@@ -19,7 +19,7 @@ class SimDeviceSimTest {
|
||||
@Test
|
||||
void testBasic() {
|
||||
try (SimDevice dev = SimDevice.create("test")) {
|
||||
SimBoolean devBool = dev.createBoolean("bool", Direction.kBidir, false);
|
||||
SimBoolean devBool = dev.createBoolean("bool", Direction.BIDIR, false);
|
||||
|
||||
SimDeviceSim sim = new SimDeviceSim("test");
|
||||
SimBoolean simBool = sim.getBoolean("bool");
|
||||
@@ -92,7 +92,7 @@ class SimDeviceSimTest {
|
||||
AtomicInteger callback2Counter = new AtomicInteger(0);
|
||||
|
||||
try (SimDevice dev1 = SimDevice.create("testVM1")) {
|
||||
dev1.createBoolean("v1", Direction.kBidir, false);
|
||||
dev1.createBoolean("v1", Direction.BIDIR, false);
|
||||
SimDeviceSim sim = new SimDeviceSim("testVM1");
|
||||
try (CallbackStore callback1 =
|
||||
sim.registerValueCreatedCallback(
|
||||
@@ -106,13 +106,13 @@ class SimDeviceSimTest {
|
||||
callback2Counter.get(),
|
||||
"Callback 2 called early or not initialized with existing devices");
|
||||
|
||||
dev1.createDouble("v2", Direction.kBidir, 0);
|
||||
dev1.createDouble("v2", Direction.BIDIR, 0);
|
||||
|
||||
assertEquals(
|
||||
1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
|
||||
assertEquals(2, callback2Counter.get(), "Callback 2 called either more or less than twice");
|
||||
}
|
||||
dev1.createBoolean("v3", Direction.kBidir, false);
|
||||
dev1.createBoolean("v3", Direction.BIDIR, false);
|
||||
|
||||
assertEquals(1, callback1Counter.get(), "Callback 1 called after closure");
|
||||
assertEquals(2, callback2Counter.get(), "Callback 2 called after closure");
|
||||
@@ -125,7 +125,7 @@ class SimDeviceSimTest {
|
||||
AtomicInteger callback2Counter = new AtomicInteger(0);
|
||||
|
||||
try (SimDevice dev1 = SimDevice.create("testVM1")) {
|
||||
SimBoolean val = dev1.createBoolean("v1", Direction.kBidir, false);
|
||||
SimBoolean val = dev1.createBoolean("v1", Direction.BIDIR, false);
|
||||
SimDeviceSim sim = new SimDeviceSim("testVM1");
|
||||
SimValue simVal = sim.getValue("v1");
|
||||
try (CallbackStore callback1 =
|
||||
|
||||
@@ -36,14 +36,14 @@ public class XRPGyro {
|
||||
public XRPGyro() {
|
||||
m_simDevice = SimDevice.create("Gyro:XRPGyro");
|
||||
if (m_simDevice != null) {
|
||||
m_simDevice.createBoolean("init", Direction.kOutput, true);
|
||||
m_simRateX = m_simDevice.createDouble("rate_x", Direction.kInput, 0.0);
|
||||
m_simRateY = m_simDevice.createDouble("rate_y", Direction.kInput, 0.0);
|
||||
m_simRateZ = m_simDevice.createDouble("rate_z", Direction.kInput, 0.0);
|
||||
m_simDevice.createBoolean("init", Direction.OUTPUT, true);
|
||||
m_simRateX = m_simDevice.createDouble("rate_x", Direction.INPUT, 0.0);
|
||||
m_simRateY = m_simDevice.createDouble("rate_y", Direction.INPUT, 0.0);
|
||||
m_simRateZ = m_simDevice.createDouble("rate_z", Direction.INPUT, 0.0);
|
||||
|
||||
m_simAngleX = m_simDevice.createDouble("angle_x", Direction.kInput, 0.0);
|
||||
m_simAngleY = m_simDevice.createDouble("angle_y", Direction.kInput, 0.0);
|
||||
m_simAngleZ = m_simDevice.createDouble("angle_z", Direction.kInput, 0.0);
|
||||
m_simAngleX = m_simDevice.createDouble("angle_x", Direction.INPUT, 0.0);
|
||||
m_simAngleY = m_simDevice.createDouble("angle_y", Direction.INPUT, 0.0);
|
||||
m_simAngleZ = m_simDevice.createDouble("angle_z", Direction.INPUT, 0.0);
|
||||
} else {
|
||||
m_simRateX = null;
|
||||
m_simRateY = null;
|
||||
|
||||
@@ -57,9 +57,9 @@ public class XRPMotor implements MotorController {
|
||||
SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName);
|
||||
|
||||
if (xrpMotorSimDevice != null) {
|
||||
xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true);
|
||||
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false);
|
||||
m_simVelocity = xrpMotorSimDevice.createDouble("velocity", Direction.kOutput, 0.0);
|
||||
xrpMotorSimDevice.createBoolean("init", Direction.OUTPUT, true);
|
||||
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.INPUT, false);
|
||||
m_simVelocity = xrpMotorSimDevice.createDouble("velocity", Direction.OUTPUT, 0.0);
|
||||
} else {
|
||||
m_simInverted = null;
|
||||
m_simVelocity = null;
|
||||
|
||||
@@ -53,9 +53,9 @@ public class XRPServo {
|
||||
SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName);
|
||||
|
||||
if (xrpServoSimDevice != null) {
|
||||
xrpServoSimDevice.createBoolean("init", Direction.kOutput, true);
|
||||
xrpServoSimDevice.createBoolean("init", Direction.OUTPUT, true);
|
||||
// This should mimic PWM position [0.0, 1.0]
|
||||
m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5);
|
||||
m_simPosition = xrpServoSimDevice.createDouble("position", Direction.OUTPUT, 0.5);
|
||||
} else {
|
||||
m_simPosition = null;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ using namespace wpi::xrp;
|
||||
|
||||
XRPGyro::XRPGyro() : m_simDevice("Gyro:XRPGyro") {
|
||||
if (m_simDevice) {
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
|
||||
m_simRateX =
|
||||
m_simDevice.CreateDouble("rate_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateY =
|
||||
m_simDevice.CreateDouble("rate_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateZ =
|
||||
m_simDevice.CreateDouble("rate_z", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleX =
|
||||
m_simDevice.CreateDouble("angle_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleY =
|
||||
m_simDevice.CreateDouble("angle_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleZ =
|
||||
m_simDevice.CreateDouble("angle_z", hal::SimDevice::kInput, 0.0);
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::Direction::OUTPUT, true);
|
||||
m_simRateX = m_simDevice.CreateDouble(
|
||||
"rate_x", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simRateY = m_simDevice.CreateDouble(
|
||||
"rate_y", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simRateZ = m_simDevice.CreateDouble(
|
||||
"rate_z", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleX = m_simDevice.CreateDouble(
|
||||
"angle_x", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleY = m_simDevice.CreateDouble(
|
||||
"angle_y", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
m_simAngleZ = m_simDevice.CreateDouble(
|
||||
"angle_z", hal::SimDevice::Direction::INPUT, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ XRPMotor::XRPMotor(int deviceNum) {
|
||||
m_simDevice = hal::SimDevice(m_deviceName.c_str());
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
|
||||
m_simInverted =
|
||||
m_simDevice.CreateBoolean("inverted", hal::SimDevice::kInput, false);
|
||||
m_simVelocity =
|
||||
m_simDevice.CreateDouble("velocity", hal::SimDevice::kOutput, 0.0);
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::Direction::OUTPUT, true);
|
||||
m_simInverted = m_simDevice.CreateBoolean(
|
||||
"inverted", hal::SimDevice::Direction::INPUT, false);
|
||||
m_simVelocity = m_simDevice.CreateDouble(
|
||||
"velocity", hal::SimDevice::Direction::OUTPUT, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ XRPServo::XRPServo(int deviceNum) {
|
||||
m_simDevice = hal::SimDevice(m_deviceName.c_str());
|
||||
|
||||
if (m_simDevice) {
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
|
||||
m_simPosition =
|
||||
m_simDevice.CreateDouble("position", hal::SimDevice::kOutput, 0.5);
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::Direction::OUTPUT, true);
|
||||
m_simPosition = m_simDevice.CreateDouble(
|
||||
"position", hal::SimDevice::Direction::OUTPUT, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user