PSA: Balance in auto

After watching many of the week 1 events, it seems a lot of teams did either nothing in auto, scored a piece and stayed put, tried to get mobility and got a penalty, or successfully got mobility but got in the way of other potential autos.

This lead me to the theory that auto balancing is not only easier than mobility, it is more accessible too.

So we set out to write a simple auto balancing routine that uses no sensors except the built in accelerometer on the RoboRIO, with no PID, and is simple and quick to tune. Works for RoboRIOs in any orientation (although RoboRIOs mounted high off the ground may experience more acceleration).

Here it is: GitHub - FRC3683/OpenAutoBalance: Autobalancing is easy, safe, and fun for the whole FRC family.

Here is a video of it working: Open Auto Balance example - YouTube

Why should you use this?
Automobility is hard to do in a way that is both alliance partner friendly in terms of not touching game pieces and also not getting a penalty for crossing half. There just isn’t a good window of time or angle that reliably gets this done. Even if you do its worth 3 points. Scoring one game piece low and balancing is worth 15 if you engage, and 11 if you are just docked, and the endgame balancing requirements for RP is the same if you dock but don’t engage. The whole thing can easily take less than 10 seconds. It’s very easy to tune by changing these parameters:

It is easy to implement in any project:
Initialize like this:
image
Use in autonomous:

There is also a variant that only balances if you want to run your own scoring sequence first:

Enjoy! (don’t enjoy the light theme editor though)
Any questions are welcome.

67 Likes

Forgot a python implementation :wink:

5 Likes

Thank you for this example! I implemented it into the 2023 Everybot code to help a local rookie team and thought I’d share it here for Everybot teams: GitHub - IsabellaHaladjian/Everybot2023-Modified: Modified 2023 Everybot Code

10 Likes

Me and another team at the competition I’m in are having some difficulties trying to get it to work in command based structures can you show an example of how to get it working in command based?

I believe it should be as simple as creating an autoBalance object in your command. And then in execute(), call it like the other example, make sure you set your motors to the speed. I didn’t in the example below because I wanted to give you a quick answer.

Latest commit has a fix for a spelling related syntax error

So I have it basically exactly the same as you just slightly changes setSpeed() command due to our drivetrain. I have also just changed the autoBalance to extend SubsystemBase. It will drive the right side but the left doesn’t move.

image

1 Like

You mentioned one side moving but the other wasn’t. In your code you give the same values to both sides. Maybe the issue lies somewhere in the motor controller you are writing to. What happens if you just put a constant like 0.2 in your left side motor write. Make sure the wheels are off the ground when testing. Does the left side spin?

1 Like

I got both sides doing the same now I don’t remember what I did to do it but I am still getting a motorsafety saying that it isn’t updated often enough. Every other drive based command we have works I think it may be something with the setSpeed command.

If I recall, motor safety happens if you don’t when a motor write doesn’t happen every frame. Could be caused by the score and balance being expensive. Latest commit should have more efficient code

Robot.java (2.6 KB)

I made a new timeBased specifically to remove all variables no longer have a motorSafety however it only twitches the wheels. I should also note our rio is mounted vertically and upside down.


Having a motor write in your RobotPeriodic, and another in autonomous periodic will do this. Every frame you are setting the motor to a value and setting it to zero, causing twitching. Move the contents of this function to TeleopPeriodic

Ok so update, made the change to teleopPeriodic and was able to put the values in smart dashboard had to change the tilt by about 95 degrees and it now slows when lifted have yet to put it on the charge station for full test but appears to be functional just a small problem when in autonomous it causes motorSafety errors. However in teleop we have no motorSafety errors.

1 Like

I will look into MotorSafety, let me know the results of your test

1 Like

Since the finals are happening we won’t be able to get it tested before we leave as there is too much going onto get a robot through to the test field.

1 Like

What does the * 57.3 represent?

1 Like

It’s a unit conversion from radians to degrees.

1 Like

Oh, ok. Did we round it instead of multiplying 180/pi for the sake of efficiency?

Try dividing 180 by pi and see what your answer is?

That’s just not rational :wink:

6 Likes