competition control

Hey guys,
I have a single flywheel that runs absolutely wonderful until I plus in a competition control wire for a competition. The joystick mapping gets messed up and a regular toggle is taken as a forever loop, and simple motor assignments are taken as toggles. On top of that we kept on burning out.
The problem is immediately after we unplugged the wire, the flywheel would actual perform wonderfully, not burn out, and map the joystick wonderfully.
Does anybody know why this is happening and how to fix it.
David

There’s no reason why competition control would affect your code that way unless there are errors in the code, can you post here for us to look at?

Okay here is the code.


#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           treadmill1,    tmotorVex393HighSpeed_HBridge, openLoop)
#pragma config(Motor,  port2,           frontRight,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           backRight,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port4,           frontLeft,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port5,           backLeft,      tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port6,           tlLauncher,    tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           trLauncher,    tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port8,           brLauncher,    tmotorVex393HighSpeed_MC29, openLoop, reversed, encoderPort, I2C_2)
#pragma config(Motor,  port9,           blLauncher,    tmotorVex393HighSpeed_MC29, openLoop, encoderPort, I2C_1)
#pragma config(Motor,  port10,          treadmill2,    tmotorVex393HighSpeed_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(105)
#include "Vex_Competition_Includes.c"
//#include "SmartMotorLib.c"

int count = 0;
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;


//Subroutine to stop all motors
//void stop()
//{
//	motor[port2] = 0;
//	motor[port3] = 0;
//	motor[port4] = 0;
//	motor[port5] = 0;
//	motor[port6] = 0;
//	motor[port7] = 0;
//	motor[port8] = 0;
//	motor[port9] = 0;
//	motor[port10] = 0;
//}

void waitForPress()
{
	while(nLCDButtons == 0){}
	wait1Msec(5);
}

void waitForRelease()
{
	while(nLCDButtons != 0){}
	wait1Msec(5);
}

string mainBattery, backupBattery;

void pre_auton()
{
	//Initialize Smart Motor Library
	//SmartMotorsInit();
	//Start Smart Motor Library
	//SmartMotorRun();

	clearLCDLine(0);
	clearLCDLine(1);
	while(nLCDButtons != centerButton)
	{
		bLCDBacklight = true;
		switch(count){
		case 0:

			displayLCDCenteredString(0, "Placeholder");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();


			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}

			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;

		case 1:
			displayLCDCenteredString(0, "Placeholder2");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}

			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;


			displayLCDString(0, 0, "Primary: ");
			sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V');
			displayNextLCDString(mainBattery);

			displayLCDString(1, 0, "Backup: ");
			sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V');
			displayNextLCDString(backupBattery);

			wait1Msec(100);

			waitForPress();
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count = 0;
			}
			break;
		default:
			count = 0;
			break;
		}
	}
}

