-
Notifications
You must be signed in to change notification settings - Fork 0
Rotation #2
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
base: main
Are you sure you want to change the base?
Rotation #2
Changes from all commits
805b17d
6fa31b4
8cf3866
bf262f4
77608fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,9 +73,12 @@ public void execute() { | |
|
|
||
| @Override | ||
| public boolean isFinished() { | ||
|
|
||
| //speed, current position, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⭐ ⭐ ⭐ this should be returning if we've reached our goal, like you're doing above with the orientation one. Same idea of low error and low speed can apply here! |
||
| return true; | ||
|
|
||
| // Modify this to return true once you have met your goal, | ||
| // and you're moving fairly slowly (ideally stopped) | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,24 +5,50 @@ | |
| import xbot.common.command.BaseCommand; | ||
| import competition.subsystems.drive.DriveSubsystem; | ||
| import competition.subsystems.pose.PoseSubsystem; | ||
| import xbot.common.properties.DoubleProperty; | ||
| import xbot.common.properties.PropertyFactory; | ||
|
|
||
| public class TurnLeft90DegreesCommand extends BaseCommand { | ||
|
|
||
| DriveSubsystem drive; | ||
| PoseSubsystem pose; | ||
|
|
||
| double target; | ||
| double previousPos = 0; | ||
|
|
||
| @Inject | ||
| public TurnLeft90DegreesCommand(DriveSubsystem driveSubsystem, PoseSubsystem pose) { | ||
| this.drive = driveSubsystem; | ||
| this.pose = pose; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void initialize() { | ||
| target = pose.getCurrentHeading().getDegrees() + 90; //90 is the target not the error | ||
| // 150+90=240 .. 240-360=-120 might have to minus 360 to target | ||
| if (target > 180) { //target is out of bounds so bigger than 180. | ||
| target = target - 360; //since its out of bounds and bigger than 180, you have to subtract it by 360 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| //turn 90 degrees | ||
| double speed = pose.getCurrentHeading().getDegrees() - previousPos; | ||
| double power = target - speed; | ||
| double error = target - pose.getCurrentHeading().getDegrees(); | ||
| // higher distance error higher power,more power less speed ||| power = error - speed | ||
| drive.tankDrive(-power, power); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| @Override | ||
| public boolean isFinished() { | ||
|
|
||
| return false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⭐ ⭐ ⭐ same thing here |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐ ⭐ this is often where we would multiply error and speed by factors (p and d) so we can tune in different values for how hard it should be trying and how hard it should be braking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But will this code still work without the tuning?
The tuning will just be used for more advanced controlling right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could go faster in the simulator even by tuning the values, I'm honestly kind of surprised it's working at all right now as is.