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*/
}
}