Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TechnoLib 2.0 updates #37

Merged
merged 47 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0728f56
Cleaning up logging so things function with the dashboard
kevinfrei Nov 19, 2023
6a7b365
Ripped out the NumberBar and NumberSlider lines. Colors are next.
kevinfrei Nov 19, 2023
9bba9bc
Removed the color support from the logging stuff
kevinfrei Nov 19, 2023
7d9b05e
Minor cleaning up
kevinfrei Nov 19, 2023
57ae0d7
Updated the docs link. I should also update github.io...
kevinfrei Nov 19, 2023
5d778db
Updated prettier, formatted stuff
kevinfrei Nov 19, 2023
060c148
Undeprecated some stuff (for now) added Motor.setDir/setFwd/setBack, …
kevinfrei Oct 5, 2023
bf14740
Removed some deprecated stuff
kevinfrei Oct 5, 2023
aa5a228
Steps toward a simplified vision pipeline
kevinfrei Oct 6, 2023
7986261
Finished spelling fix for propogate->propagate
kevinfrei Oct 14, 2023
75466e9
Not yet used, but the PowerPlay branch is building with everything else
kevinfrei Oct 14, 2023
7d16862
Okay, more than just Vision improvements. [move to new branch]
kevinfrei Oct 14, 2023
b38a93e
Added consumer/biconsumer versions of CommandSchedule.schedule* funct…
kevinfrei Oct 14, 2023
90c051e
Updated tests
kevinfrei Oct 14, 2023
20af31d
Added some comments and examples, plus non-controlling commands
kevinfrei Oct 14, 2023
0430a59
Added method-ref based command stuff for controls
kevinfrei Oct 14, 2023
2f016de
Syntactic helpers for auto paths
kevinfrei Oct 15, 2023
0634a1c
Source Formatting
kevinfrei Oct 15, 2023
5a50d0e
Added a little bit to the Vision stuff as I'm porting PowerPlay
kevinfrei Oct 15, 2023
4181cc7
Moved detectionStart before numRectangles
kevinfrei Oct 15, 2023
3bb5a9b
Some doc updates. I should go dig up how to deploy stuff to github.io…
kevinfrei Oct 16, 2023
848fe6a
Added some @Deprecated tags in the IMU class, formatted code
kevinfrei Oct 17, 2023
09b6e30
Wrote up a little bit about simulation, to get it written down somewhere
kevinfrei Oct 19, 2023
d528e61
Removed a bunch of overloads to simplify the API's
kevinfrei Oct 20, 2023
fe0a89b
Added an extra constructor for SimpleCommand
kevinfrei Oct 20, 2023
c4edc95
Removed a bunch of overloads to simplify the CommandScheduler API, too
kevinfrei Oct 20, 2023
4d09f6d
Deprecated the Paramater*Command classes, and made SimpleRequiredComm…
kevinfrei Oct 20, 2023
745313e
Added comments
kevinfrei Oct 21, 2023
cf64d26
Deprecated the {Device}Subsystem classes, added TwoDeadWheelLocalizer
kevinfrei Oct 22, 2023
8ffdfa6
Finished cleaning up the *Group types
kevinfrei Oct 22, 2023
f2bb589
Modified propagate to take (effectively) a method ref to run
kevinfrei Oct 22, 2023
e0314bd
Added some stuff to readme
kevinfrei Nov 3, 2023
d28c873
Added (NYI) CRServo and MotorAsServo hardware devices
kevinfrei Nov 26, 2023
99b2b55
A few more updates, cleaned up getting the motor
kevinfrei Nov 26, 2023
a75701a
Got log data for all the sensors. Motors then let's try to use it
kevinfrei Nov 15, 2023
5994a67
LogLine overrides for all hardware types. Config-based logging next
kevinfrei Nov 16, 2023
7137ec5
Not using the logging capabilities yet, but maybe soon
kevinfrei Nov 16, 2023
91ab8fa
Fixed some minor stuff, cleaned some other stuff up
kevinfrei Nov 16, 2023
af6a162
Untested logging infrastructure
kevinfrei Nov 16, 2023
6f987e2
Working on getting things fully hidden: Not building yet.
kevinfrei Nov 19, 2023
70e8412
Removed the HardwareDeviceGroup interface
kevinfrei Nov 26, 2023
2902e1a
Cleaned up the simple command stuff
kevinfrei Jan 27, 2024
281366d
Removed the Double Supplier from CRServo
kevinfrei Jan 28, 2024
53b5e46
Some comments
kevinfrei Feb 12, 2024
9d2654b
Added suppliers on MethodCommands and Command.create commands
kevinfrei Sep 8, 2024
7a7f17b
Fixed some typos, filled out CRServo wrapper, re-doc'ed
kevinfrei Sep 9, 2024
34eb70b
Bun-ification
kevinfrei Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public PathingMecanumDrivebaseSubsystem(
c.getDouble(WheelBase.class),
c.getDouble(LateralMult.class)
);
leftFront = fl.getDevice();
leftRear = rl.getDevice();
rightRear = rr.getDevice();
rightFront = fr.getDevice();
leftFront = fl.getRawMotor(DcMotorEx.class);
leftRear = rl.getRawMotor(DcMotorEx.class);
rightRear = rr.getRawMotor(DcMotorEx.class);
rightFront = fr.getRawMotor(DcMotorEx.class);

