Team 2442A Code Reveal

Not exactly a robot reveal, but I thought that, as my final season is over and done, I might as well show the community what I’ve been working on for the better part of my four years here. Our code has seen many iterations throughout the years, and I feel that its present state is the best I’ve ever seen it. There are two repositories I have to share.

The first, BCI (Bulldog Core Includes), is our core library that provides all the tools we need to program our robot. Everything we have that gets used in competition is built using this library. Check it out here. I have provided this library as open-source under the MIT license, and I welcome collaboration.

The second, our main code, is the higher level code we actually load onto our robot. Check it out here. Although I am releasing the source for this on GitHub, I will not accept any new commits as this repository is more of an archive at this point.

These two repositories are provided as-is for whatever purpose one may see fit. I (probably) won’t document anything past the header file documentation already in place, but I will answer the questions I can.

Thanks for sharing!

I think most beginner teams would have a very difficult time understanding this. It’s gigantic and has pointers and ternary operators all over the place

Your robot was very impressive at the tournaments, especially at the December one compared to everyone else’s. Sad to see you go, Southern New England is losing a good competitor. Hopefully we will continue to grow as a region. Your code is also very impressive. Good job!

I agree that most beginner teams (beginner programmers, that is) will have some difficulty understanding this code at first glance; however, knowing how a program works and how to use a program are two different things. I believe that I have created something that can be used without the knowledge of how it works. Again, the purpose of this library is to provide the tools used to build the higher-level systems one programs a robot with (for example, driving and turning functions for autonomous). I would also like to note that this library is not exactly targeted at programmers who do not know how to use pointers because I have assumed that the end users of this library understand the core concepts of C.

I have often thought about documentation, but I don’t have the time nor a standard to conform to that would make clear and efficient documentation possible. I am, of course, open to feedback and questions.

Thanks for the kind words. I’m not exactly gone yet as I’m helping our sister teams B & C build and program their robots and will be attending worlds with them, but I think that will be it for me. Unless Tabor or someone else at WPI manages to convince me to do Vex, I think I’ll be done with competitive robotics for the foreseeable future.

I opened it, my brain broke.

On a good day I can read it like English, but after 3 hours of sleep…nope…

Perhaps another day. I personally apologize for line 49 of motorControl.c. I wanted to compress the logic onto one line, but at what cost?

Thanks for this! I didn’t have enough undocumented code to look at with my team’s 16 GitHub repositories. Actually though, this will help me get better at reading high-level code, and I’m always looking for styles other than mine and that of my mentor/partner/dude (we need official titles =) ). I’m a little confused by some of your pointers and stuff, but I only looked at it for about 30 seconds, and I’m not totally comfortable with pointers yet.

This will be great to have going into the next season, thanks!

If it weren’t for the comments that would be a bad idea. Generally you want readability over conciseness, and in this situation you don’t gain anything other than a line or two by making it into the less readable form.

Other than that though the code looks great, thanks for sharing!

This code is very impressive. I was wondering where or how you learned to apply complex C concepts into RobotC and how a program like this is uploaded to the robot itself.

I’ve been programming in a variety of languages for around five years now, so going through basic RobotC tutorials and learning the limits of the language let me know what I was dealing with. I don’t try to specifically apply one concept or another, but instead view my knowledge of programming as a tool set that I can use to solve problems. Coding our robot this year was a challenge at times, and I often sat down to think about the problem at hand and implemented the best solution I could come up with.

The process of downloading this code to a robot isn’t different than any other program, I just hit the “Download to Robot” button in the RobotC IDE. If you’re wondering how I link together files, that’s just done with the C-style “#include” system. It is important to remember that RobotC does not have a linker (devs pls), and as such all code is placed into a single monolithic file using “#include” statements; therefore, you need mentally designate one file as your main file, which will be compiled and downloaded to the robot. For reference, the file “EntryPointCompV2.c” is our main file in our main code repo.

In addition, the RobotC IDE has a handy compiler feature which lets you add search directories, which is how I added my BCI library to my projects, while keeping it in a separate folder. This way, I didn’t have to navigate my local file system in my “#include” statements.

You just include the library like you would any other files and then download normally using ROBOTC.

Hey I know this is a little late, but i was trying to implement your code and I continue to get an error for a #include in the file “autonFunctions.c”. The issue is that RobotC can not find the file “collisionVector2f.c”. I didnt know if you could show me where this file was located because the “core” folder in the “modules” folder is missing. Thanks!

Sorry about that, that code is so old that the file you are looking for no longer exists in BCI. It was just a simple structure to hold a couple values for me so I could return more than one value at once. The entire collision recovery system I wrote was never tested though, so beware. It seemed to work on paper, though.

I know I shouldn’t delete old code and instead deprecate it, but I figured that nobody was using BCI at the time and so my edits would be fine. This type of issue won’t happen in the future, though, so don’t worry. The current version of BCI is good to go. If you have any other questions about how the code works, feel free to ask.

Okay so could the new BCI code be implemented with your autonomous functions that you used last year. I am trying to use those functions such as a way to code an autonomous for this season.

Sure it could, but I’ll do you one better. Here’s the code my team is using this year to drive and turn:
driving
turning

Remember that you’ll have to come up with your own values for the conversion value they use (lines 18 and 17 in the two files, respectively). These are specific to your robot.

Awesome! To use this code I would just #include it in my main code right? Then reference the specific function in auton?

Yes, assuming you have already included the appropriate modules from BCI. This code depends on pos_PID and timer, so you’ll have to include BCI before you include those two files I gave you like so:

#define BCI_USE_TIMER
#define BCI_USE_POS_PID
#include "BCI\BCI.h"