diff --git a/romiVendordep/robotpy_pybind_build_info.bzl b/romiVendordep/robotpy_pybind_build_info.bzl index 9e115333a8..fe5e1b6f75 100644 --- a/romiVendordep/robotpy_pybind_build_info.bzl +++ b/romiVendordep/robotpy_pybind_build_info.bzl @@ -37,6 +37,16 @@ def romi_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includes ("wpi::romi::RomiMotor", "wpi__romi__RomiMotor.hpp"), ], ), + struct( + class_name = "RomiServo", + yml_file = "semiwrap/RomiServo.yml", + header_root = "$(execpath :robotpy-native-romi.copy_headers)", + header_file = "$(execpath :robotpy-native-romi.copy_headers)/wpi/romi/RomiServo.hpp", + tmpl_class_names = [], + trampolines = [ + ("wpi::romi::RomiServo", "wpi__romi__RomiServo.hpp"), + ], + ), ] resolve_casters( diff --git a/romiVendordep/src/main/java/org/wpilib/romi/OnBoardIO.java b/romiVendordep/src/main/java/org/wpilib/romi/OnBoardIO.java index 8dc3fccc82..00e7c0a51c 100644 --- a/romiVendordep/src/main/java/org/wpilib/romi/OnBoardIO.java +++ b/romiVendordep/src/main/java/org/wpilib/romi/OnBoardIO.java @@ -150,4 +150,18 @@ public class OnBoardIO { public void setYellowLed(boolean value) { m_yellowLed.set(value); } + + private static final boolean[] s_allocatedPWMs = new boolean[4]; + + static void allocatePWM(int deviceNum) { + if (deviceNum < 0 || deviceNum > 3) { + throw new IllegalArgumentException("Invalid Romi PWM output. Should be 0-3"); + } + + if (s_allocatedPWMs[deviceNum]) { + throw new IllegalArgumentException("Romi PWM output " + deviceNum + " already allocated"); + } + + s_allocatedPWMs[deviceNum] = true; + } } diff --git a/romiVendordep/src/main/java/org/wpilib/romi/RomiMotor.java b/romiVendordep/src/main/java/org/wpilib/romi/RomiMotor.java index c6ae05c9eb..c8288e4bfc 100644 --- a/romiVendordep/src/main/java/org/wpilib/romi/RomiMotor.java +++ b/romiVendordep/src/main/java/org/wpilib/romi/RomiMotor.java @@ -4,19 +4,19 @@ package org.wpilib.romi; -import org.wpilib.hardware.motor.PWMMotorController; +import org.wpilib.hardware.hal.SimDevice; +import org.wpilib.hardware.hal.SimDevice.Direction; +import org.wpilib.hardware.hal.SimDouble; +import org.wpilib.hardware.motor.MotorController; /** * RomiMotor. * - *
A general use PWM motor controller representing the motors on a Romi robot + *
A SimDevice based motor controller representing the motors on a Romi robot
*/
-public class RomiMotor extends PWMMotorController {
- /** Common initialization code called by all constructors. */
- protected final void initRomiMotor() {
- m_pwm.setOutputPeriod(5);
- setThrottle(0.0);
- }
+public class RomiMotor implements MotorController {
+ private final SimDouble m_simSpeed;
+ private boolean m_inverted;
/**
* Constructor.
@@ -24,9 +24,49 @@ public class RomiMotor extends PWMMotorController {
* @param channel The PWM channel that the RomiMotor is attached to. 0 is the left motor, 1 is the
* right.
*/
- @SuppressWarnings("this-escape")
- public RomiMotor(final int channel) {
- super("Romi Motor", channel);
- initRomiMotor();
+ public RomiMotor(int channel) {
+ OnBoardIO.allocatePWM(channel);
+
+ // We want this to appear on the WS messages as type: "PWM", device: A SimDevice based servo
+ */
+public class RomiServo {
+ private final SimDouble m_simPosition;
+
+ /**
+ * Constructs a RomiServo.
+ *
+ * @param channel the PWM channel the servo is attached to.
+ */
+ public RomiServo(int channel) {
+ OnBoardIO.allocatePWM(channel);
+
+ // We want this to appear on WS as type: "PWM", device: A SimDevice based motor controller representing the motors on a Romi robot
*/
-class RomiMotor : public wpi::PWMMotorController {
+class RomiMotor : public wpi::MotorController, public wpi::MotorSafety {
public:
/**
- * Constructor for a RomiMotor.
+ * Constructs a RomiMotor.
*
* @param channel The PWM channel that the RomiMotor is attached to.
* 0 is left, 1 is right
*/
explicit RomiMotor(int channel);
- RomiMotor(RomiMotor&&) = default;
- RomiMotor& operator=(RomiMotor&&) = default;
+ void SetThrottle(double throttle) override;
+ double GetThrottle() const override;
+
+ void SetInverted(bool isInverted) override;
+ bool GetInverted() const override;
+
+ void Disable() override;
+
+ void StopMotor() override;
+ std::string GetDescription() const override;
+
+ private:
+ hal::SimDevice m_simDevice;
+ hal::SimDouble m_simSpeed;
+ std::string m_deviceName;
+ bool m_inverted = false;
};
/** @} */
diff --git a/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp b/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp
new file mode 100644
index 0000000000..994d0fd553
--- /dev/null
+++ b/romiVendordep/src/main/native/include/wpi/romi/RomiServo.hpp
@@ -0,0 +1,52 @@
+// 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.
+
+#pragma once
+
+#include "wpi/hal/SimDevice.hpp"
+#include "wpi/units/angle.hpp"
+
+namespace wpi::romi {
+
+/**
+ * @ingroup romi_api
+ * @{
+ */
+
+/**
+ * RomiServo.
+ *
+ * A SimDevice based servo
+ */
+class RomiServo {
+ public:
+ /**
+ * Constructs a RomiServo.
+ *
+ * @param channel the servo channel
+ */
+ explicit RomiServo(int channel);
+
+ /**
+ * Set the servo angle.
+ *
+ * @param angle Desired angle in radians
+ */
+ void SetAngle(wpi::units::radian_t angle);
+
+ /**
+ * Get the servo angle.
+ *
+ * @return Current servo angle in radians
+ */
+ wpi::units::radian_t GetAngle() const;
+
+ private:
+ hal::SimDevice m_simDevice;
+ hal::SimDouble m_simPosition;
+};
+
+/** @} */
+
+} // namespace wpi::romi
diff --git a/romiVendordep/src/main/python/pyproject.toml b/romiVendordep/src/main/python/pyproject.toml
index 98e1bbbc6b..5a016b74eb 100644
--- a/romiVendordep/src/main/python/pyproject.toml
+++ b/romiVendordep/src/main/python/pyproject.toml
@@ -58,3 +58,4 @@ depends = [
OnBoardIO = "wpi/romi/OnBoardIO.hpp"
RomiGyro = "wpi/romi/RomiGyro.hpp"
RomiMotor = "wpi/romi/RomiMotor.hpp"
+RomiServo = "wpi/romi/RomiServo.hpp"
diff --git a/romiVendordep/src/main/python/romi/__init__.py b/romiVendordep/src/main/python/romi/__init__.py
index be1981eb5f..4c8163a2bd 100644
--- a/romiVendordep/src/main/python/romi/__init__.py
+++ b/romiVendordep/src/main/python/romi/__init__.py
@@ -1,8 +1,8 @@
from . import _init__romi
# autogenerated by 'semiwrap create-imports romi romi._romi'
-from ._romi import OnBoardIO, RomiGyro, RomiMotor
+from ._romi import OnBoardIO, RomiGyro, RomiMotor, RomiServo
-__all__ = ["OnBoardIO", "RomiGyro", "RomiMotor"]
+__all__ = ["OnBoardIO", "RomiGyro", "RomiMotor", "RomiServo"]
del _init__romi
diff --git a/romiVendordep/src/main/python/semiwrap/OnBoardIO.yml b/romiVendordep/src/main/python/semiwrap/OnBoardIO.yml
index 12c28b5713..94c500a219 100644
--- a/romiVendordep/src/main/python/semiwrap/OnBoardIO.yml
+++ b/romiVendordep/src/main/python/semiwrap/OnBoardIO.yml
@@ -13,3 +13,4 @@ classes:
SetGreenLed:
SetRedLed:
SetYellowLed:
+ AllocatePWM:
diff --git a/romiVendordep/src/main/python/semiwrap/RomiMotor.yml b/romiVendordep/src/main/python/semiwrap/RomiMotor.yml
index 22af2f09a5..5869584e1f 100644
--- a/romiVendordep/src/main/python/semiwrap/RomiMotor.yml
+++ b/romiVendordep/src/main/python/semiwrap/RomiMotor.yml
@@ -2,3 +2,10 @@ classes:
wpi::romi::RomiMotor:
methods:
RomiMotor:
+ SetThrottle:
+ GetThrottle:
+ SetInverted:
+ GetInverted:
+ Disable:
+ StopMotor:
+ GetDescription:
diff --git a/romiVendordep/src/main/python/semiwrap/RomiServo.yml b/romiVendordep/src/main/python/semiwrap/RomiServo.yml
new file mode 100644
index 0000000000..5fa334a0bb
--- /dev/null
+++ b/romiVendordep/src/main/python/semiwrap/RomiServo.yml
@@ -0,0 +1,6 @@
+classes:
+ wpi::romi::RomiServo:
+ methods:
+ RomiServo:
+ SetAngle:
+ GetAngle: