UNIVERSAL_ROBOTC : Intro

Universal_ROBOTC was developed in order to make programming in the RobotC environment less complicated and straightforward for beginner and expert programmers alike. The cool part about the Universal ROBOTC library is that it gives the illusion of using classes. Why is this interesting? The C language does not support classes. So how is this possible? In RobotC, there is a data type known as a struct. It is basically a combination of variables. To understand this think of it like this: The data type is a dog. A dog has a head, four legs, a body and a tail. The different parts of the body is what makes up a dog, but these parts can be seen as different from eachother. That is how a struct works. A class is similar except that our dog could do actions such as fetch, run and eat. What is cool about these data types are that they can be user defined. Therefore you can have multiple instances of each. Remember C does not support classes. So we have a very lame dog that can only store data, not very helpful since we are trying to program a robot to do something! The answer is quite simple, just create a user defined library that relies on these struct structures, and boom you have yourself a fake class. However, it truly isn’t a class nor is it real OOP programming, it’s just simulated and seems that way.

Now that we have a rudimentary understanding on how the Universal_ROBOTC library works, let’s run through an example. Let’s say we want to create just a simple program to run 4 motors for five seconds. Traditionally we were forced to do this:

Of course you could create a nice little function for recurrences of this scenario, however you would only be limited to using four motors and those motors would have to always be the same motors. The solution using the Universal_ROBOTC library is less messy. Here is an example:

The advantage is that the program stores the motors you’re using and has functions to do things with the motors and you are not limited to just four motors. You can have no motors or you can have up to ten motors. I am not going to go into detail about how this is possible, but function overloading is definitely used along with a for loop.

Stay tuned for more tips and tutorial on how to use this library! The next one will be on using sensors with Universal_ROBOTC library.