[examples] Make Romi/XRP Examples use appropriate vendordeps (#5665)

This commit is contained in:
Zhiquan Yeo
2023-09-18 22:42:10 -04:00
committed by GitHub
parent daf7702007
commit 51dcb8b55a
33 changed files with 74 additions and 1693 deletions

View File

@@ -90,7 +90,10 @@
"foldername": "romicommandbased",
"gradlebase": "javaromi",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"romi"
]
},
{
"name": "Romi - Timed Robot",
@@ -102,7 +105,10 @@
"foldername": "romitimed",
"gradlebase": "javaromi",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"romi"
]
},
{
"name": "XRP - Command Robot",
@@ -114,7 +120,10 @@
"foldername": "xrpcommandbased",
"gradlebase": "javaxrp",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"xrp"
]
},
{
"name": "XRP - Timed Robot",
@@ -126,7 +135,10 @@
"foldername": "xrptimed",
"gradlebase": "javaxrp",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"xrp"
]
},
{
"name": "Educational Robot",
@@ -149,7 +161,10 @@
"foldername": "romieducational",
"gradlebase": "javaromi",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"romi"
]
},
{
"name": "XRP - Educational Robot",
@@ -161,6 +176,9 @@
"foldername": "xrpeducational",
"gradlebase": "javaxrp",
"mainclass": "Main",
"commandversion": 2
"commandversion": 2,
"extravendordeps": [
"xrp"
]
}
]

View File

@@ -1,109 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrpcommandbased.devices;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPMotor.
*
* <p>A SimDevice based motor controller representing the motors on an XRP robot
*/
public class XRPMotor implements MotorController {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(0, "motorL");
s_simDeviceNameMap.put(1, "motorR");
s_simDeviceNameMap.put(2, "motor3");
s_simDeviceNameMap.put(3, "motor4");
}
private final SimDouble m_simSpeed;
private final SimBoolean m_simInverted;
/** XRPMotor. */
public XRPMotor(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on the WS messages as type: "XRPMotor", device: <motor name>
String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName);
if (xrpMotorSimDevice != null) {
xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true);
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false);
m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0);
} else {
m_simInverted = null;
m_simSpeed = null;
}
}
@Override
public void set(double speed) {
if (m_simSpeed != null) {
boolean invert = false;
if (m_simInverted != null) {
invert = m_simInverted.get();
}
m_simSpeed.set(invert ? -speed : speed);
}
}
@Override
public double get() {
if (m_simSpeed != null) {
return m_simSpeed.get();
}
return 0.0;
}
@Override
public void setInverted(boolean isInverted) {
if (m_simInverted != null) {
m_simInverted.set(isInverted);
}
}
@Override
public boolean getInverted() {
if (m_simInverted != null) {
return m_simInverted.get();
}
return false;
}
@Override
public void disable() {
set(0.0);
}
@Override
public void stopMotor() {
set(0.0);
}
}

View File

