I am by far the most advanced programmer in my robotics club, but I still feel like there has to be a much better way to do some of the things I have accomplished on my robot.
Code is written in C++ with VEXcode Pro v5
I’m no veteran, but I have done quite a bit of coding for Vex. I’ll write things as I notice them.
Use multiple files to separate your code into smaller sections. For example, you might separate your code into drive functions, shooter functions, autons, usercontrol, and main.
You don’t really have any control methods for driving or turning. Consider using a PID controller or just a P loop to increase the accuracy of your autos.
I think half the code I’m seeing is just to check whether the drivetrain is overheated. Take all that out and fix your drive physically so it doesn’t overheat.
If you’re feeling adventurous, maybe try out the JAR-Template:
It’s for VexCode and requires you to use a gyro. That’s about it.
Okay, I have to pick on this. It is technically true, but as someone who has reviewed a LOT of code at this point, doing this can actually lead to harder-to-read code. Why? Because when you start shortcutting with true statements, you’ll get into the habit of doing the shortcut for false statements.
I can tell you completely from experience, when your code has developed some weird bug and you’re in a time crunch, it’s VERY easy to miss the intent of the code if you’re reviewing as an outside source (or even reviewing code you write couple weeks/months/years ago).
Be intentional about what your code is saying if the language allows it. It will save your sanity some day, I promise.
Also, do it because the compiler won’t care, it assembles to machine instructions in the same way; improved legibility code makes everyone’s life easier.