Open Curtain
Act 1: Satus
In this world filled with divine comedy, individual shows are played out each day. Here begins my progress report for 2/5/2024 regarding the issue of our team’s swerve drive.
Monday: The Rise of Darkness (1/29/2024)
I will begin by defining the problem. Our swerve modules are built and wired dubiously, but that’s beyond the fact. The problem with our code is the alignment of the wheels. Because the wheels and the motors could not be installed in the same orientation, it is up to us poor programmers to fix the sins of the father and right these wrongs. We use angle offset variables in our code to change the starting orientation of the wheels in our code and apply them constantly so that the wheel pretends like it knows where it is and moves accordingly with respect to where it should be. While this should work in theory, however, our wheels were not moving (Monday). After sifting through gilded towers filled with 1s and 0s, we discovered that we weren’t actually applying our offsets at all. With our target in sight, we applied the offsets to the optimized angle, and to our getAngle and setAngle method (I’m sure you guys know what those methods do). With our hearts lightened, we ran the code, expecting victory. What we found was much more shocking.
Wednesday: The Unfading Void (1/31/2024)
Our motors started spasming back and forth, like an overstressed student faced with several tests.
Flip flop issue
After doing some investigative journalism, we realized that this was not feasible for the robot, and reverted our changes a bit, returning to an age before the darkness. At the same time, we found some other team’s code, and took inspiration from their work, seeking to fix our problems. Through our relentless efforts, we discovered the fact that we should not try to offset our optimized states, rather, our current position only. However, this all comes to head today.
Thursday: The Tower’s Fall
Today the kitchen was opens, the tools were laid out, and the meat was done marinating. I cooked quite a bit. I started by analyzing the Rev code repository. As I looked at where the angle offset was being applied, I realized that it was only being applied in three places, one of which didn’t do anything.
The third place it was being applied was in the getState command, but because that command wasn’t being called outside of where it was defined, I have no included a screenshot of it.
Like a good programmer, I copied their technique and applied the offset in the same way to our code.
This worked out, but in a very strange way. Although all the wheels now point the same way, and drive, but after driving for a bit, they decide to point in all different directions. On top of that, the turn commands on the right joystick didn’t work.
I believe that this problem has to do with our PID constants, and accumulated error, which may be due to PID or the optimize function not working correctly. However, progress was made today. Despite our obstacles a match was struck, our path is lit, and our hearts are ready to face the darkest dungeon.
Friday: The Return of The Light (2/2/2024)
I’ve been doing some more investigative journalism, and I’ve noticed something. I don’t think the odometry drive and turn positions thing matters. I’ve tested Akash’s code and it doesn’t matter whether or not the offset is there. Rather, I think the offset matters when the setpoint is run. Looking at the Rev Swerve code, as I said above, the offset is being applied in two places, the getPosition itself and the setting the position it wants to go to (remember that getState doesn’t exist in the code outside of where it gets defined). However, something funny occurs here. The getPosition and setDesiredStates methods interface with each other
So me and Akash Dubey did some cooking during 5th and 6th periods. After looking at the code again and trying some various fixes, we decided to open Advantage Scope (a program that we use to look at the state of the robot). As we started at the shifting numbers and dials, Akash noticed that some of the swerve modules weren’t matching up with their location on Advantage Scope, so we changed around the motor IDs a bit. Turns out that fixed the offset problem as well as the turning issue. However, the robot is driving a bit of a weird angle. Might be because it’s field relative. Further reading of code is required. (HI This is zzhao1 from the future. The code is not in field relative right now. I will touch upon this a bit later in the Act and in Act 3
Sliding around and catching - IMG_3960.MOV
Video of it working at the very end - IMG_3961.MOV
INTERMISSION
Use this time to grab a drink and snack. Our story is just beginning
INTERMISSION FIN
As we move to Saturday (2/3/2024), our endless struggle continues. As Akash had brought up earlier, the issue we were facing could potentially be a PID issue, so we decided to get sysID working. sysID, aka system ID, is used to find the specific PID constants to run our wheels with. For those who do not know what PID is, it stands for Proportion, Integral, Derivative, and is used to move motors to accurate rotations. The reason we need this for our drivetrain is because our motors need to all spin in the same orientation and rotation in order to effectively drive the robot, and thus must be kept accurate to produce effective results. Before we could do sysID, we had to ensure our offsets worked, and worked they did. Offsetting the desiredstate and the getPosition opposite ways worked, and with our motor controller IDs switched around, we were balling. As we were staring at Advantage Scope, Akash had a startling realization, our odometry wasn’t being properly updated. This means that fieldRelative driving won’t work (I’ll come back to this). Our righteous crusade would have to come to rest for a moment though, as our build subteam required the robot to fix its belly pan. As they toiled with their fancy tools and grinding machines, Akash and Sam combined their minds to calculate equations to find the angle at which to shoot from. Using their combined knowledge and the power of Desmos, they created a calculator that would relate the position of the speaker relative to the robot. Linked here, it is very handy (and is a surprise tool that will come in handy later). As time progressed, the robot was no closer to being done. In fact, it had only regressed its status, turning from a temporary chassis into no chassis at all. Mobilizing, Jace Lopez, Akash Dubey, William Kimmel, and Michael Sisoev sprung into action, disassembling the swerve modules and replacing them with the pinions required for the highest speed, as well as taping up the bars, ensuring that no empty space remains. As the meeting wrapped up, we affirmed our vows and returned to our respective abodes, ready to face the horrors of the future.
Wednesday: Shadows (2/7/2024)
Each day brings a fresh new battlefield. After some robot testing, I discover that the absolute encoder wire connectors have all fallen out due to the robot spinning. The WIFI power port connection also wasn’t connected, which was honestly a small miracle that the I was able to connect to the robot at all. To remedy this situation, I zip-tied the encoders onto the motor controller and rewired the WIFI power port , expecting the problem to be fixed, but with a solution comes fresh problems. By zip-tying the encoder connections down, apparently that someone changed the angle they were plugged in at, which caused the motor to lose track of where it was. With this lesson in mind, I resolved to drive the robot more carefully. After another couple minutes of testing, I realized that the offsets were being applied in the wrong direction, so I decided to re-zero all of the swerve modules, to ensure they would be pointed in the right direction. Halfway through the zeroing process however, I neglected to follow my own labels, and had zeroed all the motor modules in the wrong direction. Hastily undoing my error, I resumed testing, and discovered that trying to drive the robot forward would only spin the turning motors without actually moving the wheels. Running the code again, the spinning issue fixed itself, but the wheels stopped turning. With time running short, I tactically fall back, leaving the issue for another day.
Thursday: The Birth of Hope (2/8/2024)
All of the swerve problems fixed themselves overnight. Sometimes when logic fails, faith prevails. Though I cannot explain why it’s fixed, what matters is that the swerve drive works. However, one small problem remains. Our wheels’ angle in robot relative drive is slightly off, despite field relative working. This might be a sysID issue, or the wheels themselves could be installed wrong, though that remains to be seen. The robot drives, and that’s all that matters.
The Mountain
Our robot still a long journey to complete before it can compete, programming wise. Swerve must be tuned, vision must be calibrated, and physics simulations must be completed. However, a journey of a thousand miles always begins with a single step. With the robot’s drivetrain working, we are ready to brave this darkest dungeon.
Act 1: Fin
Written by Zandy Zhao @Swordman51