@@ -1,123 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrpcommandbased.devices;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPServo.
*
* <p>A SimDevice based servo
*/
public class XRPServo {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(4, "servo1");
s_simDeviceNameMap.put(5, "servo2");
}
private final SimDouble m_simPosition;
/** XRPServo. */
public XRPServo(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on WS as type: "XRPServo", device: <servo name>
String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName);
if (xrpServoSimDevice != null) {
xrpServoSimDevice.createBoolean("init", Direction.kOutput, true);
// This should mimic PWM position [0.0, 1.0]
m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5);
} else {
m_simPosition = null;
}
}
/**
* Set the servo angle.
*
* @param angle Desired angle in degrees
*/
public void setAngle(double angle) {
if (angle < 0.0) {
angle = 0.0;
}
if (angle > 180.0) {
angle = 180.0;
}
double pos = angle / 180.0;
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo angle.
*
* @return Current servo angle
*/
public double getAngle() {
if (m_simPosition != null) {
return m_simPosition.get() * 180.0;
}
return 90.0;
}
/**
* Set the servo position.
*
* @param pos Desired position (Between 0.0 and 1.0)
*/
public void setPosition(double pos) {
if (pos < 0.0) {
pos = 0.0;
}
if (pos > 1.0) {
pos = 1.0;
}
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo position.
*
* @return Current servo position
*/
public double getPosition() {
if (m_simPosition != null) {
return m_simPosition.get();
}
return 0.5;
}
}

View File

@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrpcommandbased.subsystems;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.templates.xrpcommandbased.devices.XRPMotor;
import edu.wpi.first.wpilibj.xrp.XRPMotor;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class XRPDrivetrain extends SubsystemBase {

View File

@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrpeducational;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.templates.xrpeducational.devices.XRPMotor;
import edu.wpi.first.wpilibj.xrp.XRPMotor;
public class XRPDrivetrain {
private static final double kGearRatio =

View File

@@ -1,109 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrpeducational.devices;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPMotor.
*
* <p>A SimDevice based motor controller representing the motors on an XRP robot
*/
public class XRPMotor implements MotorController {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(0, "motorL");
s_simDeviceNameMap.put(1, "motorR");
s_simDeviceNameMap.put(2, "motor3");
s_simDeviceNameMap.put(3, "motor4");
}
private final SimDouble m_simSpeed;
private final SimBoolean m_simInverted;
/** XRPMotor. */
public XRPMotor(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on the WS messages as type: "XRPMotor", device: <motor name>
String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName);
if (xrpMotorSimDevice != null) {
xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true);
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false);
m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0);
} else {
m_simInverted = null;
m_simSpeed = null;
}
}
@Override
public void set(double speed) {
if (m_simSpeed != null) {
boolean invert = false;
if (m_simInverted != null) {
invert = m_simInverted.get();
}
m_simSpeed.set(invert ? -speed : speed);
}
}
@Override
public double get() {
if (m_simSpeed != null) {
return m_simSpeed.get();
}
return 0.0;
}
@Override
public void setInverted(boolean isInverted) {
if (m_simInverted != null) {
m_simInverted.set(isInverted);
}
}
@Override
public boolean getInverted() {
if (m_simInverted != null) {
return m_simInverted.get();
}
return false;
}
@Override
public void disable() {
set(0.0);
}
@Override
public void stopMotor() {
set(0.0);
}
}

View File

