Autonomous Code Problems

I’m using an LCD in the competition template and can run my bot correctly through the field control. However, when I plug my controller into the competition switch and choose a program the left drive goes in reverse, right drive forwards, and the intake goes out, no matter which code I choose. This obviously is not supposed to happen. Does anyone know a correction or an error I may have in my code that would make it do that?

PS: Comp Saturday! D:

You have to post your code before we can help you find the problem.

See the attached file, I couldn’t copy and paste because character limit…

You mean the field control system (connected at competition) works but not the competition switch?

I will test it for you later, I didn’t see anything obvious in a 10 second look but with such a long autonomous task it’s hard to follow without a little cleanup and I don’t have time right now. Should have an answer for you by end of day.

Insert this code at the bottom of your code selection program:

displayLCDCeneteredString(0, "Selected:");
switch (count)
case 0:
	displayLCDCenteredString(1, "Front Red");
case 1:
	displayLCDCenteredString(1, "Back Red");
case 2:
	displayLCDCenteredString(1, "Front Blue");
case 3:
	displayLCDCenteredString(1, "Back Blue");
case 4:
	displayLCDCenteredString(1, "1 Min Auto");

It should allow you to see which autonomous you selected after you have finished the selection process.

Does the autonomous selection work as intended?

Your robot is doing exactly what the code is instructing it.

Lets look at the driver control code for the drive, here is the relevant part from usercontrol()

motor[LeftDrive1]   = -vexRT[Ch3];     // up = CW
motor[LeftDrive2]   = -vexRT[Ch3];     // up = CW
motor[LeftDrive3]   = -vexRT[Ch3];     // up = CW

motor[RightDrive4]  =  vexRT[Ch2];     // up = CCW
motor[RightDrive5]  =  vexRT[Ch2];     // up = CCW
motor[RightDrive10] = -vexRT[Ch2];     // up = CCW

and the motor definitions

#pragma config(Motor,  port1,           LeftDrive1,    tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port2,           LeftDrive2,    tmotorVex393HighSpeed, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor,  port3,           LeftDrive3,    tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port4,           RightDrive4,   tmotorVex393HighSpeed, openLoop, encoder, encoderPort, I2C_2, 1000)
#pragma config(Motor,  port5,           RightDrive5,   tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port6,           Mech1,         tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port7,           Mech2,         tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port8,           Mech3,         tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port9,           Mech4,         tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port10,          RightDrive10,  tmotorServoContinuousRotation, openLoop)

It looks like you have a 6 motor tank drive, 3 motors on each side, motor reversal is a bit messed up but that’s ok I guess.

Now lets look at the first few line of one autonomous routine.

if(alt == false)
    displayLCDCenteredString(0, "Front Red");
    displayLCDCenteredString(1, "is running!");
    wait1Msec(30);                      // Robot waits for 30 milliseconds

    //Tile 1    12-13


    while(SensorValue[I2C_1] < 300)

You are instructing the motor on port8 (Mech3) to run forwards, the motor on port2 (LeftDrive2) to run forwards (but normally you would send it negative values so it actually runs backwards, see the driver control code) and the motor on port4 (RightDrive4) to also run forwards. You are not instructing the other four drive motors to do anything at all.

Does that make sense?

What the problem is, my autonomous codes will run like shown when it is plugged in through the field control.
for example:
port2 = left drive
port4 = right drive
port8 = intake

In field control it does:

^^ This is what makes the intake go in, and the bot to move straight forwards

only whenever I plug in to the competition switch (the black box with switches) it seems to be doing this:


^^Making the intake go out, and the robot to spin counter-clockwise.

This is not what my code is telling it to do, so why would it do this at all?
And why would it only do this when plugged into the competition switch and run normally when in field control?

I ran the code with a competition switch and I don’t see any problems, motors are doing what they are commanded to do.

So you only have one motor on left and right sides of the drive ?

Which version of ROBOTC are you using?

Which version of the master code are you using ? ie. did you upgrade to V4.0 or are you still on 3.23 (don’t upgrade, bad idea I’m finding out)


