RobotC Help

Been doing autonomous yesterday and I’m getting errors for tasks. I googled it could not find anything to fix I will post code down bellow and another question didn’t check forum but what is the best and most accurate way to make a turn for autonomous. Thanks in advance

#pragma config(Sensor, in1,    LiftRight,      sensorPotentiometer)
#pragma config(Sensor, in2,    LiftLeft,       sensorPotentiometer)
#pragma config(Sensor, dgtl1,  LeftEncoder,    sensorRotation)
#pragma config(Sensor, dgtl2,  LeftEncoder,    sensorRotation)
#pragma config(Sensor, dgtl3,  RightEncoder,   sensorRotation)
#pragma config(Sensor, dgtl4,  RightEncoder,   sensorRotation)
#pragma config(Motor,  port1,           Claw,          tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           LeftDrive,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           MOGO1,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           Lift1,         tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor,  port5,           Lift2,         tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor,  port6,           Lift3,         tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor,  port7,           Lift4,         tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor,  port8,           MOGO2,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           RightDrive,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          ChainBar,      tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(150)
#include "VEX_Competition_Includes.c"
void pre_auton (){
}
task autonomous () {


#define abs(X) ((X < 0) ? -1 * X : X)
 
void driveStraightDistance(int tenthsOfIn, int masterPower)
{
  int tickGoal = (42 * tenthsOfIn) / 10;
 
  //This will count up the total encoder ticks despite the fact that the encoders are constantly reset.
  int totalTicks = 0;
 
  //Initialise slavePower as masterPower - 5 so we don't get huge error for the first few iterations. The
  //-5 value is based off a rough guess of how much the motors are different, which prevents the robot from
  //veering off course at the start of the function.
  int slavePower = masterPower - 5; 
 
  int error = 0;
 
  int kp = 5;
 
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;
 
  //Monitor 'totalTicks', instead of the values of the encoders which are constantly reset.
  while(abs(totalTicks) < tickGoal)
  {
    //Proportional algorithm to keep the robot going straight.
    motor[LeftDrive] = masterPower;
    motor[RightDrive] = slavePower;
 
    error = SensorValue[LeftEncoder] - SensorValue[RightEncoder];
 
    slavePower += error / kp;
 
    SensorValue[LeftEncoder] = 0;
    SensorValue[RightEncoder] = 0;
 
    wait1Msec(100);
 
    //Add this iteration's encoder values to totalTicks.
    totalTicks+= SensorValue[LeftEncoder];
  }
  motor[LeftDrive] = 0; // Stop the loop once the encoders have counted up the correct number of encoder ticks.
  motor[RightDrive] = 0;  
}
 
 
task main()
{
  //Distances specified in tenths of an inch.
 
  driveStraightDistance(50,127); 
  wait1Msec(500);              //Stop in between to prevent momentum causing wheel skid.
  
  
	motor[LeftDrive] = 100;
	motor[RightDrive] = 100;
	wait1Msec(4000);
	motor[LeftDrive] = 0;
	motor[RightDrive] = 0;
	//How many inches the bot moves in 1 second
	int secIn = 33.52;
	//Move forward for 49 inches
	motor[LeftDrive] = 127;
	motor[RightDrive] = 127;
	wait1Msec((49/secIn)*1000);
	//Move backward for 49 inches
	motor[RightDrive] = -127;
	motor[LeftDrive] = -127;
	wait1Msec((49/secIn)*1000);
	//Rotate bot clockwise 130 degrees
	motor[RightDrive] = -127;
	motor[LeftDrive] = 127;
	wait1Msec(1300);
	//Move forward 12 inches
	motor[RightDrive] = 127;
	motor[LeftDrive] = 127;
	wait1Msec((12/secIn)*1000);
	//Stop
	motor[RightDrive] = 0;
	motor[LeftDrive] = 0;

}
task usercontrol(){
	while (1==1){
		//Right joystick controls right wheels
		motor[RightDrive] = vexRT[Ch3];
		//Left joystick controls left wheels
		motor[LeftDrive] = vexRT[Ch2];

		//Above, we mutiplied the above values by 0.5 to reduce the power going to the motors by 50% in order to reduce overheating

		//Tower controlled by buttons 5U and 5D
		if(vexRT[Btn5D]){
			motor[Lift1] = -100;
			motor[Lift2] = -100;
			motor[Lift3] = -100;
			motor[Lift4] = -100;
		}
		else if(vexRT[Btn5U]){
			motor[Lift1] = 100;
			motor[Lift2] = 100;
			motor[Lift3] = 100;
			motor[Lift4] = 100;
		}
		else{
			motor[Lift1] = 0;
			motor[Lift2] = 0;
			motor[Lift3] = 0;
			motor[Lift4] = 0;
		}
		//Claw opening and closing controlled by Buttons 7U and 8U
		if(vexRT[Btn7U]){
			motor[Claw] = 100;
		}
		else if(vexRT[Btn8U]){
			motor[Claw] = -100;
		}
		else{
			motor[Claw] = 0;
		}
		if(vexRT[Btn8D]){
			startTask(autonomous);
			wait1Msec(15000);
		}

			stopTask(autonomous);
		}
		/* press the bottom button of the right buttons to
		start the autonomous*/
	}
}