@@ -1,123 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrpeducational.devices;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPServo.
*
* <p>A SimDevice based servo
*/
public class XRPServo {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(4, "servo1");
s_simDeviceNameMap.put(5, "servo2");
}
private final SimDouble m_simPosition;
/** XRPServo. */
public XRPServo(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on WS as type: "XRPServo", device: <servo name>
String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName);
if (xrpServoSimDevice != null) {
xrpServoSimDevice.createBoolean("init", Direction.kOutput, true);
// This should mimic PWM position [0.0, 1.0]
m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5);
} else {
m_simPosition = null;
}
}
/**
* Set the servo angle.
*
* @param angle Desired angle in degrees
*/
public void setAngle(double angle) {
if (angle < 0.0) {
angle = 0.0;
}
if (angle > 180.0) {
angle = 180.0;
}
double pos = angle / 180.0;
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo angle.
*
* @return Current servo angle
*/
public double getAngle() {
if (m_simPosition != null) {
return m_simPosition.get() * 180.0;
}
return 90.0;
}
/**
* Set the servo position.
*
* @param pos Desired position (Between 0.0 and 1.0)
*/
public void setPosition(double pos) {
if (pos < 0.0) {
pos = 0.0;
}
if (pos > 1.0) {
pos = 1.0;
}
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo position.
*
* @return Current servo position
*/
public double getPosition() {
if (m_simPosition != null) {
return m_simPosition.get();
}
return 0.5;
}
}

View File

@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrptimed;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.templates.xrptimed.devices.XRPMotor;
import edu.wpi.first.wpilibj.xrp.XRPMotor;
public class XRPDrivetrain {
private static final double kGearRatio =

View File

@@ -1,109 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrptimed.devices;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPMotor.
*
* <p>A SimDevice based motor controller representing the motors on an XRP robot
*/
public class XRPMotor implements MotorController {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(0, "motorL");
s_simDeviceNameMap.put(1, "motorR");
s_simDeviceNameMap.put(2, "motor3");
s_simDeviceNameMap.put(3, "motor4");
}
private final SimDouble m_simSpeed;
private final SimBoolean m_simInverted;
/** XRPMotor. */
public XRPMotor(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on the WS messages as type: "XRPMotor", device: <motor name>
String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName);
if (xrpMotorSimDevice != null) {
xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true);
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false);
m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0);
} else {
m_simInverted = null;
m_simSpeed = null;
}
}
@Override
public void set(double speed) {
if (m_simSpeed != null) {
boolean invert = false;
if (m_simInverted != null) {
invert = m_simInverted.get();
}
m_simSpeed.set(invert ? -speed : speed);
}
}
@Override
public double get() {
if (m_simSpeed != null) {
return m_simSpeed.get();
}
return 0.0;
}
@Override
public void setInverted(boolean isInverted) {
if (m_simInverted != null) {
m_simInverted.set(isInverted);
}
}
@Override
public boolean getInverted() {
if (m_simInverted != null) {
return m_simInverted.get();
}
return false;
}
@Override
public void disable() {
set(0.0);
}
@Override
public void stopMotor() {
set(0.0);
}
}

View File

@@ -1,123 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.templates.xrptimed.devices;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import java.util.HashMap;
import java.util.HashSet;
/**
* XRPServo.
*
* <p>A SimDevice based servo
*/
public class XRPServo {
private static HashMap<Integer, String> s_simDeviceNameMap = new HashMap<>();
private static HashSet<Integer> s_registeredDevices = new HashSet<>();
private static void checkDeviceAllocation(int deviceNum) {
if (!s_simDeviceNameMap.containsKey(deviceNum)) {
throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5");
}
if (s_registeredDevices.contains(deviceNum)) {
throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated");
}
s_registeredDevices.add(deviceNum);
}
static {
s_simDeviceNameMap.put(4, "servo1");
s_simDeviceNameMap.put(5, "servo2");
}
private final SimDouble m_simPosition;
/** XRPServo. */
public XRPServo(int deviceNum) {
checkDeviceAllocation(deviceNum);
// We want this to appear on WS as type: "XRPServo", device: <servo name>
String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum);
SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName);
if (xrpServoSimDevice != null) {
xrpServoSimDevice.createBoolean("init", Direction.kOutput, true);
// This should mimic PWM position [0.0, 1.0]
m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5);
} else {
m_simPosition = null;
}
}
/**
* Set the servo angle.
*
* @param angle Desired angle in degrees
*/
public void setAngle(double angle) {
if (angle < 0.0) {
angle = 0.0;
}
if (angle > 180.0) {
angle = 180.0;
}
double pos = angle / 180.0;
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo angle.
*
* @return Current servo angle
*/
public double getAngle() {
if (m_simPosition != null) {
return m_simPosition.get() * 180.0;
}
return 90.0;
}
/**
* Set the servo position.
*
* @param pos Desired position (Between 0.0 and 1.0)
*/
public void setPosition(double pos) {
if (pos < 0.0) {
pos = 0.0;
}
if (pos > 1.0) {
pos = 1.0;
}
if (m_simPosition != null) {
m_simPosition.set(pos);
}
}
/**
* Get the servo position.
*
* @return Current servo position
*/
public double getPosition() {
if (m_simPosition != null) {
return m_simPosition.get();
}
return 0.5;
}
}