Skip to content

Commit

Permalink
Added (NYI) CRServo and MotorAsServo hardware devices
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinfrei committed Nov 26, 2023
1 parent 9f2f465 commit 9bd0cab
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.technototes.library.hardware.motor;

import com.technototes.library.hardware.HardwareDevice;
import java.io.InvalidClassException;
import java.util.function.Supplier;

/**
* This is for "continuous rotation" servos. They work, unfortunately, like motors
* without encoders: You can set a power (from 0 to 1, typically, with .5 as "stop") and the
* servo will spin in the direct, at the provided speed...
*
* Not Yet Implemented!
* TODO: Implement this
*/
public class CRServo extends HardwareDevice<com.qualcomm.robotcore.hardware.CRServo> implements Supplier<Double> {

public CRServo(com.qualcomm.robotcore.hardware.CRServo device, String deviceName) throws InvalidClassException {
super(device, deviceName);
throw new InvalidClassException("com.technototes.library.hardware.motor.CRServo", "Not Yet Implemented");
}

protected CRServo(String deviceName) throws InvalidClassException {
super(deviceName);
throw new InvalidClassException("com.technototes.library.hardware.motor.CRServo", "Not Yet Implemented");
}

@Override
public String LogLine() {
return null;
}

@Override
public Double get() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public Motor(String deviceName) {
* @return The Motor (for chaining)
*/
public Motor<T> setLimits(double mi, double ma) {
min = Range.clip(mi, -1, 1);
max = Range.clip(ma, -1, 1);
mi = Range.clip(mi, -1, 1);
ma = Range.clip(ma, -1, 1);
min = Math.min(mi, ma);
max = Math.max(mi, ma);
return this;
}

Expand Down Expand Up @@ -83,18 +85,39 @@ public Motor<T> setDirection(DcMotorSimple.Direction dir) {
* Gets the power value for the motor
*
* @return the power value (as a double)
* @deprecated use getPower() instead
*/
@Deprecated
public double getSpeed() {
return getPower();
}

/**
* Gets the power value for the motor
*
* @return the power value (as a double)
*/
public double getPower() {
return device.getPower();
}

/**
* Set speed of motor
* Set the (range-clipped) speed of motor
*
* @param speed The speed of the motor
*/
@Deprecated
public void setSpeed(double speed) {
device.setPower(Range.clip(speed, min, max));
setPower(speed);
}

/**
* Set the (range-clipped) power of the motor
*
* @param pow The power value (-1 -> 1)
*/
public void setPower(double pow) {
device.setPower(Range.clip(pow, min, max));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.technototes.library.hardware.servo;

import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.technototes.library.hardware.HardwareDevice;
import com.technototes.library.hardware.Sensored;
import java.io.InvalidClassException;

/**
* This is to use a motor as a servo using the built-in capabilities (instead of doing it manually)
*
* One rather important feature would be to hand control back & forth between a normal encoded
* motor. The alternative would be to extend EncodedMotor to just "do" this stuff automatically.
* Honestly, that probably makes more sense, but requires some thought about state transitions.
*
* @param <T>
* Not Yet Implemented!
* TODO: Implement this
*
*/
public class MotorAsServo<T extends DcMotor> extends HardwareDevice<T> implements Sensored {

public MotorAsServo(T device, String deviceName) throws InvalidClassException {
super(device, deviceName);
throw new InvalidClassException("com.technototes.library.hardware.servo.MotorAsServo", "Not Yet Implemented");
}

protected MotorAsServo(String deviceName) throws InvalidClassException {
super(deviceName);
throw new InvalidClassException("com.technototes.library.hardware.servo.MotorAsServo", "Not Yet Implemented");
}

/**
* @return
*/
@Override
public String LogLine() {
return null;
}

/**
* @return
*/
@Override
public double getSensorValue() {
return 0;
}

/**
* @return
*/
@Override
public double getAsDouble() {
return getSensorValue();
}
}

0 comments on commit 9bd0cab

Please sign in to comment.