Robot not moving...

Hi. First post here. I have a national competition tomorrow and we are DEFINITELY not going well. Our robot is somehow not moving anymore. When we first connect the robot to the joystick via VEX NET keys, then plugged in the competition control switch to the joystick, (program already downloaded to robot) it first moves when I flick it to usercontrol, then when I flick disable and then autonomous and then enable, it does not work. Same goes for the opposite, if started with autonomous, usercontrol won’t work. After it doesn’t work, even if I flick it back and forth, it does not work. Then when I powercycle, it works once and then stops again. Please help.

Here is our code, maybe its our codes’ problem.

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_3,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Motor,  port1,           RightgoalMtr,  tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port3,           ArmMtrLeft,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           ClawMtr,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           ArmMtrRight,   tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           RightbackMtr,  tmotorVex393_MC29, openLoop, encoderPort, I2C_3)
#pragma config(Motor,  port8,           RightfrontMtr, tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_2)
#pragma config(Motor,  port9,           LeftfrontMtr,  tmotorVex393_MC29, openLoop, encoderPort, I2C_1)
#pragma config(Motor,  port10,          LeftgoalMtr,   tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// This code is for the VEX cortex platform
#pragma platform(VEX2)

// Select Download method as "competition"
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(60)

//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"


/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the cortex has been powered on and    */
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton()
{
	// Set bStopTasksBetweenModes to false if you want to keep user created tasks
	// running between Autonomous and Driver controlled modes. You will need to
	// manage all user created tasks if set to false.
	bStopTasksBetweenModes = true;
	// Set bDisplayCompetitionStatusOnLcd to false if you don't want the LCD
	// used by the competition include file, for example, you might want
	// to display your team name on the LCD in this function.
	// bDisplayCompetitionStatusOnLcd = false;

	// All activities that occur before the competition starts
	// Example: clearing encoders, setting servo positions, ...LeftfrontMtr
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/
void waitforencoders()
{
		waitUntilMotorStop(LeftfrontMtr);
		waitUntilMotorStop(RightfrontMtr);
		waitUntilMotorStop(RightbackMtr);
}
void resetencoder()
{
	resetMotorEncoder(RightbackMtr);
	resetMotorEncoder(LeftfrontMtr);
	resetMotorEncoder(RightfrontMtr);
}
void left90()
{
	resetencoder();
	setMotorTarget(LeftfrontMtr,369, -127, true);
	setMotorTarget(RightfrontMtr,738, 127, true);
	setMotorTarget(RightbackMtr,738, 127, true);
	waitforencoders();
}
void right90()
{
	resetencoder();
	setMotorTarget(LeftfrontMtr,738, 127, true);
	setMotorTarget(RightfrontMtr,369, -127, true);
	setMotorTarget(RightbackMtr,369, -127, true);
	waitforencoders();
}

task autonomous()
{
		int straight1;
		straight1 = 2220;

		int straight2;
		straight2 = 550;

		int straight3;
		straight3 = 825;

		int straight4;
		straight4 = 1660;


		resetencoder();
		setMotorTarget(LeftfrontMtr,straight1, 127, true);
		setMotorTarget(RightfrontMtr,straight1, 127, true);
		setMotorTarget(RightbackMtr,straight1, 127, true);
		waitforencoders();

		left90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight2, 127, true);
		setMotorTarget(RightfrontMtr,550, straight2, true);
		setMotorTarget(RightbackMtr,550, straight2, true);
		waitforencoders();

		right90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,825, straight3, true);
		setMotorTarget(RightfrontMtr,825, straight3, true);
		setMotorTarget(RightbackMtr,825, straight3, true);
		waitforencoders();

		left90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight4, 127, true);
		setMotorTarget(RightfrontMtr,straight4, 127, true);
		setMotorTarget(RightbackMtr,straight4, 127, true);
		waitforencoders();

		left90();

		motor(RightgoalMtr) = 20;
		motor(LeftgoalMtr) = 20;

		left90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight4, 127, true);
		setMotorTarget(RightfrontMtr,straight4, 127, true);
		setMotorTarget(RightbackMtr,straight4, 127, true);
		waitforencoders();

		right90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight3, 127, true);
		setMotorTarget(RightfrontMtr,straight3, 127, true);
		setMotorTarget(RightbackMtr,straight3, 127, true);
		waitforencoders();

		left90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight2, 127, true);
		setMotorTarget(RightfrontMtr,straight2, 127, true);
		setMotorTarget(RightbackMtr,straight2, 127, true);
		waitforencoders();

		right90();

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight1, 127, true);
		setMotorTarget(RightfrontMtr,straight1, 127, true);
		setMotorTarget(RightbackMtr,straight1, 127, true);
		waitforencoders();

		motor(RightgoalMtr) = -20;
		motor(LeftgoalMtr) = -20;
		wait10Msec(700);

		resetencoder();
		setMotorTarget(LeftfrontMtr,straight1, 127, true);
		setMotorTarget(RightfrontMtr,straight1, 127, true);
		setMotorTarget(RightbackMtr,straight1, 127, true);
		waitforencoders();
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              User Control Task                            */
/*                                                                           */
/*  This task is used to control your robot during the user control phase of */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

