Motors won't stop when they should

Hello, when the line tracker reads >1300 it won’t spin

#include "vex.h"

using namespace vex;

vex::motor ClawMotor = vex::motor(vex::PORT9);
vex::motor LeftMotor = vex::motor(vex::PORT1);
vex::motor RightMotor = vex::motor(vex::PORT14);
vex::motor Motor1 = vex::motor(vex::PORT20);
vex::motor Motor2 = vex::motor(vex::PORT7);
vex::controller Controller1 = vex::controller();

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  
  while (true) {
    // If the reflectivity is greater than the threshold it will move the LeftMotor forward
    if (LineTrackerA.reflectivity() < 1300) {
      LeftMotor.stop(brakeType::hold);
      RightMotor.stop(brakeType::hold);;
    } else 
    {
      // If the reflectivity is less than the threshold it will move the RightMotor forward
      LeftMotor.spin(directionType::fwd, 50, vex::velocityUnits::pct);
      RightMotor.spin(directionType::rev, 50, vex::velocityUnits::pct);
    }
    wait(5, msec);
  }
}

You need to put a motor stop command in the else statement as well.

But i want it to spin when it’s in the else phase…

Place the motor stop command after the motors spin.
Right now your code turns your motors when not on the line, but never tells them to stop spinning, so they keep rotating.
You could try a rotateFor command, for example
Else{
RotateFor(12 rotations)
}

This would tell your motor to turn 12 times and stop.

Right now, from what I can tell, your code just tells your motors to turn at 50% speed

reflectivity is in the range 0 to 100%, it will always be below 1300

3 Likes

thanks! i didn’t know that, how would i program it to be the arbitrary value displayed on the brain

LineTrackerA.value()

2 Likes

it says "no matching member function to “value”

well, yea, I didn’t specify units, sorry. The correct call is

LineTrackerA.value( analogUnits::range12bit );

API for line tracker is here.
https://api.vexcode.cloud/v5/html/classvex_1_1line.html

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.