-
Notifications
You must be signed in to change notification settings - Fork 0
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
Auto-Balance Update 0.1 #3
base: main
Are you sure you want to change the base?
Conversation
- Added a driveType in SwerveDrive.java called AUTO_BALANCE - When the robot is in AUTO_BALANCE, robot will move at an xSpeed based upon it's pitch times 2 (for example, with a pitch of -15, the robot will move at an xSpeed of -30)
- Changed AUTO_BALANCE to move bot when Math.abs(getPitch()) is greater than or equal to 5, instead of less than or equal to
- The previous version of AUTO_BALANCE only checked the pitch of the robot and adjusted the xSpeed. Now, the robot will check it's roll as well, as adjust it's ySpeed accordingly (in the same manner xSpeed was changed)
- Swapped ySpeed and xSpeed. I mixed them up before
- Added else statements to both if(Math.abs(gyro.getPitch()) >= 5) and if(Math.abs(gyro.getRoll()) >= 5), so that the speeds are set to 0 while within 5 degrees of angle. - Added setDrive() and drive() at the end of AUTO_BALANCE
if(gyro.getPitch() != 0){ | ||
if(Math.abs(gyro.getPitch()) >= 5){ |
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.
What happens if the pitch/roll goes directly from 5 to 0?
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.
As the code sits now, the speed would not change. I should fix the != 0 part. Thank you
if (driveState == driveType.AUTO_BALANCE){ | ||
if(gyro.getPitch() != 0){ | ||
if(Math.abs(gyro.getPitch()) >= 5){ | ||
ySpeed = gyro.getPitch() * 2; |
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.
A minimum speed of 10 sure is fast
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.
I didn't have an accurate reference for how fast the different speeds are, so I just thought 10% of maximum speed would be pretty slow. Stuart suggested a speed of 30 should be our top speed on the ramp, so I assumed it was slow
- Removed if(gyro.getPitch() !=0) (and the same if statement for .getRoll()) as they were redundant and could cause the robot to move while pitch or roll is at 0 in some cases. - Slowed speed to a minimum of 2.5 and a max of 7.5 - Made code a little more readable, and added a comment above setDrive() explaining why roll and gyro are set to 0
@@ -266,6 +266,24 @@ public void update() { | |||
this.swerveSignal = swerveHelper.setDrive(xSpeed, ySpeed, rotSpeed, getGyroAngle()); | |||
drive(); | |||
} | |||
if (driveState == driveType.AUTO_BALANCE){ | |||
if (Math.abs(gyro.getPitch()) >= 5){ |
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 may not matter, but it probably is better to get and store the pitch/roll rather than query the gyro up to 6 times.
Ultimately gyros should be in hardware as inputs to prevent this issue, but that's not part of this task. On that topic we are using the Pigeon 2 this year which uses a different API. Not sure what the state of switching to that is.
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.
Looks like you are behind main, API calls should be identical so you should just have to pull in those changes.
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.
Also created wildstang/robot_framework#19 (this is probably an offseason task)
…023_111_robot_software into Shane_Auto-balancing
- gyro.getPitch() and gyro.getRoll() are now stored in gyroPitch and gyroRoll, respectively, to not have to call from gyro multiple times. I plan to move these to a separate function in the future
Subsystem: swerve
Description:
Added a driveType in SwerveDrive.java called AUTO_BALANCE. When the robot is in AUTO_BALANCE, robot will move at an xSpeed and/or ySpeed based upon it's roll or pitch (respectively) times 0.5 (for example, with a pitch of -15, the robot will move at a ySpeed of -7.5)
Tested: No
Collaborators: Only myself, @StabStabImAChicken