I fixed it a little but getting duplicated task main

CODE:

#pragma config(Sensor, in1,    LiftRight,      sensorPotentiometer)
#pragma config(Sensor, in2,    LiftLeft,       sensorPotentiometer)
#pragma config(Sensor, dgtl1,  LeftEncoder,    sensorRotation)
#pragma config(Sensor, dgtl2,  LeftEncoder,    sensorRotation)
#pragma config(Sensor, dgtl3,  RightEncoder,   sensorRotation)
#pragma config(Sensor, dgtl4,  RightEncoder,   sensorRotation)
#pragma config(Motor,  port1,           Claw,          tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           LeftDrive,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           MOGO1,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           Lift1,         tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor,  port5,           Lift2,         tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor,  port6,           Lift3,         tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor,  port7,           Lift4,         tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor,  port8,           MOGO2,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           RightDrive,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          ChainBar,      tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(150)
#include "VEX_Competition_Includes.c"
void pre_auton (){
}

task autonomous () {


#define abs(X) ((X < 0) ? -1 * X : X)
}
void driveStraightDistance(int tenthsOfIn, int masterPower)
{
  int tickGoal = (42 * tenthsOfIn) / 10;
 
  //This will count up the total encoder ticks despite the fact that the encoders are constantly reset.
  int totalTicks = 0;
 
  //Initialise slavePower as masterPower - 5 so we don't get huge error for the first few iterations. The
  //-5 value is based off a rough guess of how much the motors are different, which prevents the robot from
  //veering off course at the start of the function.
  int slavePower = masterPower - 5; 
 
  int error = 0;
 
  int kp = 5;
 
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;
 
  //Monitor 'totalTicks', instead of the values of the encoders which are constantly reset.
  while(abs(totalTicks) < tickGoal)
  {
    //Proportional algorithm to keep the robot going straight.
    motor[LeftDrive] = masterPower;
    motor[RightDrive] = slavePower;
 
    error = SensorValue[LeftEncoder] - SensorValue[RightEncoder];
 
    slavePower += error / kp;
 
    SensorValue[LeftEncoder] = 0;
    SensorValue[RightEncoder] = 0;
 
    wait1Msec(100);
 
    //Add this iteration's encoder values to totalTicks.
    totalTicks+= SensorValue[LeftEncoder];
  }
  motor[LeftDrive] = 0; // Stop the loop once the encoders have counted up the correct number of encoder ticks.
  motor[RightDrive] = 0;  
}
 
task main()
{
  //Distances specified in tenths of an inch.
 
  driveStraightDistance(50,127); 
  wait1Msec(500);              //Stop in between to prevent momentum causing wheel skid.
  
  
	motor[LeftDrive] = 100;
	motor[RightDrive] = 100;
	wait1Msec(4000);
	motor[LeftDrive] = 0;
	motor[RightDrive] = 0;
	//How many inches the bot moves in 1 second
	int secIn = 33.52;
	//Move forward for 49 inches
	motor[LeftDrive] = 127;
	motor[RightDrive] = 127;
	wait1Msec((49/secIn)*1000);
	//Move backward for 49 inches
	motor[RightDrive] = -127;
	motor[LeftDrive] = -127;
	wait1Msec((49/secIn)*1000);
	//Rotate bot clockwise 130 degrees
	motor[RightDrive] = -127;
	motor[LeftDrive] = 127;
	wait1Msec(1300);
	//Move forward 12 inches
	motor[RightDrive] = 127;
	motor[LeftDrive] = 127;
	wait1Msec((12/secIn)*1000);
	//Stop
	motor[RightDrive] = 0;
	motor[LeftDrive] = 0;
}

task usercontrol(){
	while (1==1){
		//Right joystick controls right wheels
		motor[RightDrive] = vexRT[Ch3];
		//Left joystick controls left wheels
		motor[LeftDrive] = vexRT[Ch2];

		//Above, we mutiplied the above values by 0.5 to reduce the power going to the motors by 50% in order to reduce overheating

		//Tower controlled by buttons 5U and 5D
		if(vexRT[Btn5D]){
			motor[Lift1] = -100;
			motor[Lift2] = -100;
			motor[Lift3] = -100;
			motor[Lift4] = -100;
		}
		else if(vexRT[Btn5U]){
			motor[Lift1] = 100;
			motor[Lift2] = 100;
			motor[Lift3] = 100;
			motor[Lift4] = 100;
		}
		else{
			motor[Lift1] = 0;
			motor[Lift2] = 0;
			motor[Lift3] = 0;
			motor[Lift4] = 0;
		}
		//Claw opening and closing controlled by Buttons 7U and 8U
		if(vexRT[Btn7U]){
			motor[Claw] = 100;
		}
		else if(vexRT[Btn8U]){
			motor[Claw] = -100;
		}
		else{
			motor[Claw] = 0;
		}
		if(vexRT[Btn8D]){
			startTask(autonomous);
			wait1Msec(15000);
		}

			stopTask(autonomous);
		}
		/* press the bottom button of the right buttons to
		start the autonomous*/
	}

I think the part of the program under “task main” should be under “task autonomous” instead and you don’t need the “task main”. In the competition template, there is no “task main” only “task autonomous” and “task user control”

Does anyone know why my programming skips autonomous in robotC.
Here’s my code:

#pragma config(Motor, port2, claw, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, leftmogo, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, frontleft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, frontright, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, backleft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, backright, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port8, rightmogo, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, arm, tmotorVex393_HBridge, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

/* Description: Competition template for VEX EDR */

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

// Select Download method as “competition”
#pragma competitionControl(Competition)

//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, ...

}

/---------------------------------------------------------------------------/
/* Autonomous Task */

task autonomous()
{
// …
// Insert user code here.
// …

																	//////Autonomous//////

//What Autonomous is supposed to do…
//First Step: Drive Forward a little bit.
//Second Step Stop
//Third Step: Mobile Goal Lift Comes Down
//Forth Step: Drive Farther
//Fith Step: Lift Up a Mobile Goal
//Step Seven: Do a 180* Turn
//Step Eight: Go To Scoring Corner.
//Step Nine: Reday for the End…of Atonomous.

motor[arm] = -127;  //The Arm says, "UUUUUPPPPP!!!!"
wait1Msec(2000);
motor[port3] = -127;
motor[port8] = -127; //Mobile Goal Intake is getting ready.
wait1Msec(2000);
motor[port4] = -127;
motor[port5]  = -127;		 //Driving to the Mobile Goal.
motor[port6] = -127;
motor[port7]  = -127;
wait1Msec(3000);
motor[port4] = 0;
motor[port5] = 0;		//Waiting Around A Useless Corner is a Happy Holiday
motor[port6] = 0;
motor[port7] = 0;
wait1Msec(100);
motor[port4] = -127;
motor[port5]  = -127;
motor[port6] = -127;		   //Ram Mobile Goal into My Lift and a Corner
motor[port7]  = -127;
wait1Msec(4000);
motor[port3] = 127;
motor[port8] = 127;  //Let's Play: Lift Up a Mobile Goal.
wait1Msec(2000);
motor[port4] = 127;
motor[port5] = -127;
motor[port6] = 127;		   //Turning 180*s since 2014!
motor[port7] = -127;
wait1Msec(200);
motor[port4] = -127;
motor[port5]  = -127;
motor[port6] = -127;		 //Going to take the Mobile Goal to 20 Point Zone. Mabey?
motor[port7]  = -127;
wait1Msec(3000);
motor[port4] = 0;
motor[port5] = 0;
motor[port6] = 0;		    //Time to take a nap.
motor[port7] = 0;
wait1Msec(300);
// Remove this function call once you have "real" code.
AutonomousCodePlaceholderForTesting();

}

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

while (true)
{

	motor(frontright) = vexRT(Ch2); //Front Right Drive
	motor(backright) = vexRT(Ch2); //Back Right Drive
	motor(frontleft) = vexRT(Ch3); //Front Left Drive
	motor(backleft) = vexRT(Ch3); //Back Right Drive             //My Robot is very Complicated.
	motor(rightmogo) = vexRT(Btn5U)*127 + vexRT(Btn5D)*-127; //Right Side of the Mobile Goal Lift
	motor(leftmogo) = vexRT(Btn5U)*127 + vexRT(Btn5D)*-127; //Left Side of the Mobile Goal Lift
	motor(arm) = vexRT(Btn6U)*127 + vexRT(Btn6D)*-127; //arm
	motor(claw) = vexRT(Btn7U)*127 + vexRT(Btn7D)*-127; // claw
	UserControlCodePlaceholderForTesting();
}

}

Are you using a competition switch to switch between autonomous and driver?

We don’t have a competition switch

Do you have any CAT 5e (ethernet) cables that you are willing to cut? Do you have any switches and buttons? Do you have any soldering experience?

I’m sure I could find some, and a have little and I emphasis the LITTLE experience

Ok, if you have a cable and a switch and soldering equipment, cut the ethernet cable and strip the White wire with green stripes, the green wire, the white wire with orange stripes, the blue wire, and the white wire with brown stripes. Solder the white wire with green stripes, the blue wire, and the white wire with brown stripes together to one lead of the switch/button. Then solder the green wire to the other lead of the switch. When you hit the switch, it should switch between autonomous and driver

There is also a built in competition switch in robot C. You should be able to search how to use it. No soldering needed, lol.

Did not know that, how do you use it?

That would be very helpful.

I highly recommend buying a competition switch. Cost: $20. Value: priceless.

Once you upload your program and your RobotC UI is in the debugger mode (before you press Start), go to menu Robot->Debugger windows->Competition control.
You’ll get a new window with “Disabled”, “Autonomous” and “User Control” buttons.
Press “Disabled”, this is the equivalent of switching the disable/enable switch to disabled state.
Then press “Start” in the debugger window. Your pre-auton will run and then the robot would wait for enablement.
When you press “Autonomous”, is is the equivalent of switching the competition switch to Autonomous and enabling it at the same time. Similarly when you press “User Control”, it is like switching to user and enabling.

Thanks that is very useful.