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

Auto-Balance Update 0.1 #3

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

Conversation

StabStabImAChicken
Copy link
Contributor

@StabStabImAChicken StabStabImAChicken commented Jan 19, 2023

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

- 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
Comment on lines 270 to 271
if(gyro.getPitch() != 0){
if(Math.abs(gyro.getPitch()) >= 5){
Copy link
Member

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?

Copy link
Contributor Author

@StabStabImAChicken StabStabImAChicken Jan 21, 2023

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;
Copy link
Member

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

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 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){
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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)

StabStabImAChicken and others added 4 commits January 22, 2023 13:45
- 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
@fruzyna fruzyna changed the base branch from protobot to main January 26, 2023 23:45
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.

3 participants