Question on RobotC Intrinsics

Every once in a while I am at a robotics event and get drafted into helping debug non nominal behavior. There have been a few times I never could get to the root cause and help a team to compete. This last weekend at the BEST robotics practice day in Denver I had ‘almost’ another one of those issues. In the end I found out the correction but I am still stumped as to the cause. Fortunately this is a reproducible bug and I have a program I tested today which can reproduce it. I was wondering if anyone with a thorough understanding of Robot C could help explain what causes this and I thought I’d like to share it because I’m sure others have run into similar situations.

First the student was using RobotC I believe the latest 4.x version although I didn’t check the version at the time. I am still using 3.6.5 and I had the same experience. I’ll post the code below, They had a simple arcade style drive working and wanted to add arm motion (up and down) based upon pushing the buttons 7U and 7D on the controller. So I helped them set up a simple program to get started and planned to provide suggestions on where to make improvements however we found that given the code below the Arm would move down but not up unless a drive motor was commanded at the same time. So after much staring at the very few lines of code and testing and re-coding on my own laptop with RC 3.65 … aha I found the problem the student used a lower case letter b for the vexRT[Btn7U] line. when correcting the typo the program ran exactly as I expected. My Questions are…
Why does the compiler not give any kind of error warning? in so many other places RobotC ‘corrects’ things for the users.
What is really happening when a lower case b is placed in the line? If I use the 'go to definition ’ function I am taken to a section of RobotCIntrinsics where the enum is typed with a lower case b…

Anyway here is the code and if you replace vexRT[Btn7U] with vexRT[btn7U] the arm motor will drop but never raise (in this example) unless the drive motors (push the joystick) are driven. If there is some signal to the Ch1 or Ch2 inputs the arm will travel in either direction based upon pressing btn7U or the Btn7D.

#pragma config(Motor,  port2,           armM,          tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port5,           leftM,         tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port6,           rightM,        tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int ch1Val,ch2Val,button7U;
task main()

while (true) {
    ch1Val = vexRT[Ch1];
    ch2Val = vexRT[Ch2];
    button7U = vexRT[Btn7U];

    // simple arcade style driving
    motor[leftM] = (vexRT[Ch2] + vexRT[Ch1])/2;
    motor[rightM] = (vexRT[Ch2] - vexRT[Ch1])/2;
    if (vexRT[Btn7U]) { // this is where the typo occurred i.e. vexRT[btn7U]  
        motor[armM] = 60; // move up
        } else if ( vexRT[Btn7D] ) {
         motor[armM] = -60; // move down
         } else {
        motor[armM] = 0; // stop


Here’s what comes up if I use a capital B or lower case b and choose ‘go to definition/declaration’ in the IDE
in the file RobotCIntrinsics.c I am taken to btn7U below

  typedef enum
		btn5D             = 0x0001,    // Button Group 5, Up
		btn5U             = 0x0002,    // Button Group 5, Down
		btn6D             = 0x0004,    // Button Group 6, Up
		btn6U             = 0x0008,    // Button Group 6, Down

		btn7D             = 0x0100,    // Button Group 7, Down
		btn7L             = 0x0200,    // Button Group 7, Up
		btn7U             = 0x0400,    // Button Group 7, Left
		btn7R             = 0x0800,    // Button Group 7, Right

		btn8D             = 0x0010,    // Button Group 8, Down
		btn8L             = 0x0020,    // Button Group 8, Up
		btn8U             = 0x0040,    // Button Group 8, Left
		btn8R             = 0x0080     // Button Group 8, Right
	} TButtonMasks;

Which as I post this seems to map btn7L to UP (per the comments) and btn7U to the left button (per the comments) I have found the bottons work as expected when using Btn vs btn

Cheers Kb

As far as I can tell, they (the lower case version from the enum TButtonMasks) are a historical remnant of some previous version of the code. I don’t see that they have any useful function anymore. My assumption would be that they were once used when button data was returned as a 16 bit integer with a single bit per button, you would mask that data to detect which button had been pressed.

Perhaps we can remove them from a future version.

Thanks James,

When I comment out the enum declaration I get a prompt that Robot C is swapping ‘Btn7U for btn7U’ I expect that was the issue. I’ve saved the intrinsics.c file witht he change.

Can you explain the difference between #define VEX and #define VEX2? Seems I knew once but have forgotten.

Cheers Kb