motors = Arrays.asList(leftFront, leftRear, rightRear, rightFront);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.PIDFCoefficients;
import com.qualcomm.robotcore.hardware.VoltageSensor;
import com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType;
import com.technototes.library.hardware.HardwareDevice;
import com.technototes.library.hardware.motor.EncodedMotorGroup;
import com.technototes.library.hardware.motor.EncodedMotor;
import com.technototes.library.hardware.sensor.IMU;
import com.technototes.library.subsystem.Subsystem;
import com.technototes.path.subsystem.TankConstants.*;
Expand All @@ -34,7 +33,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;

public class TankDrivebaseSubsystem extends TankDrive implements Subsystem {
Expand All @@ -60,14 +58,14 @@ public class TankDrivebaseSubsystem extends TankDrive implements Subsystem {

private TrajectoryFollower follower;

private List<DcMotorEx> motors, leftMotors, rightMotors;
private List<EncodedMotor<DcMotorEx>> motors, leftMotors, rightMotors;
private IMU imu;

private VoltageSensor batteryVoltageSensor;

public TankDrivebaseSubsystem(
EncodedMotorGroup<DcMotorEx> left,
EncodedMotorGroup<DcMotorEx> right,
List<EncodedMotor<DcMotorEx>> left,
List<EncodedMotor<DcMotorEx>> right,
IMU i,
TankConstants c,
Localizer localizer
Expand Down Expand Up @@ -120,17 +118,19 @@ public TankDrivebaseSubsystem(
// add/remove motors depending on your robot (e.g., 6WD)

motors = new ArrayList<>();
leftMotors = left.getAllDeviceList().stream().map(HardwareDevice::getDevice).collect(Collectors.toList());
rightMotors = right.getAllDeviceList().stream().map(HardwareDevice::getDevice).collect(Collectors.toList());
leftMotors = left;
rightMotors = right;
motors.addAll(leftMotors);
motors.addAll(rightMotors);

for (DcMotorEx motor : motors) {
/*
* Turning this off for now, because we don't expose it in the EncodedMotor class (yet?)
for (EncodedMotor<DcMotorEx> motor : motors) {
MotorConfigurationType motorConfigurationType = motor.getMotorType().clone();
motorConfigurationType.setAchieveableMaxRPMFraction(1.0);
motor.setMotorType(motorConfigurationType);
}

*/
if (c.getBoolean(TankConstants.UseDriveEncoder.class)) {
setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
Expand Down Expand Up @@ -215,14 +215,18 @@ public boolean isBusy() {
}

public void setMode(DcMotor.RunMode runMode) {
for (DcMotorEx motor : motors) {
motor.setMode(runMode);
for (EncodedMotor<DcMotorEx> motor : motors) {
motor.setRunMode(runMode);
}
}

public void setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior) {
for (DcMotorEx motor : motors) {
motor.setZeroPowerBehavior(zeroPowerBehavior);
for (EncodedMotor<DcMotorEx> motor : motors) {
if (zeroPowerBehavior == DcMotor.ZeroPowerBehavior.BRAKE) {
motor.brake();
} else if (zeroPowerBehavior == DcMotor.ZeroPowerBehavior.FLOAT) {
motor.coast();
}
}
}

Expand All @@ -233,7 +237,7 @@ public void setPIDFCoefficients(DcMotor.RunMode runMode, PIDFCoefficients coeffi
coefficients.d,
(coefficients.f * 12) / batteryVoltageSensor.getVoltage()
);
for (DcMotorEx motor : motors) {
for (EncodedMotor<DcMotorEx> motor : motors) {
motor.setPIDFCoefficients(runMode, compensatedCoefficients);
}
}
Expand All @@ -255,13 +259,13 @@ public void setWeightedDrivePower(Pose2d drivePower) {
@Override
public List<Double> getWheelPositions() {
double leftSum = 0, rightSum = 0;
for (DcMotorEx leftMotor : leftMotors) {
for (EncodedMotor<DcMotorEx> leftMotor : leftMotors) {
leftSum +=
TankConstants.encoderTicksToInches(leftMotor.getCurrentPosition(), WHEEL_RADIUS, GEAR_RATIO, TICKS_PER_REV);
for (DcMotorEx rightMotor : rightMotors) {
TankConstants.encoderTicksToInches(leftMotor.getSensorValue(), WHEEL_RADIUS, GEAR_RATIO, TICKS_PER_REV);
for (EncodedMotor<DcMotorEx> rightMotor : rightMotors) {
rightSum +=
TankConstants.encoderTicksToInches(
rightMotor.getCurrentPosition(),
rightMotor.getSensorValue(),
WHEEL_RADIUS,
GEAR_RATIO,
TICKS_PER_REV
Expand All @@ -273,11 +277,11 @@ public List<Double> getWheelPositions() {

public List<Double> getWheelVelocities() {
double leftSum = 0, rightSum = 0;
for (DcMotorEx leftMotor : leftMotors) {
for (EncodedMotor<DcMotorEx> leftMotor : leftMotors) {
leftSum +=
TankConstants.encoderTicksToInches(leftMotor.getVelocity(), WHEEL_RADIUS, GEAR_RATIO, TICKS_PER_REV);
}
for (DcMotorEx rightMotor : rightMotors) {
for (EncodedMotor<DcMotorEx> rightMotor : rightMotors) {
rightSum +=
TankConstants.encoderTicksToInches(rightMotor.getVelocity(), WHEEL_RADIUS, GEAR_RATIO, TICKS_PER_REV);
}
Expand All @@ -286,11 +290,11 @@ public List<Double> getWheelVelocities() {

@Override
public void setMotorPowers(double v, double v1) {
for (DcMotorEx leftMotor : leftMotors) {
leftMotor.setPower(v);
for (EncodedMotor<DcMotorEx> leftMotor : leftMotors) {
leftMotor.setSpeed(v);
}
for (DcMotorEx rightMotor : rightMotors) {
rightMotor.setPower(v1);
for (EncodedMotor<DcMotorEx> rightMotor : rightMotors) {
rightMotor.setSpeed(v1);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.technototes.path.subsystem;

import static com.technototes.path.subsystem.DeadWheelConstants.EncoderOverflow;
import static com.technototes.path.subsystem.DeadWheelConstants.ForwardOffset;
import static com.technototes.path.subsystem.DeadWheelConstants.GearRatio;
import static com.technototes.path.subsystem.DeadWheelConstants.LateralDistance;
import static com.technototes.path.subsystem.DeadWheelConstants.TicksPerRev;
import static com.technototes.path.subsystem.DeadWheelConstants.WheelRadius;

import androidx.annotation.NonNull;
import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.acmerobotics.roadrunner.localization.ThreeTrackingWheelLocalizer;
import com.acmerobotics.roadrunner.localization.TwoTrackingWheelLocalizer;
import com.technototes.library.hardware.sensor.IMU;
import com.technototes.library.hardware.sensor.encoder.MotorEncoder;
import com.technototes.library.subsystem.Subsystem;
import java.util.Arrays;
import java.util.List;
import java.util.function.DoubleSupplier;

/*
* Sample tracking wheel localizer implementation assuming a standard configuration:
*
* /---------------\
* | ____ |
* | ---- |
* | || ^ |
* | ||<- lr | |
* | fb |
* | |
* \---------------/
*
* COMPLETELY UNTESTED!!
*/
public class TwoDeadWheelLocalizer extends TwoTrackingWheelLocalizer implements Subsystem {

protected MotorEncoder leftrightEncoder, frontbackEncoder;
protected DoubleSupplier headingSupplier;
protected double lateralDistance, forwardOffset, gearRatio, wheelRadius, ticksPerRev;

protected boolean encoderOverflow;

public TwoDeadWheelLocalizer(IMU imu, MotorEncoder lr, MotorEncoder fb, DeadWheelConstants constants) {
super(
Arrays.asList(
new Pose2d(0, constants.getDouble(LateralDistance.class), 0), // left
new Pose2d(constants.getDouble(ForwardOffset.class), 0, Math.toRadians(90)) // front
)
);
leftrightEncoder = lr;
frontbackEncoder = fb;
headingSupplier = () -> imu.gyroHeading();

lateralDistance = constants.getDouble(LateralDistance.class);
forwardOffset = constants.getDouble(ForwardOffset.class);
encoderOverflow = constants.getBoolean(EncoderOverflow.class);
gearRatio = constants.getDouble(GearRatio.class);
ticksPerRev = constants.getDouble(TicksPerRev.class);
wheelRadius = constants.getDouble(WheelRadius.class);
}

public double encoderTicksToInches(double ticks) {
return ((getWheelRadius() * 2 * Math.PI * getGearRatio() * ticks) / getTicksPerRev());
}

@NonNull
@Override
public List<Double> getWheelPositions() {
return Arrays.asList(
encoderTicksToInches(leftrightEncoder.getCurrentPosition()),
encoderTicksToInches(frontbackEncoder.getCurrentPosition())
);
}

@NonNull
@Override
public List<Double> getWheelVelocities() {
// TODO: If your encoder velocity can exceed 32767 counts / second (such as the REV Through Bore and other
// competing magnetic encoders), change Encoder.getRawVelocity() to Encoder.getCorrectedVelocity() to enable a
// compensation method

return Arrays.asList(
encoderTicksToInches(leftrightEncoder.getCorrectedVelocity()),
encoderTicksToInches(frontbackEncoder.getCorrectedVelocity())
);
}

public double getTicksPerRev() {
return ticksPerRev;
}

public double getWheelRadius() {
return wheelRadius;
}

public double getGearRatio() {
return gearRatio;
}

@Override
public double getHeading() {
return headingSupplier.getAsDouble();
}
}
Loading
Loading