We have tried to create an autonomous code on VEXcode v5 text. It only runs one part of the code at a time. Does anyone have a solution?
we can’t help if we can’t see what you did
If you want me to guess, it’s because you have blocking commands, which stops code execution until complete
2 Likes
We are running this code on the left. It always runs in reverse and we cant figure it out. Any help?
include "vex.h"
using namespace vex;
int threshold = 45;
int baseSpeed = 20;
void clawGo()
{
gearTrack.setVelocity(25,percent);
Claw.setVelocity(25,percent);
Claw.spin(forward);
wait (2,seconds);
gearTrack.spin(forward);
waitUntil(limitSwitch.pressing());
gearTrack.stop();
Claw.spin(reverse);
wait (2,seconds);
Claw.stop();
gearTrack.spin(reverse);
waitUntil(bumperH.pressing());
gearTrack.stop();
}
void driveStraight()
{
bLeftDrive.setVelocity(baseSpeed,rpm);
bRightDrive.setVelocity(baseSpeed,rpm);
fRightDrive.setVelocity(baseSpeed,rpm);
fLeftDrive.setVelocity(baseSpeed,rpm);
bLeftDrive.spin(forward);
bRightDrive.spin(forward);
fLeftDrive.spin(forward);
fRightDrive.spin(forward);
}
void trackLine()
{
if((rightTracker.reflectivity() > threshold) && (leftTracker.reflectivity() > threshold)) //if on line, drive straight//
{
driveStraight();
}
else if((leftTracker.reflectivity() < threshold) && (rightTracker.reflectivity() > threshold)) //if left tracker off, shift right//
{
bLeftDrive.setVelocity(baseSpeed, rpm);
bRightDrive.setVelocity(baseSpeed,rpm);
fLeftDrive.setVelocity(baseSpeed,rpm);
fRightDrive.setVelocity(baseSpeed,rpm);
bLeftDrive.spin(reverse);
bRightDrive.spin(forward);
fLeftDrive.spin(reverse);
fRightDrive.spin(forward);
}
else if((rightTracker.reflectivity() < threshold) && (leftTracker.reflectivity() > threshold)) //if right tracker off, shift left//
{
bLeftDrive.setVelocity(baseSpeed, rpm);
bRightDrive.setVelocity(baseSpeed,rpm);
fLeftDrive.setVelocity(baseSpeed,rpm);
fRightDrive.setVelocity(baseSpeed,rpm);
bLeftDrive.spin(forward);
bRightDrive.spin(reverse);
fLeftDrive.spin(forward);
fRightDrive.spin(reverse);
}
else
{
bLeftDrive.stop();
bRightDrive.stop();
fLeftDrive.stop();
fRightDrive.stop();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
while(true)
{
if(Controller1.ButtonA.pressing()) //if button A pressed//
{
trackLine ();
if(leftVision.objects[0].exists) //if left vision sensor senses objects//
{
bLeftDrive.setVelocity(baseSpeed, rpm);
bRightDrive.setVelocity(baseSpeed,rpm);
fLeftDrive.setVelocity(baseSpeed,rpm);
fRightDrive.setVelocity(baseSpeed,rpm);
bLeftDrive.stop();
bRightDrive.stop();
fLeftDrive.stop();
fRightDrive.stop();
wait (1, seconds);
bLeftDrive.spin(reverse); //turn left
fRightDrive.spin(forward);
wait (1,seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait(1,seconds);
driveStraight ();
wait (1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
clawGo(); //claw void
bLeftDrive.spin(reverse);
fRightDrive.spin(forward);
wait (.25, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait (1,seconds);
bRightDrive.spin(forward);
fLeftDrive.spin(reverse);
wait(1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
trackLine ();
}
if(rightVision.objects[0].exists)
{
bLeftDrive.setVelocity(baseSpeed, rpm);
bRightDrive.setVelocity(baseSpeed,rpm);
fLeftDrive.setVelocity(baseSpeed,rpm);
fRightDrive.setVelocity(baseSpeed,rpm); //turn right
bRightDrive.spin(reverse);
fLeftDrive.spin(forward);
wait (1,seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait (1, seconds);
driveStraight ();
wait (1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
clawGo(); //claw void
bLeftDrive.spin(reverse);
fRightDrive.spin(forward); //turn left
wait (1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait(1,seconds);
bLeftDrive.spin(reverse);
fRightDrive.spin(forward); //turn left
wait(1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
}
if(RangeFinder.distance(inches)<6) //if detects drop box
{
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait (1, seconds);
gearTrack.setVelocity(25,percent);
Claw.setVelocity(25,percent);
gearTrack.spin(forward);
waitUntil(limitSwitch.pressing()); //drop beaker
gearTrack.stop();
Claw.spin(forward);
wait (2,seconds);
Claw.stop();
gearTrack.spin(reverse);
waitUntil(bumperH.pressing());
wait(1, seconds);
bRightDrive.spin(reverse);
fLeftDrive.spin(forward); //turn right
wait (1, seconds);
bLeftDrive.stop();
bRightDrive.stop(); //stop
fLeftDrive.stop();
fRightDrive.stop();
wait (1,seconds);
}
else
{
trackLine ();
}
}
if (Controller1.ButtonB.pressing())
{
bLeftDrive.stop();
bRightDrive.stop();
fLeftDrive.stop();
fRightDrive.stop();
gearTrack.stop();
Claw.stop();
}
}
}
Have you considered reversing the motors
@nholton28 I’m confused what is supposed to be running simultaneously
How did you set up 4 motors for the drivetrain? I do not see how you can do this.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.