I do see some big issues with driver control. It looks like you used a hacked version of the ROBOTC default code. For example, you left in the motor reversal code.

        bMotorReflected[LeftDrive1]   = (bool)SensorValue[jmp1];
        bMotorReflected[LeftDrive2]   = (bool)SensorValue[jmp2];
        bMotorReflected[LeftDrive3]   = (bool)SensorValue[jmp3];
        bMotorReflected[RightDrive4]  = (bool)SensorValue[jmp4];
        bMotorReflected[RightDrive5]  = (bool)SensorValue[jmp5];
        bMotorReflected[Mech1]        = (bool)SensorValue[jmp6];
        bMotorReflected[Mech2]        = (bool)SensorValue[jmp7];
        bMotorReflected[Mech3]        = (bool)SensorValue[jmp8];
        bMotorReflected[Mech4]        = (bool)SensorValue[jmp9];
        bMotorReflected[RightDrive10] = (bool)SensorValue[jmp10];

But you are also using some of these as outputs.

            if(vexRT[Btn7U] == 1)         // If button 7U (upper right shoulder button) is pressed:
                SensorValue[dgtl7] = 1;  // ...activate the solenoid.
            else                          // If button 7U (upper right shoulder button) is  NOT pressed:
                SensorValue[dgtl7] = 0;  // ..deactivate the solenoid.

            if(vexRT[Btn7D] == 1)         // If button 7U (upper right shoulder button) is pressed:
                SensorValue[dgtl10] = 1;  // ...activate the solenoid.
            else                          // If button 7U (upper right shoulder button) is  NOT pressed:
                SensorValue[dgtl10] = 0;  // ..deactivate the solenoid.

Using these will reverse some motors (which you may not be using). Probably nothing to do with your autonomous problem but it would be worth cleaning all this up.

We have a y-splitter on the base to two motors, on each side of the drive.
Port 2 controls the left drive’s motors, and port 4 controls the right drive’s motors. Also we have not updated the latest version of RobotC.

Btw, it’s not the driver control that is messing up, it is the autonomous. What we did was used the default driver template, and edited it to where it worked for our bot, then copied that into a competition template with the ldc code that team 6135A from my school used. It works fine for them, but as I said before, when its plugged into field control the auton works normally, but when its through the competition switch it “freaks out”.

Ok, that makes more sense, I couldn’t figure out how you were running with a 2 motor drive on a competition robot.

Ok, but what version is it, I’m not on the latest either but I’m trying to duplicate your environment.

Ok, I’m just looking for unusual behavior and that stood out.

I’m not sure where to go from here, perhaps I will send a simplified version for you and we can go from there.

Okay, thanks so much.

Before you clean it up too much i just figured you should know:

port2 = left drive
port4 = right drive
port6 = arm (left)
port7 = arm (right)
port8 = intake
port9 = omni

and we need all the digital sensors like they are, along with analog.

Try a really simple autonomous like this.

task autonomous()
    // Clears the LCD.

    displayLCDCenteredString(0, "Test Code  ");
    displayLCDCenteredString(1, "is running!");

    // run motors


    // stop motors

    // block until task stopped

It just runs the three motors for 2 seconds.

Because you are using the modified default code, it’s a little hard to decipher everything thats going on as I don’t know if you have jumpers and things like that installed that would change behavior in driver control (and yes I understand driver control is not the issue). I wonder if under field control the driver control code briefly runs and sets something that will not happen with the competition switch (which is not what I would expect but it’s the only theory I have to go on right now).

When you try the autonomous above check what happens to the motors in the ROBOTC debugger as well as on the robot.

I can’t right now, my bot is at school. I will be with it in two classes, and stay after school for about 4 hours to work on it, so I’ll be able to test it then.
I’ll get back to you on what happens.

It is doing the same thing, it just goes for 2 seconds now instead of running forever.

Try running driver control first, switch to driver, enable then disable, switch to autonomous and then run it.

What jumpers do you have installed in the analog and digital IO?

No jumpers used

So I cleaned up the driver part of the code like you suggested, and after some tweaking it works! :smiley: I deleted the "(bool)"s and I think that was it. Thanks!