code works for a second and then stops

Hello,
so I’ve been having problems with the code running on the robot for a second or so, and then just stopping (until you turn it off and then back on again), so i was wondering if its an issue with the code or with the actual motors on the robot itself. Below is a copy of my code, as well as a screenshot from the code within robot c. There wasn’t any error in compiling so it might be the format messing up?? I’m not sure, I’m a new coder so please be easy on me.

/////////////////////////
task main()
{
while(1 == 1)
{
//Right side of the robot is controlled by the right joystick, Y-axis
motor[rightdrive] = vexRT[Ch2];
//Left side of the robot is controlled by the left joystick, Y-axis
motor[leftdrive] = vexRT[Ch3];
//moving the arm up (all together)

if(vexRT[Btn6U] == 1)
//moving the arm up (all together)
{
motor[leftliftoutup] = 127;
motor[leftliftoutdown] = 127;
motor[leftliftinup] = -127; //move up
motor[leftliftindown] = -127;
motor[rightliftoutup] = -127;
motor[rightliftoutdown] = -127;
motor[rightliftinup] = 127;
motor[rightliftindown] = 127;
}
else
if(vexRT[Btn6D] == 1)
//moving the arm down (all together)
{
motor[leftliftoutup] = -127;
motor[leftliftoutdown] = -127;
motor[leftliftinup] = 127; //move down
motor[leftliftindown] = 127;
motor[rightliftoutup] = 127;
motor[rightliftoutdown] = 127;
motor[rightliftinup] = -127;
motor[rightliftindown] = -127;
}
}
}
//end of task main
////////////////////////////////////////
pasted_image.png

Could you post a screenshot of your motor and sensor set up?

Have you looked at your joystick lights when it stops?

here it is
pasted_image.png

Assuming that all the motors and wires are configured correctly all you have to do is add a


wait1msec(nNumberofMiliseconds);

These commands are as simple as what they read. Just replace nNumberofMiliseconds with 20. Add this right before the end of the while loop so the cortex has enough time to process all the information before cycling through the while loop. Wait commands are required in ALL while loops so it has enough time to do the calculations. If you don’t add a wait command, then the program will likely crash which is what your are experiencing.

wait1msec.PNG

The caps lock comments are the ones that I added. Usually its good to comment each curly brace so you know what command they belong to. That’s not absolutely necessary, but it improves the code’s organization.

Do you expect your arms to stop moving?

6U is one direction and 6D is the other but I don’t see code to tell them to stop moving. Usually you would code something like the following:

task main()
{
	while(1 == 1)
	{
		//Right side of the robot is controlled by the right joystick, Y-axis
		motor[rightdrive] = vexRT[Ch2];
		//Left side of the robot is controlled by the left joystick, Y-axis
		motor[leftdrive] = vexRT[Ch3];
		//moving the arm up (all together)

		if(vexRT[Btn6U] == 1)
			//moving the arm up (all together)
		{
			motor[leftliftoutup] = 127;
			motor[leftliftoutdown] = 127;
			motor[leftliftinup] = -127; //move up
			motor[leftliftindown] = -127;
			motor[rightliftoutup] = -127;
			motor[rightliftoutdown] = -127;
			motor[rightliftinup] = 127;
			motor[rightliftindown] = 127;
		}
		else if(vexRT[Btn6D] == 1)
			//moving the arm down (all together)
		{
			motor[leftliftoutup] = -127;
			motor[leftliftoutdown] = -127;
			motor[leftliftinup] = 127; //move down
			motor[leftliftindown] = 127;
			motor[rightliftoutup] = 127;
			motor[rightliftoutdown] = 127;
			motor[rightliftinup] = -127;
			motor[rightliftindown] = -127;
		}

		else {
			//stopping the arm down (all together)
			motor[leftliftoutup] = 0;
			motor[leftliftoutdown] = 0;
			motor[leftliftinup] = 0;  
			motor[leftliftindown] = 0;
			motor[rightliftoutup] = 0;
			motor[rightliftoutdown] = 0;
			motor[rightliftinup] = 0;
			motor[rightliftindown] = 0;
		}

	}
}

That only applies to PROS. We recommend you also do that in ROBOTC, but it’s not absolutely necessary.

Can you check the connections with your CORTEX and your battery to make sure nothing is loose? Also, by adding a 9V may potentially help. Did you also check the amount of friction on the lift? Is it not too shabby?
The code legitimately seems perfectly fine, other than telling the motors to stop when nothing is pressed. I am thinking it’s more of a hardware and not software issue.

looking at the various awesome robotC debuggers also may help. There’s one telling you the tasks running and another telling the values sent to motors that could be quite helpful.