task autonomous()
{
	//	motor[port6] = 10;
	//wait1Msec(1000);

	//motor[port7] = 10;
	//	wait1Msec(1000);

	//		motor[port8] = 10;
	//	wait1Msec(1000);

	//	motor[port9] = 10;
	//	wait1Msec(1000);

	//	motor[port6] = 20;
	//	wait1Msec(1000);

	//		motor[port7] = 20;
	//	wait1Msec(1000);

	//		motor[port8] = 20;
	//	wait1Msec(1000);

	//	motor[port9] = 20;
	//	wait1Msec(1000);

	//		motor[port6] =  80;
	//	wait1Msec(1000);

	//		motor[port7]= 80;
	//	wait1Msec(1000);

	//		motor[port8] = 80;
	//	wait1Msec(1000);

	//	motor[port9] = 80;
	//	wait1Msec(1000);
	//	repeat(forever)
	// {
	//motor[port6] = 123;
	//motor[port7] = 123;
	//motor[port8] = 123;
	//motor[port9] = 123;
	//motor[port1] = 127;
	//motor[port10] = 127;
	//	}
}
task usercontrol()
{

	int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
	bool on47 = false;
	bool on60 = false;
	int count = 0;
	while(true)
	{
		bLCDBacklight = true;
		displayLCDString(0, 0, "Primary: ");
		sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V');
		displayNextLCDString(mainBattery);

		displayLCDString(1, 0, "Backup: ");
		sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V');
		displayNextLCDString(backupBattery);


		//took these if statements as toggles so if I pressed it I didnt have to hold it. Everything also changed as soon as I went to skills.

		// half court shooting
		if(vexRT[Btn7L] == 1){
			motor[port6] = 59
			motor[port7] = 59
			motor[port8] = 59
			motor[port9] = 59
		}
		// full court shooting
		if(vexRT[Btn7U] == 1){
			motor[port6] = 72
			motor[port7] = 72
			motor[port8] = 72
			motor[port9] = 572
		}
		//stop
		if(vexRT[Btn8R] == 1){
			motor[port6] = 0
			motor[port7] = 0
			motor[port8] = 0
			motor[port9] = 0
		}
		// just for faster acceleration
		if(vexRT[Btn8D] == 1){
			motor[port6] = 127
			motor[port7] = 127
			motor[port8] = 127
			motor[port9] = 127
		}


		//boolean if statements
		// took the code blow as a forever loop and the toggle didn't work+caused bunouts

		if(vexRT[Btn8L])
		{
			on47 = true;
		}
		if(vexRT[Btn8R])
		{
			on47 = false;
		}
		if(vexRT[Btn8U])
		{
			on60 = true;
		}
		if(vexRT[Btn8R])
		{
			on60 = false;
		}
		//bool if statements//
		//start if statements for full power//
		if(on47)
		{
			while(on47)
			{
				if(vexRT[Btn8R])
				{
					on47 = false;
					motor[port6] = 0
					motor[port7] = 0
					motor[port8] = 0
					motor[port9] = 0

					if (vexRT[Btn8D] == 1){
						motor[port6] = 127
						motor[port7] = 127
						motor[port8] = 127
						motor[port9] = 127

					}
					break;
				}
				motor[port6] = 59
				motor[port7] = 59
				motor[port8] = 59
				motor[port9] = 59

				if (vexRT[Btn8D] == 1){
					motor[port6] = 127
					motor[port7] = 127
					motor[port8] = 127
					motor[port9] = 127

				}

				//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
				//Create "deadzone" for Y1/Ch3
				if(abs(vexRT[Ch1]) > threshold)
					Y1 = vexRT[Ch1];
				else
					Y1 = 0;
				//Create "deadzone" for X1/Ch1
				if(abs(vexRT[Ch4]) > threshold)
					X1 = vexRT[Ch4];
				else
					X1 = 0;
				//Create "deadzone" for X2/Ch4
				if(abs(vexRT[Ch3]) > threshold)
					X2 = vexRT[Ch3];
				else
					X2 = 0;


				//Remote Control Commands
				motor[frontLeft] = Y1  -X2  -X1;
				motor[frontRight]= Y1  +X2  -X1;
				motor[backLeft]  = Y1  -X2  +X1;
				motor[backRight] = Y1  +X2  +X1;

				motor[port1] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);
				motor[port10] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);

			}
		}
		//end if statement for 100% power//
		//.......................................................................................................//
		//start for 65% power//

		if(on60)
		{
			while(on60)
			{
				if(vexRT[Btn8R])
				{
					on60 = false;
					motor[port6] = 0
					motor[port7] = 0
					motor[port8] = 0
					motor[port9] = 0

					if (vexRT[Btn8D] == 1){
						motor[port6] = 127
						motor[port7] = 127
						motor[port8] = 127
						motor[port9] = 127

					}
					break;
				}
				motor[port6] = 0
				motor[port7] = 0
				motor[port8] = 0
				motor[port9] = 0

				if (vexRT[Btn8D] == 1){
					motor[port6] = 127
					motor[port7] = 127
					motor[port8] = 127
					motor[port9] = 127

				}

				//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
				//Create "deadzone" for Y1/Ch3
				if(abs(vexRT[Ch1]) > threshold)
					Y1 = vexRT[Ch1];
				else
					Y1 = 0;
				//Create "deadzone" for X1/Ch1
				if(abs(vexRT[Ch4]) > threshold)
					X1 = vexRT[Ch4];
				else
					X1 = 0;
				//Create "deadzone" for X2/Ch4
				if(abs(vexRT[Ch3]) > threshold)
					X2 = vexRT[Ch3];
				else
					X2 = 0;
				//Remote Control Commands
				motor[frontLeft] = Y1  -X2  -X1;
				motor[frontRight]= Y1  +X2  -X1;
				motor[backLeft]  = Y1  -X2  +X1;
				motor[backRight] = Y1  +X2  +X1;

				motor[port1] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);
				motor[port10] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);

			}
		}
		//................................//

		//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
		//Create "deadzone" for Y1/Ch3
		if(abs(vexRT[Ch1]) > threshold)
			Y1 = vexRT[Ch1];
		else
			Y1 = 0;
		//Create "deadzone" for X1/Ch1
		if(abs(vexRT[Ch4]) > threshold)
			X1 = vexRT[Ch4];
		else
			X1 = 0;
		//Create "deadzone" for X2/Ch4
		if(abs(vexRT[Ch3]) > threshold)
			X2 = vexRT[Ch3];
		else
			X2 = 0;
		//Remote Control Commands
		motor[frontLeft] = Y1  -X2  -X1;
		motor[frontRight]= Y1  +X2  -X1;
		motor[backLeft]  = Y1  -X2  +X1;
		motor[backRight] = Y1  +X2  +X1;

		motor[port1] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);
		motor[port10] = (vexRT(Btn6U) * 127) + (vexRT(Btn6D) * -127);
		//..............................//
		if (vexRT[Btn8D] == 1){
			motor[port6] = 127;
			motor[port7] = 127;
			motor[port8] = 127;
			motor[port9] = 127;

		}


	}
}

// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.

bStopTasksBetweenModes = true;

I got this from the competition template, but I don’t see it in your code. Put it in pre_auton and give it a run.

I don’t know if this was a typo in posting or not. Also, add some semicolons so the compiler doesn’t yell at you :wink: You could change port6 to tlLauncher so your team members can look at your program and understand it easier. Or how about a void to setFlywheelSpeed?


void Flywheel(int speed)
{
	motor[tlLauncher] = speed;
	motor[trLauncher] = speed;
	motor[brLauncher] = speed;
	motor[blLauncher] = speed;
}

...

// full court shooting
// set flywheel speed to 72
if(vexRT[Btn7U] == 1)
{
	Flywheel(72);
}

Okay I rewrote the entire code with some changes. I will try your suggestions. What I wanted to do originally was have a single button toggle. So when I press button 8 up it will set power to 72 and when I press it again it will ramp up power to 127 and quickly drop it back to 72. Also I wanted to add a limit switch, so when the ball touches it, the the power gets set to 0 since I have a ratchet an when the ball is shot it will ramp up to 127 and then quickly comes back to 59 for rapid fire from half court. All this happens when I tap the button 8L until I press the designated button button 8r to shut the flywheels off.
Thanks

I don’t see anything that would specifically stop this code working with competition control.

VEX_9185 pointed this out, if you had an autonomous function that controlled the flywheel then this may be an issue, but the code you posted does not have anything in autonomous.

Yes, many missing semi-colons to fix, ROBOTC is kind in that regard.

In general you may have problems as the same motors are set in multiple places, this, for example, is a problem.

      while(on47)
      {
        if(vexRT[Btn8R])
        {
          on47 = false;
          motor[port6] = 0
          motor[port7] = 0
          motor[port8] = 0
          motor[port9] = 0

          if (vexRT[Btn8D] == 1){
            motor[port6] = 127
            motor[port7] = 127
            motor[port8] = 127
            motor[port9] = 127

          }
          break;
        }
        motor[port6] = 59
        motor[port7] = 59
        motor[port8] = 59
        motor[port9] = 59

        if (vexRT[Btn8D] == 1){
          motor[port6] = 127
          motor[port7] = 127
          motor[port8] = 127
          motor[port9] = 127

        }
      }

motors can be set multiple times during that loop (if Btn8D is held then they will toggle between 59 and 127), take a look at this post and perhaps simplify the code.

RobotC - Bad programming habit Post #4

Could you please explain this

Could you please explain this part?

In general you may have problems as the same motors are set in multiple places, this, for example, is a problem.

Wait I just realized we never updated our keys prior to the competition. This was after the new version of Robotc came out. How big of an impact could this have played.

If it played a big role wow. Little details will hinder a team from maximum performance.

I explained that in the post I linked.
Generally you only want to set motors once each time around your main while loop. Using conditional statements is fine but you have to be careful that only one condition can be true.

So, this is not so good.

		// half court shooting
		if(vexRT[Btn7L] == 1){
			motor[port6] = 59
			motor[port7] = 59
			motor[port8] = 59
			motor[port9] = 59
		}
		// full court shooting
		if(vexRT[Btn7U] == 1){
			motor[port6] = 72
			motor[port7] = 72
			motor[port8] = 72
			motor[port9] = 572
		}

As both Btn7L and Btn7U may be pressed at the same time.

In this code;

while(on47)
      {
        if(vexRT[Btn8R])
        {
          on47 = false;
          motor[port6] = 0
          motor[port7] = 0
          motor[port8] = 0
          motor[port9] = 0

          if (vexRT[Btn8D] == 1){
            motor[port6] = 127
            motor[port7] = 127
            motor[port8] = 127
            motor[port9] = 127

          }
          break;
        }
        motor[port6] = 59
        motor[port7] = 59
        motor[port8] = 59
        motor[port9] = 59

        if (vexRT[Btn8D] == 1){
          motor[port6] = 127
          motor[port7] = 127
          motor[port8] = 127
          motor[port9] = 127

        }
      }

motors will be first set to 0 and then to 127 each time around the loop (if Btn8R is not pressed)

Assuming you had a VEXnet connection, probably no effect. The master firmware (from VEX, currently V4.25) and VEXnet key firmware( currently V1.46) need to be matched. ROBOTC is much more tolerant, of you upgraded from say V4.32 to V4.50 the required master firmware (and hence the vex net firmware) is the same for both.

If you read through old posts on the forum you will find many that claim their robot stopped working as soon as they used it in a real competition. Field control is often blamed but is almost never the root cause of the problems. A difference in game objects, field tiles etc. causing more/less friction compared to your practice field can have an effect. Driving in a more aggressive fashion can also cause motors to burn out more quickly. Static can cause problems, etc. etc.