mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal] Add frequency support to DutyCycle (#8076)
This commit is contained in:
@@ -50,7 +50,7 @@ public class DutyCycle implements Sendable, AutoCloseable {
|
||||
*
|
||||
* @return frequency in Hertz
|
||||
*/
|
||||
public int getFrequency() {
|
||||
public double getFrequency() {
|
||||
return DutyCycleJNI.getFrequency(m_handle);
|
||||
}
|
||||
|
||||
@@ -74,27 +74,6 @@ public class DutyCycle implements Sendable, AutoCloseable {
|
||||
return DutyCycleJNI.getHighTime(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scale factor of the output.
|
||||
*
|
||||
* <p>An output equal to this value is always high, and then linearly scales down to 0. Divide a
|
||||
* raw result by this in order to get the percentage between 0 and 1. Used by DMA.
|
||||
*
|
||||
* @return the output scale factor
|
||||
*/
|
||||
public int getOutputScaleFactor() {
|
||||
return DutyCycleJNI.getOutputScaleFactor(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycle.
|
||||
*
|
||||
* @return the FPGA index
|
||||
*/
|
||||
public final int getFPGAIndex() {
|
||||
return DutyCycleJNI.getFPGAIndex(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel of the source.
|
||||
*
|
||||
|
||||
@@ -19,7 +19,7 @@ import edu.wpi.first.util.sendable.SendableRegistry;
|
||||
public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
private final DutyCycle m_dutyCycle;
|
||||
private boolean m_ownsDutyCycle;
|
||||
private int m_frequencyThreshold = 100;
|
||||
private double m_frequencyThreshold = 100;
|
||||
private double m_fullRange;
|
||||
private double m_expectedZero;
|
||||
private double m_periodNanos;
|
||||
@@ -165,7 +165,7 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
*
|
||||
* @return duty cycle frequency in Hz
|
||||
*/
|
||||
public int getFrequency() {
|
||||
public double getFrequency() {
|
||||
return m_dutyCycle.getFrequency();
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
*
|
||||
* @param frequency the minimum frequency in Hz.
|
||||
*/
|
||||
public void setConnectedFrequencyThreshold(int frequency) {
|
||||
public void setConnectedFrequencyThreshold(double frequency) {
|
||||
if (frequency < 0) {
|
||||
frequency = 0;
|
||||
}
|
||||
@@ -235,15 +235,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycleEncoder.
|
||||
*
|
||||
* @return the FPGA index
|
||||
*/
|
||||
public int getFPGAIndex() {
|
||||
return m_dutyCycle.getFPGAIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel of the source.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,6 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
import edu.wpi.first.hal.simulation.DutyCycleDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.DutyCycle;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/** Class to control a simulated duty cycle digital input. */
|
||||
public class DutyCycleSim {
|
||||
@@ -19,7 +18,7 @@ public class DutyCycleSim {
|
||||
* @param dutyCycle DutyCycle to simulate
|
||||
*/
|
||||
public DutyCycleSim(DutyCycle dutyCycle) {
|
||||
m_index = dutyCycle.getFPGAIndex();
|
||||
m_index = dutyCycle.getSourceChannel();
|
||||
}
|
||||
|
||||
private DutyCycleSim(int index) {
|
||||
@@ -27,29 +26,13 @@ public class DutyCycleSim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a digital input channel.
|
||||
* Creates a DutyCycleSim for a SmartIO channel.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @param channel SmartIO channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no DutyCycle is configured for that channel
|
||||
*/
|
||||
public static DutyCycleSim createForChannel(int channel) {
|
||||
int index = DutyCycleDataJNI.findForChannel(channel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no duty cycle found for channel " + channel);
|
||||
}
|
||||
return new DutyCycleSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a simulated index. The index is incremented for each simulated
|
||||
* DutyCycle.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static DutyCycleSim createForIndex(int index) {
|
||||
return new DutyCycleSim(index);
|
||||
return new DutyCycleSim(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +82,7 @@ public class DutyCycleSim {
|
||||
*
|
||||
* @return the duty cycle frequency
|
||||
*/
|
||||
public int getFrequency() {
|
||||
public double getFrequency() {
|
||||
return DutyCycleDataJNI.getFrequency(m_index);
|
||||
}
|
||||
|
||||
@@ -108,7 +91,7 @@ public class DutyCycleSim {
|
||||
*
|
||||
* @param frequency the new frequency
|
||||
*/
|
||||
public void setFrequency(int frequency) {
|
||||
public void setFrequency(double frequency) {
|
||||
DutyCycleDataJNI.setFrequency(m_index, frequency);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user