Skip to content

Drive holdheading encoder pid#34

Open
ashergottlieb wants to merge 36 commits intomasterfrom
drive-holdheading-encoder-pid
Open

Drive holdheading encoder pid#34
ashergottlieb wants to merge 36 commits intomasterfrom
drive-holdheading-encoder-pid

Conversation

@ashergottlieb
Copy link
Member

@ashergottlieb ashergottlieb commented Feb 21, 2017

Before Merging

Check the following subsystems work:

Drivetrain

  • Teleop w/ joysticks
  • Hold heading
  • Turn to angle

Shooter

  • Shooter motor spins at right speed
  • Feeder runs forward and backwards on butttons
  • Shoot at least one ball

Turret/Vision

  • All other subsystems work w/ camera unplugged
  • Turret turns to limit switches w/ manual control
  • Turns to target w/ vision

Climbtake

  • Intake runs forward
  • Runs backward
  • Climbs

Auto

  • At least one auto mode has been run

private final ConnectableFlowable<Double> currentHeading;
private final TimeUnit pidTerminateUnit = TimeUnit.MILLISECONDS;
private final long pidTerminateTime = 1000;
private final double distanceP = 0.2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these static constants

this.teleHoldHeading = teleHoldHeading;
}

private Flowable<?> pidTerminator(Flowable<Double> error, double tolerance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into FRamework (time permitting)

*/
public Command driveDistanceAction(double distance, double speed) {
System.out.println(FEET_PER_ENCODER_ROTATION);
public Command driveDistance(double distance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move all three to separate lines

public Command driveDistanceAction(double distance, double speed) {
System.out.println(FEET_PER_ENCODER_ROTATION);
public Command driveDistance(double distance,
double distanceTolerance, double angleTolerance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining that this just stores the current heading

double setpoint = distance / FEET_PER_ENCODER_ROTATION;
System.out.println(setpoint);
Command resetRight = Command.just(x -> {
Flowable<Double> distanceError = toFlow(() ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the 2.0 come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the simple average of the two controllers' positions.

Command resetRight = Command.just(x -> {
Flowable<Double> distanceError = toFlow(() ->
(rightDrive.position() + leftDrive.position()) / 2.0 - setpoint);
Flowable<Double> distanceOutput = distanceError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move .onBackpressureDrop to new line

distanceOutput.subscribe(new WpiSmartDashboard().getTextFieldDouble("distance"));
Command right = Command.fromSubscription(() ->
combineLatest(distanceOutput, angleOutput, (x, y) -> x + y)
.map(limitWithin(-1.0, 1.0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

.terminable(pidTerminator(distanceError,
distanceTolerance / WHEEL_ROTATION_PER_ENCODER_ROTATION))
.then(driveHoldHeading(noDrive, noDrive, Flowable.just(true), targetHeading)
.terminable(pidTerminator(angleError, angleTolerance))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this hard coded in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this stop us from going a longer distance?

.subscribeOn(Schedulers.io())
.onBackpressureDrop()
.map(limitWithin(-1.0, 1.0))
.map(Events::power)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use lambda notation

public Command registerAuto() {
Command drive = this.drivetrain.driveDistanceAction(4.0, 0.3);
return drive.then(this.drivetrain.turn(-85, 1)).then(drive);
return Command.serial(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice. Very declarative!

private static final double FEET_PER_ENCODER_ROTATION =
FEET_PER_WHEEL_ROTATION * WHEEL_ROTATION_PER_ENCODER_ROTATION;
// PID for turning to an angle based on the gyro
private static final double angleP = 0.09;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make constant notation

public void registerSubscriptions() {
FlowOperators.deadband(joyControl).map(FlowOperators::printId).map(x -> Events.power(x / 4))
FlowOperators.deadband(joyControl).map(x -> Events.power(x / 4))
.subscribe(hoodMaster); //TODO: remove this joystick
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this TODO been done?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in Lydia's branch, wait for that to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants