So right now my students and I are trying to figure out that if a button is pressed on the controller it goes backwards for certain time and speed. But if they program it, then when they use the joysticks on the controller it is affected by making the robot all jittery if they run it. Code will be listed below:
#pragma config(Motor, motor1, LeftDrive, tmotorVexIQ, PIDControl, driveLeft, encoder)
#pragma config(Motor, motor2, BottomLift, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor3, TopLift, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor4, Strafe, tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor, motor8, MiddleLift, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor12, RightDrive, tmotorVexIQ, PIDControl, reversed, driveRight, encoder)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
//Drive Controls
int threshold = 10;
while (true)
{
int channelA = getJoystickValue(ChA);
int channelD = getJoystickValue(ChD);
//Threshold for Channel A
if (channelA > threshold || channelA < -threshold)
{
setMotorSpeed(LeftDrive, getJoystickValue(ChA)); //
}
else
{
setMotorSpeed(LeftDrive, 0); //
}
//Threshold for Channel D
if (channelD > threshold || channelD < -threshold)
{
setMotorSpeed(RightDrive, getJoystickValue(ChD));
}
else
{
setMotorSpeed(RightDrive, 0);
}
//Lift Controls
if(getJoystickValue(BtnLUp) == 1)
{
setMotorSpeed(TopLift, 100);
setMotorSpeed(MiddleLift, 100);
setMotorSpeed(BottomLift, 100);
}
else if(getJoystickValue(BtnLDown) == 1)
{
setMotorSpeed(TopLift, -100);
setMotorSpeed(MiddleLift, -100);
setMotorSpeed(BottomLift, -100);
}
else
{
setMotorSpeed(TopLift, 0);
setMotorSpeed(MiddleLift, 0);
setMotorSpeed(BottomLift, 0);
}
//Strafe Control
if(getJoystickValue(BtnRUp) == 1)
{
setMotorSpeed(Strafe, 100);
}
else if(getJoystickValue(BtnRDown) == 1)
{
setMotorSpeed(Strafe, -100);
}
else
{
setMotorSpeed(Strafe, 0);
}
//Tongs Routine
if(getJoystickValue(BtnFUp) == 1)
{
setMotorSpeed(LeftDrive, -50);
setMotorSpeed(RightDrive, -50);
}
else
{
setMotorSpeed(LeftDrive, 0);
setMotorSpeed(RightDrive, 0);
sleep(1500);
}
}
}