generated from wpilibsuite/vendor-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic squaring of omega and velocity magnitudes
- Loading branch information
1 parent
6665ac0
commit 6e18bd6
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
wpi_interface/src/main/java/coppercore/wpi_interface/DriveTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package coppercore.wpi_interface; | ||
|
||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
|
||
public interface DriveTemplate { | ||
public void setGoalSpeeds(ChassisSpeeds goalSpeeds, boolean fieldCentric); | ||
} |
47 changes: 47 additions & 0 deletions
47
wpi_interface/src/main/java/coppercore/wpi_interface/DriveWithJoysticks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package coppercore.wpi_interface; | ||
|
||
import coppercore.math.Deadband; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Transform2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.button.CommandJoystick; | ||
|
||
public class DriveWithJoysticks extends Command { | ||
private DriveTemplate drive; | ||
private CommandJoystick leftJoystick; | ||
private CommandJoystick rightJoystick; | ||
|
||
public DriveWithJoysticks( | ||
DriveTemplate drive, CommandJoystick leftJoystick, CommandJoystick rightJoystick) { | ||
this.drive = drive; | ||
this.leftJoystick = leftJoystick; | ||
this.rightJoystick = rightJoystick; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Translation2d linearSpeeds = getLinearVelocity(leftJoystick.getX(), leftJoystick.getY()); | ||
|
||
double omega = Deadband.oneAxisDeadband(rightJoystick.getX(), 0.1); | ||
omega = Math.copySign(omega * omega, omega); | ||
|
||
drive.setGoalSpeeds(new ChassisSpeeds(linearSpeeds.getX(), linearSpeeds.getY(), omega), true); | ||
} | ||
|
||
public Translation2d getLinearVelocity(double x, double y) { | ||
double deadband = Deadband.oneAxisDeadband(Math.hypot(x, y), 0.1); | ||
|
||
Rotation2d direction = new Rotation2d(x, y); | ||
double squaredMagnitude = deadband * deadband; | ||
|
||
Translation2d linearVelocity = | ||
new Pose2d(new Translation2d(), direction) | ||
.transformBy(new Transform2d(squaredMagnitude, 0.0, new Rotation2d())) | ||
.getTranslation(); | ||
|
||
return linearVelocity; | ||
} | ||
} |