task ClawTask()
{
	while(true)
	{
		if (vexRT[Btn7R] == 1)
		{
			motor(ClawMtr) = 25;
			wait1Msec(600);
			motor(ClawMtr) = 0;
		}
		else if(vexRT[Btn7L] == 1)
		{
			motor(ClawMtr) = -25;
			wait1Msec(600);
			motor(ClawMtr) = 0;
		}
		else
		{
			motor(ClawMtr) = 0;
		}
	}
}

task usercontrol()
{
	// User control code here, inside the loop

	while (true)
	{
		startTask(ClawTask);

		resetencoder();


		if (abs(vexRT[Ch2]) > 20)
		{
			motor[RightbackMtr] = vexRT[Ch2];
			motor[RightfrontMtr] = vexRT[Ch2];
		}

		else if (abs(vexRT[Ch2]) <= 20)
		{
			motor[RightbackMtr] = 0;
			motor[RightfrontMtr] = 0;
		}


		if (abs(vexRT[Ch3]) > 20)
		{
			motor[LeftfrontMtr] = vexRT[Ch3];
		}

		else if (abs(vexRT[Ch3]) <= 20)
		{
			motor[LeftfrontMtr] = 0;
		}



		if (vexRT[Btn6U] == 1)
		{
			motor(ArmMtrLeft) = 80;
			motor(ArmMtrRight) = 80;
		}
		else if (vexRT[Btn6D] == 1)
		{
			motor(ArmMtrLeft) = -80;
			motor(ArmMtrRight) = -80;
		}
		else
		{
			motor(ArmMtrLeft) = 0;
			motor(ArmMtrRight) = 0;
		}


		if (vexRT[Btn5U] == 1)
		{
			motor(LeftgoalMtr) = 127; //This speed will change as it is the speed of the mobile goal holder move.
			motor(RightgoalMtr) = 127; //Same here.
		}
		else if (vexRT[Btn5D] == 1)
		{
			motor(LeftgoalMtr) = -127;
			motor(RightgoalMtr) = -127;
		}
		else
		{
			motor(LeftgoalMtr) = 0;
			motor(RightgoalMtr) = 0;
		}
	}
}

]

Thanks in Advance,

Rougescales

The only thing I can see rn-eating breakfast so I can’t compile it- is the brace at the end of the code. It should be }
Also, I don’t see any task for the autonomous.

Oh sorry about that. That was put in the post and not in the code. Sorry for the mistake.

Wait what is the brace or the task? Have you got it working?

Try taking the competition control switch out of the equation, if you haven’t already. What does the robot do if you reboot it without the competition switch plugged into the controller?

Tip: When you turn off the robot make sure all the lights on the cortex and joystick are off. If you have a 9V battery plugged into the brain it will remain on, and you are not really rebooting it. Same for the joystick, if it is plugged into a computer via the USB or programming switch. You have to fully unplug it to get a real reboot.

@SkinnyPanda Robotics - yes, there is an autonomous in the original code, right after the left90 and right90 functions.

I can’t read. Pardon my slysdexia

Here’s one issue that would affect the usercontrol program, but not the auton:

	
while (true)
	{
		startTask(ClawTask);
...

Another instance of ClawTask is being created every time this loop is executed. Only one instance of this task needs to be running, so the task should be started before entering the while loop. Or, it could be changed to a function*, and then it would be OK to call the function each time the loop goes around.

Tasks are not the same as functions. A function is like a set of instructions that you ask the computer to execute in a certain order. You could think of it as a TO DO list - ‘here ya go Mr. Computer, this is what I want you to do’. Whereas a task is kind of like a person, or another computer, that you can recruit so you can get more stuff done at the same time. The main task will take care of the driving instructions, while the claw task takes care of the claw stuff.

You are allowed to create multiple instances of the same task, kind of like cloning. Each time you call startTask you are creating another clone. By putting the startTask inside the while loop a whole clone army is quickly being created. All the claw task is doing is waiting for someone to push a button on the joystick, so only one instance of the task is needed.

Creating multiple instances of the same task is useful for certain types of tasks. A real world analogy might be attempting to dig a big hole by hand. Having more clones with shovels will get the job done quicker.

I mean the brace was a mistake. Sorry!

try writing the code like this

startTask(ClawTask);
while (true);
{
etc…
this is what we do in our code and it works just fine