Smart drive .turnfor command

I am trying to use the turn for command for vex and I have a problems and that is when trying to turn 180 degrees we do have a inertial sensor the robot wont stop turn here is the code:

int autondrive(){
    wait(10, seconds);
    FL.setVelocity(200, percent);
    ML.setVelocity(200, percent);
    BL.setVelocity(200, percent);
    FR.setVelocity(200, percent);
    MR.setVelocity(200, percent);
    BR.setVelocity(200, percent);
    DriveTrain.turnFor(180, degrees)
}

Is the robot turning clockwise (ie. the front turning to the right) ?
can you show how drivetrain is configured ?

unrelated, but…

BR.setVelocity(200, percent);

200% does not work, 100% is maximum.

You should also be using DriveTrain.setTurnVelocity and DriveTrain.setDriveVelocity rather than setVelocity.

1 Like

I know about the 200 percent thing my non coding friend was messing around

motor FR = motor(PORT8, ratio6_1, false);
motor BR = motor(PORT10, ratio6_1, false);
motor MR = motor(PORT9, ratio6_1, true);
motor_group RightSide = motor_group(FR,MR,BR);
motor FL = motor(PORT15, ratio6_1, true);
controller Controller1 = controller(primary);
motor BL = motor(PORT19, ratio6_1, true);
motor ML = motor(PORT17, ratio6_1, false);
motor_group LeftSide = motor_group(FL,ML,BL);
inertial motion = inertial(PORT21);
smartdrive DriveTrain = smartdrive(RightSide,LeftSide,motion,319.19,320,40,mm, 1.6666666666666666666667);
motor PUNCH = motor(PORT11, ratio36_1, true);
motor Flap = motor(PORT4, ratio18_1, false);
pneumatics elevation = pneumatics(Brain.ThreeWirePort.B);

is this what you wanted

I believe you need to supply the turnFor( ) command with a turning direction. An example would be:

Drivetrain.turnFor(left, 180, degrees);

The direction is optional, it assumes “right” if you don’t specify.

1 Like

Instead of using the built in turnFor program you can test the inertial sensor with a custom algorithm or just test it in your drive code to ensure that it is properly calibrated and reading values.

An example of a custom algorithm to test the inertial sensor is:

//tHeading(desired turn angle, turn direction, tolerance, speed of turn)
void tHeading(double angD, bool lr,double tolerance, double fastness){

  double lrNum = 0;
  double angS = motion.heading(degrees);

    while (!(((angD - tolerance) < motion.heading(degrees)) && (motion.heading(degrees) < (angD + tolerance)))){

      if(lr){

    FL.spin(forward, perc, percent);
    BL.spin(forward, perc, percent);
    ML.spin(forward, perc, percent);

    FR.spin(reverse, perc, percent);
    BR.spin(reverse, perc, percent);
    MR.spin(reverse, perc, percent);    

  }else{

    FL.spin(reverse, perc, percent);
    BL.spin(reverse, perc, percent);
    ML.spin(reverse, perc, percent);

    FR.spin(forward, perc, percent);
    BR.spin(forward, perc, percent);
    MR.spin(forward, perc, percent);

  }

    }

  FL.stop();
  ML.stop();
  BL.stop();
  FR.stop();
  MR.stop();
  BR.stop();

}

If you don’t want to implement that then simply add something like this to your while loop in your user control:

Controller1.Screen.setCursor(0,0);
Controller1.Screen.print(motion.heading(degrees));

If you end up finding that the inertial sensor itself isn’t reading correctly then you can try putting the entire inertial code into a while loop or switching to a different compiler like VSC. Good luck and please reply if you have any other questions.

1 Like