Introducing BNSLib! An Advanced Programming Library from Team BNS

I’m proud to introduce BNSLib V0.13, an advanced programming library designed for RobotC!

What is BNSLib might you ask? This library offers powerful functionality not quite seen in Vex Robotics before, where advanced algorithms are implemented to help improve your autonomous performance! This is made possible by dynamically allocated memory designed within RobotC, allowing for easy implementation for machine-learning and probabilistic algorithms.

We have implemented the following:

  • Dynamic Matrix Operations (+ - * /, determinant, trace, and others)
  • Dynamically Allocated Arrays.
  • Kalman Filters.
  • Simple PID controllers.
  • Multivariate Gaussian Distribution Functions.
    and more machine-learning algorithms to come…

Currently, BNSLib V0.13 is compatible with RobotC 4.27 and can be used out of the box by filling in the Template.c file. See the Examples folder for how to use the library!

BNSLib is Open Source and be downloaded here.

Examples using BNSLib can be found here.

If you have any questions or comments concerning this library, feel free to comment below or email me directly!](

1 Like

Justin, this is really awesome!

This is very awesome. Currently studying it.

I guess that like me, the VEX community is more concerned with the PID part as it directly improves accuracy. Therefore I wonder if any more advanced integrated PID controllers are going to be built in. For instance, built in dual encoder error correcting drive, built in dual encoder gyro error correcting drive, built in gyro turn, built in mecanum error correcting strafe, lift control software like that of Jpearman, etc.

Also, a really nice thing would be a library of empirically tested PID constant library. For instance, a lot of teams use a mecanum base, all aluminum robot around 15lbs, dual encoder and a gyro. If some empirically tested out PID constants can be added to the library somehow, it would be absolutely amazing.

I would suggest that future development be focused on PID features. It is a necessity in Skyrise, and teams know that. I really admire GDC for designing such a revolutionary game in VEX history. However I still think that we need more open discussion about PID tricks, including common constant values, tuning, structuring, multitasking, etc. Comparing to massive amount of scissor lift discussion, PID is still more kept in secret. If BNS can use this library to improve the community’s knowledge of PID control, I will greatly appreciate your efforts.

Great job, thanks. ~ Martin, 3921B

Plus: if you guys want a new BNS member from Georgia Tech next year, I am here. :slight_smile:

Do you normally use all these algorithms?

That would make it TOO easy.


I think everything you mentioned are very good ideas. PID is definitely the most useful function for teams to understand. There was no intention for going much farther PID-wise, however I had some thoughts about creating acceleration-profiles for teams to use. Generally I see teams who PID to position, while I have found PID to control velocity with an acceleration-profile to be much more accurate. The motivation behind creating this library was to develop a core group of data structures and algorithms that could be used as a bridge to more complicated concepts, such as Kalman Filters and Normal Distributions. For that reason, I think what your saying seems like it would be a really good extension that utilized BNSLib. Unfortunately I don’t have the parts with me to do all the testing, hopefully that can be something that can be worked on sometime in the future though.

Yup :slight_smile:

Thanks for sharing. I never read about the Kalamn Filter, Median Filter, or Gussian Probability. I kind of remember going over the Gussian curve in Calculus, but we only spent five minutes on it.

Excellent job. I like how you organized the code and the github.

I am unfamiliar with how to assign the probabilities on the filters for Vex components. Ultrasonics and gyros seem to have lower probabilities at times while buttons, potentiometers, and quad encoders would tend to have higher probabilities.

Any stories on how you practically used these filters with Vex based robots?

How would you like comments and suggestions on the code? Just branch in github and go? Or do you want a discussion and a proposed change?

Merging elements of jpearman’s smart motor library would be cool too!

I would recommend checking out a site called Udacity, they have several REALLY good AI/machine-learning classes.

Specifically for Vex, I’ve found the median filter to be very useful for sonar sensors. They tend to give back crazy results at random (usually from bouncing over several surfaces), so the median filter tends to reduce these results getting fed into your program. While I haven’t tried it in Vex specifically, Kalman Filters are useful for combing the gyro & accelerometer data to get more accurate results and are good for localizing as well. PID is PID of course. There are more in the works atm, but I’ll talk about them when I get to publishing them.

For bugs, raise an issue on the github repo and fork/pull-request the fix if possible. For any major implementations/improvements, I believe it would be a good idea to discuss it here so that everyone is on the same page. You can always email me directly too if you would like.

Sure would be a cool addition to have

Excellent Job!!!