Hey guys, we were working on an autonomous code for vex, but we’re running into issues.
The robot is supposed to execute a sequence after interacting with a touch sensor in the autonomous period.
#pragma config(Sensor, dgtl1, rightencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, liftencoder, sensorRotation)
#pragma config(Sensor, dgtl6, leftencoder, sensorRotation)
#pragma config(Sensor, dgtl7, funnelencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl11, caurax, sensorTouch)
#pragma config(Sensor, dgtl12, touch, sensorTouch)
#pragma config(Motor, port1, RightLift2, tmotorVex393, openLoop)
#pragma config(Motor, port2, FrontRight, tmotorVex393, openLoop)
#pragma config(Motor, port3, BackRight, tmotorVex393, openLoop)
#pragma config(Motor, port4, FrontLeft, tmotorVex393, openLoop)
#pragma config(Motor, port5, BackLeft, tmotorVex393, openLoop)
#pragma config(Motor, port6, Funnel, tmotorVex269, openLoop)
#pragma config(Motor, port7, LeftLift, tmotorVex393, openLoop)
#pragma config(Motor, port8, RightLift1, tmotorVex393, openLoop)
#pragma config(Motor, port9, Intake, tmotorVex393, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c"
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
SensorValue(leftencoder) = 0;
SensorValue(rightencoder) = 0;
SensorValue(funnelencoder) = 0;
SensorValue(liftencoder) = 0;
// All activities occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
int bursts = 0;
int mode = 0;
int keep = 1;
void refresh()
{
SensorValue(leftencoder) = 0;
SensorValue(rightencoder) = 0;
}
void armcontrol(int c)
{
motor[LeftLift] = -c;
motor[RightLift1] = c;
motor[RightLift2] = c;
}
void setMotors(int l,int r, int c, int f, int intk)
{
motor[FrontRight] = -r; //This should go Backwards
motor[FrontLeft] = l; //This should go Backwards
motor[BackRight] = -r; //This should go Backwards
motor[BackLeft] = l;
motor[LeftLift] = -c;
motor[RightLift1] = c;
motor[RightLift2] = c;
motor[Funnel] = f;
motor[Intake] = intk;
}
void StraightMotors(int l, int r)
{
motor[FrontRight] = -r; //This should go Backwards
motor[FrontLeft] = l; //This should go Backwards
motor[BackRight] = -r; //This should go Backwards
motor[BackLeft] = l;
}
void Straight (int b)
{
if(abs(SensorValue(rightencoder)/2) < SensorValue(leftencoder))
{
StraightMotors(b*5/6 ,b);
}
if(abs(SensorValue(rightencoder)/2) > SensorValue(leftencoder))
{
StraightMotors(b ,b*5/6);
}
if(abs(SensorValue(rightencoder)/2) == SensorValue(leftencoder))
{
StraightMotors(b ,b);
}
}
void Foward(int x, int z, int v)
{
motor[Funnel] = z;
motor[Intake] = v;
if(SensorValue(leftencoder) < (x-180) )
{
Straight(127);
}
if(SensorValue(leftencoder) < (x-90))
{
Straight(63);
}
if(SensorValue(leftencoder) > (x-90) && SensorValue(leftencoder) < x)
{
Straight(30);
}
}
void Backwards(int x, int z, int v )
{
motor[Funnel] = z;
motor[Intake] = v;
if(SensorValue(leftencoder) < (x-180) )
{
Straight(-127);
}
if(SensorValue(leftencoder) < (x-90))
{
Straight(-63);
}
if(SensorValue(leftencoder) > (x-90) && SensorValue(leftencoder) < x)
{
Straight(-40);
}
}
task autonomous()
{
pre_auton();
while(bursts==0)
{
refresh();
if(SensorValue(caurax) == 1)
{
while(abs(SensorValue(rightencoder)/2) < 210)
{
setMotors(-127,127,-10,0,-127);
}
while( bursts == 0)
{
setMotors(0,0,-10,0,-127);
if(SensorValue(touch) == 1)
{
bursts = bursts + 1;
wait1Msec(300);
}
}
}
if(SensorValue(caurax) == 0)
{
while(SensorValue(leftencoder) < 210)
{
setMotors(127,-127,-10,0,-127);
}
while( bursts == 0)
{
setMotors(0,0,-10,0,-127);
if(SensorValue(touch) == 1)
{
bursts = bursts + 1;
wait1Msec(300);
}
}
}
}
while(bursts==1)
{
refresh();
ClearTimer( time1[T1]);
while(time1[T1] < 500)
{
Foward((510+90),0,-10);
armcontrol(60);
}
while(SensorValue(leftencoder) < 510)
{
Foward((510+90),0,-10);
armcontrol(15);
}
refresh();
while(SensorValue(leftencoder) < 510)
{
Backwards((510+90),0,0);
armcontrol(0);
}
while(bursts==1)
{
setMotors(0,0,0,0,0);
if(SensorValue(touch) ==1)
{
bursts ++;
}
}
}
However, when pressing the touch sensor, the robot does not respond. We checked through the debugger window and we know that the touch sensor can be sensed. Additionally, we originally used an && statement, but we found out that wasn’t the problem either.
any help would be greatly appreciated