Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sCurveForward(float distance, double velocity, int timeout) {
- //vel means velocity
- //acell means accelleration
- //func means function
- //drive variable and calculations
- double wheelDiameterIN = 3.25;
- double travelTargetCM = distance; //distance set to travel
- double circumfrence = wheelDiameterIN * 3.141592 * 0.6;
- double degreesToRotate = (360 * travelTargetCM) / circumfrence;
- //acceleration variables
- int base = 2; //base int for accel function
- int counter = 0; //counter for calculations
- double calcVel = velocity; //for deaccel calc
- double subtractor = 0; //for deaccel
- double subtractor2 = 0; //for deaccel calc
- //all motor encoder variables
- int encoderR = RightMotor.rotation(deg); //encoder value
- double motorVelR = 0; //vel based of function
- int encoderRb = LeftMotor.rotation(deg); //encoder value
- double motorVelRb = 0; //vel based of function
- int encoderL = RightMotorBack.rotation(deg); //encoder value
- double motorVelL = 0; //vel based of function
- int encoderLb = LeftmotorBack.rotation(deg); //encoder value
- double motorVelLb = 0; //vel based of function
- // RIGHT FRONT////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelR < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelR = Math.pow(base, (.5 * encoderR) - 3);
- }
- //rounds motor vel
- motorVelR = Math.round(motorVelR);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelR < velocity) {
- while(motorVelR < velocity) {
- motorVelR = motorVelR + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelR > velocity) {
- while(motorVelR > velocity) {
- motorVelR = motorVelR - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderR) {
- //if motorVel more than 1, deaccel
- while(motorVelR > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderR) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelR = motorVelR - subtractor;
- }
- }
- //rounds motorVel
- motorVelR = Math.round(motorVelR);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelR = motorVelR - motorVel;
- // RIGHT BACK////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelRb < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelRb = Math.pow(base, (.5 * encoderRb) - 3);
- }
- //rounds motor vel
- motorVelRb = Math.round(motorVelRb);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelRb < velocity) {
- while(motorVelRb < velocity) {
- motorVelRb = motorVelRb + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelRb > velocity) {
- while(motorVelRb > velocity) {
- motorVelRb = motorVelRb - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderRb) {
- //if motorVel more than 1, deaccel
- while(motorVelRb > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderRb) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelRb = motorVelRb - subtractor;
- }
- }
- //rounds motorVel
- motorVelRb = Math.round(motorVelRb);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelRb = motorVelRb - motorVelRb;
- // Left Front////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelL < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelL = Math.pow(base, (.5 * encoderL) - 3);
- }
- //rounds motor vel
- motorVelL = Math.round(motorVelL);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelL < velocity) {
- while(motorVelL < velocity) {
- motorVelL = motorVelL + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelL > velocity) {
- while(motorVelL > velocity) {
- motorVelL = motorVelL - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderL) {
- //if motorVel more than 1, deaccel
- while(motorVelL > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderL) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelL = motorVelL - subtractor;
- }
- }
- //rounds motorVel
- motorVelL = Math.round(motorVelL);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelL = motorVelL - motorVelL;
- // Left Back////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelLb < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelLb = Math.pow(base, (.5 * encoderLb) - 3);
- }
- //rounds motor vel
- motorVelLb = Math.round(motorVelLb);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelLb < velocity) {
- while(motorVelLb < velocity) {
- motorVelLb = motorVelLb + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelLb > velocity) {
- while(motorVelLb > velocity) {
- motorVelLb = motorVelLb - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderLb) {
- //if motorVel more than 1, deaccel
- while(motorVelLb > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderLb) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelLb = motorVelLb - subtractor;
- }
- }
- //rounds motorVel
- motorVelLb = Math.round(motorVelLb);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelLb = motorVelLb - motorVelLb;
- LeftMotor.setVelocity(motorVelL, vex::velocityUnits::pct);
- LeftMotor.setReversed(true);
- RightMotor.setVelocity(motorVelR, vex::velocityUnits::pct);
- RightMotor.setReversed(false);
- LeftmotorBack.setVelocity(motorVelLb, vex::velocityUnits::pct);
- LeftmotorBack.setReversed(true);
- RightMotorBack.setVelocity(motorVelRb, vex::velocityUnits::pct);
- RightMotorBack.setReversed(false);
- LeftMotor.setTimeout(timeout, msec);
- RightMotor.setTimeout(timeout, msec);
- LeftmotorBack.setTimeout(timeout, msec);
- RightMotorBack.setTimeout(timeout, msec);
- LeftMotor.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- RightMotor.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- LeftmotorBack.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- RightMotorBack.rotateFor(degreesToRotate, vex::rotationUnits::deg, true);
- }
- void cCurveLeft(float distance, double velocity, double curve int timeout) {
- //vel means velocity
- //acell means accelleration
- //func means function
- //drive variable and calculations
- double wheelDiameterIN = 3.25;
- double travelTargetCM = distance; //distance set to travel
- double circumfrence = wheelDiameterIN * 3.141592 * 0.6;
- double degreesToRotate = (360 * travelTargetCM) / circumfrence;
- //acceleration variables
- int base = 2; //base int for accel function
- int counter = 0; //counter for calculations
- double calcVel = velocity; //for deaccel calc
- double subtractor = 0; //for deaccel
- //double cFinal = (velocity / curve);
- //all motor encoder variables
- int encoderR = RightMotor.rotation(deg); //encoder value
- double motorVelR = 0; //vel based of function
- int encoderRb = LeftMotor.rotation(deg); //encoder value
- double motorVelRb = 0; //vel based of function
- int encoderL = RightMotorBack.rotation(deg); //encoder value
- double motorVelL = 0; //vel based of function
- int encoderLb = LeftmotorBack.rotation(deg); //encoder value
- double motorVelLb = 0; //vel based of function
- // Left Front////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelL < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelL = Math.pow(base, (.5 * encoderL) - 3);
- }
- //rounds motor vel
- motorVelL = Math.round(motorVelL);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelL < velocity) {
- while(motorVelL < velocity) {
- motorVelL = motorVelL + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelL > velocity) {
- while(motorVelL > velocity) {
- motorVelL = motorVelL - 1;
- }
- }
- //c curve
- //if motorVel more than velocity / curve, deaccel
- while(motorVelL > curve) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderL) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelL = motorVelL - subtractor;
- }
- //rounds motorVel
- motorVelL = Math.round(motorVelL);
- // Left Back////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelLb < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelLb = Math.pow(base, (.5 * encoderLb) - 3);
- }
- //rounds motor vel
- motorVelLb = Math.round(motorVelLb);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelLb < velocity) {
- while(motorVelLb < velocity) {
- motorVelLb = motorVelLb + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelLb > velocity) {
- while(motorVelLb > velocity) {
- motorVelLb = motorVelLb - 1;
- }
- }
- //c curve
- //if motorVel more than velocity / curve, deaccel
- while(motorVelLb > curve) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderLb) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelLb = motorVelLb - subtractor;
- }
- //rounds motorVel
- motorVelLb = Math.round(motorVelLb);
- // RIGHT FRONT////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelR < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelR = Math.pow(base, (.5 * encoderR) - 3);
- }
- //rounds motor vel
- motorVelR = Math.round(motorVelR);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelR < velocity) {
- while(motorVelR < velocity) {
- motorVelR = motorVelR + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelR > velocity) {
- while(motorVelR > velocity) {
- motorVelR = motorVelR - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderR) {
- //if motorVel more than 1, deaccel
- while(motorVelR > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderR) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelR = motorVelR - subtractor;
- }
- }
- //rounds motorVel
- motorVelR = Math.round(motorVelR);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelR = motorVelR - motorVel;
- // RIGHT BACK////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //beginning vel curve
- while(motorVelRb < velocity) {
- //accel func (2^(.5 * x) - 3)
- motorVelRb = Math.pow(base, (.5 * encoderRb) - 3);
- }
- //rounds motor vel
- motorVelRb = Math.round(motorVelRb);
- //velocity correction
- //if motor vel less than target vel, add vel until equal target vel
- if(motorVelRb < velocity) {
- while(motorVelRb < velocity) {
- motorVelRb = motorVelRb + 1;
- }
- }
- //if motor vel more than target vel, subtract vel until equal target vel
- if(motorVelRb > velocity) {
- while(motorVelRb > velocity) {
- motorVelRb = motorVelRb - 1;
- }
- }
- //decreasing curve time calc
- while(calcVel > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor2 = Math.pow(base, (.5 * encoder) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- calcVel = calcVel - subtractor2;
- //counts time to reach 0 vel to know when to deaccel
- counter = counter + 1;
- }
- //decreasing curve
- //calc if bot needs to deaccel then runs code
- while((distance - counter) > encoderRb) {
- //if motorVel more than 1, deaccel
- while(motorVelRb > 1) {
- //accel func (2^(.5 * x) - 3)
- subtractor = Math.pow(base, (.5 * encoderRb) - 3);
- //subtracts accel func from max vel to create a decreasing accel
- motorVelRb = motorVelRb - subtractor;
- }
- }
- //rounds motorVel
- motorVelRb = Math.round(motorVelRb);
- //subtracts motorVel by itself so it is 0 than a decimal
- motorVelRb = motorVelRb - motorVelRb;
- LeftMotor.setVelocity(motorVelL, vex::velocityUnits::pct);
- LeftMotor.setReversed(true);
- RightMotor.setVelocity(motorVelR, vex::velocityUnits::pct);
- RightMotor.setReversed(false);
- LeftmotorBack.setVelocity(motorVelLb, vex::velocityUnits::pct);
- LeftmotorBack.setReversed(true);
- RightMotorBack.setVelocity(motorVelRb, vex::velocityUnits::pct);
- RightMotorBack.setReversed(false);
- LeftMotor.setTimeout(timeout, msec);
- RightMotor.setTimeout(timeout, msec);
- LeftmotorBack.setTimeout(timeout, msec);
- RightMotorBack.setTimeout(timeout, msec);
- LeftMotor.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- RightMotor.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- LeftmotorBack.rotateFor(degreesToRotate, vex::rotationUnits::deg, false);
- RightMotorBack.rotateFor(degreesToRotate, vex::rotationUnits::deg, true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement