So I been doing some testing today and coding so I got a autonomous working but have do I make it more precise. I’m currently using Robot C and have two Optical Shaft Encoders on each side of our bases here is the code I made hope someone could help.
#pragma config(Sensor, dgtl1, , sensorQuadEncoder)
#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)
#pragma config(Motor, port5, Lift2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, Lift3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, Lift4, tmotorVex393_MC29, openLoop)
#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 () {
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*/
}
}