Skip to content

Commit

Permalink
Fixed dutycycle sensor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
levyishai committed Aug 2, 2024
1 parent d1b9b18 commit 9cc9867
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class SimpleSensor {
private final String name;
private final SimpleSensorIO sensorIO;
private final SimpleSensorInputsAutoLogged sensorInputs = new SimpleSensorInputsAutoLogged();
private double
scalingSlope = 1,
scalingInterceptPoint = 0;

public static SimpleSensor createAnalogSensor(int channel, String name) {
final SimpleSensor nonRealSensor = createNonRealSensor(name);
Expand Down Expand Up @@ -48,6 +51,11 @@ private SimpleSensor(SimpleSensorIO sensorIO, String name) {
this.name = name;
}

public void setScalingConstants(double scalingSlope, double scalingInterceptPoint) {
this.scalingSlope = scalingSlope;
this.scalingInterceptPoint = scalingInterceptPoint;
}

public double getValue() {
return sensorInputs.value;
}
Expand All @@ -56,8 +64,8 @@ public boolean getBinaryValue() {
return sensorInputs.value > 0;
}

public double getDutyCycleValue(double maximumValue) {
return (sensorInputs.value - 0.5) * maximumValue;
public double getScaledValue() {
return (sensorInputs.value * scalingSlope) + scalingInterceptPoint;
}

public void setSimulationSupplier(DoubleSupplier simulationValueSupplier) {
Expand All @@ -66,6 +74,6 @@ public void setSimulationSupplier(DoubleSupplier simulationValueSupplier) {

public void updateSensor() {
sensorIO.updateInputs(sensorInputs);
Logger.processInputs("AnalogSensors/" + name, sensorInputs);
Logger.processInputs("SimpleSensors/" + name, sensorInputs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DutyCycleSensorIO(int channel) {
}

public void updateInputs(SimpleSensorInputsAutoLogged inputs) {
inputs.value = dutyCycle.getOutput();
inputs.value = dutyCycle.getHighTimeNanoseconds();
}
}

0 comments on commit 9cc9867

Please sign in to comment.