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

"Flare" Command - Auto-Drive Distance to Target #35

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

ZachOrr
Copy link
Contributor

@ZachOrr ZachOrr commented Jan 27, 2022

The "flare" command is used to drive the robot towards a target (ex: the Hub) until it reaches a certain distance. As the robot reaches the distance, it will slow down to a stop. The driver can strafe up-to the target to change the trajectory, as well as strafe around the target once the distance is reached.

@ZachOrr ZachOrr force-pushed the zorr/flair branch 11 times, most recently from 0b9bd2f to 255aae8 Compare January 28, 2022 00:29
// Driver can strafe during this command. Forward should be forward to the robot.
// Note that this command assumes we're facing the target (use with Heading)
return new AutoDrive.State(
output,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The driver's forward should be able to control speed if it's less than the desired speed. This would allow the driver to slow the approach, if necessary.

The thing to think about is if the driver pulls "back" while we're moving towards the target how we want to negotiate that input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's - 100% back is a full halt. They'll still be able to strafe around but they won't move forward. Anything less than 100% back is some percentage of a slow down. Anything forward up to our calculated output overrides the calculated speed. Anything above our calculated speed is ignored (this is so we don't over shoot or come in TOO hot)

@ZachOrr ZachOrr force-pushed the zorr/flair branch 4 times, most recently from 768b2b3 to 5a8e16c Compare February 8, 2022 17:23
@ZachOrr ZachOrr changed the title [WIP] Drives distance towards target command "Flare" Command - Auto-Drive Distance to Target Feb 8, 2022
@ZachOrr ZachOrr force-pushed the zorr/flair branch 2 times, most recently from c662c55 to 5916b15 Compare February 8, 2022 17:43
PolarCoordinate robotCoordinate = getRobotCoordinate();
distanceController.reset(
robotCoordinate.getRadiusMeters(),
chassisSpeedsProvider.get().vxMetersPerSecond
Copy link
Contributor Author

@ZachOrr ZachOrr Feb 8, 2022

Choose a reason for hiding this comment

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

I'm almost CERTAIN this LOC is wrong. It's under-thought. Our distance controller's velocity should be set based on the velocity of the robot towards the target. I think this can be done by constructing a triangle with the vx and vy speeds, looking at the robot's current angle from the target, and solving for the hypotenuse (which should be our velocity vector towards the point).

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the concern if we are moving at an angle to the target or away from the target the first move towards the target will be too violent? i.e. if we are moving away from the target at 50% speed and we hit the button while the profiled PID will ramp up velocity toward the target that will result in a severe direction changing event and potentially tip the robot.

Shouldn't the profiled PID take this into account though? Not sure, but something we can test since we never tested this command on the move.

Copy link
Contributor Author

@ZachOrr ZachOrr Feb 8, 2022

Choose a reason for hiding this comment

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

The use case is exactly right - if you're not moving in the direction of the target, we want to ramp down to zero and then back up to a velocity towards the target.

The profiled PID does not take this in to account by default. It'll assume your starting velocity is zero, unless you specify otherwise. https://github.com/wpilibsuite/allwpilib/blob/791770cf6e2b97901333fbd4d02215380e2a535c/wpimath/src/main/java/edu/wpi/first/math/controller/ProfiledPIDController.java#L363-L371

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm axing the velocity handoff stuff - since I'm still not confident on the math of this one. I need to do some more research before I feel confident landing this. If we have drivers driving and see not having a velocity handoff as really making the move in to flare jumpy we can prioritize getting it back in.

@ZachOrr
Copy link
Contributor Author

ZachOrr commented Feb 10, 2022

Okay got the last piece of this. For finding the trajectory of the robot towards/away from the point-

The theta of our polar coordinate allows us to construct a triangle that represents our velocity towards/away from the point. If the robot is at a 45 degree angle - the hypotenuse of both the vx and vy vectors will be our velocity towards/away from the point.

If the robot is not at a 45 - we're working with one side of a triangle and need to find the other in order to construct the velocity. In the case that the robot is 0-45, we're moving further on the X direction than the Y, so our vx is the leg we can use. In the case of 45-90, we're moving further on the Y direction than the X, so our vy is the leg we can use. In the case of our 0-45, our angle can be whatever the angle is. In the case of our 45-90, we need to look at the angle relative to the 90 as opposed to the zero (our Y axis as opposed to our X axis) because the vy leg would be "too short" to reach the angle starting from zero.

Once we have a side and an angle, we can calculate our new side using -
a = b * tan(α)

And then once we have our final side, we can calculate our hypotenuse - which will be our velocity towards/away from the point.

Fairly straightforward - I think the "reference from 90" is the only arc of work I need to think about to make sure it's a clean, readable solution.

Comment on lines 50 to 53
distanceController = new ProfiledPIDController(2, 0.0, 0.0,
// Use max speed above. Come up to max speed in one second
new TrapezoidProfile.Constraints(
Units.inchesToMeters(120),
Units.inchesToMeters(120) / 2
)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These values were looking pretty good today. We're still jumpy towards the end. We probably need to look to decrease our P value.

@ZachOrr ZachOrr force-pushed the zorr/flair branch 13 times, most recently from 3e034a0 to 574dfe3 Compare February 18, 2022 05:07
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.

2 participants