V5 Smart Motors Not Going Full Speed

Hello! I am sure this has already been posted about, and answered, so I am sorry for a potential accidental repost. With that being said, I was unable to find a viable answer to my issue. In my code, my drivetrain is going full speed as wanted. But every other motor is going at a much slower speed than they are able to. (As running them before with different code allowed them to go full speed).

Example Of Problematic Code

----------------------------------------------------------------------------------------------------------

// Include the V5 Library
#include "vex.h"
  
// Allows for easier use of the VEX Library
using namespace vex;

int Brain_precision = 0, Console_precision = 0, Controller1_precision = 0;

double dtDrive, dtTurn;

// Used to find the format string for printing numbers with the
// desired number of decimal places
const char* printToBrain_numberFormat() {
  // look at the current precision setting to find the format string
  switch(Brain_precision){
    case 0:  return "%.0f"; // 0 decimal places (1)
    case 1:  return "%.1f"; // 1 decimal place  (0.1)
    case 2:  return "%.2f"; // 2 decimal places (0.01)
    case 3:  return "%.3f"; // 3 decimal places (0.001)
    default: return "%f"; // use the print system default for everthing else
  }
}

// "when started" hat block
int whenStarted1() {
  while (true) {
    dtDrive = Controller1.Axis3.position();
    if (dtDrive > 30.0) {
      Drivetrain.setDriveVelocity(100.0, percent);
    } else if (dtDrive < -30.0) {
      Drivetrain.setDriveVelocity(-100.0, percent);
    } else {
      Drivetrain.setDriveVelocity(0.0, percent);
    }
    while (true) {
      dtTurn = Controller1.Axis1.position();
      if (dtTurn > 30.0) {
        Drivetrain.setTurnVelocity(100.0, percent);
      } else if (dtTurn < -30.0) {
        Drivetrain.setTurnVelocity(-100.0, percent);
      } else {
        Drivetrain.setTurnVelocity(0.0, percent);
      }
    wait(5, msec);
    }
    if (Controller1.ButtonX.pressing()) {
      forkLift.setVelocity(100.0, percent);
    } else if (Controller1.ButtonB.pressing()) {
      forkLift.setVelocity(-100.0, percent);
    } else {
      forkLift.setVelocity(0.0, percent);
    }
    if (Controller1.ButtonR1.pressing()) {
      armMotors.setVelocity(100.0, percent);
    } else if (Controller1.ButtonR2.pressing()) {
      armMotors.setVelocity(-100.0, percent);
    } else {
      armMotors.setVelocity(0.0, percent);
    }
    if (Controller1.ButtonL1.pressing()) {
      hook.setVelocity(100.0, percent);
    } else if (Controller1.ButtonL2.pressing()) {
      hook.setVelocity(-100.0, percent);
    } else {
      hook.setVelocity(0.0, percent);
    }
  wait(5, msec);
  }
  return 0;
}


int main() {
  // post event registration

  // set default print color to black
  printf("\033[30m");

  // wait for rotation sensor to fully initialize
  wait(30, msec);

  whenStarted1();
}

-Archer (VRC Team 25460Z)

Perhaps check if the motors are defined with the gearset that matches what is physically in the motors of the robot?

1 Like

@Mentor_355v

I made sure, all motors are using the 18:1 cartridge. Although I am using gear reductions on all of them externally. Would that be something I would need to specify in code, if so how would I do that?

The code looks like a converted blocks project. Is that the actual code or are you actually programming in blocks ? I ask because the code as posted should probably not work at all, there are no “spin” commands for drivetrain or motors. setVelocity, setDriveVelocity and setTurnVelocity don’t usually make motors move (they can if motor was told to spin at some point).

2 Likes

@jpearman

Yes this is converted from block code, sorry for the confusion, as this was the best way to present the code in my question.

Among other things, it looks like you have one or more nested while(true) loops. I don’t see how the code would ever tell anything other than the Drivetrain to change velocity.

// "when started" hat block
int whenStarted1() {
  while (true) {
    dtDrive = Controller1.Axis3.position();
    if (dtDrive > 30.0) {
      Drivetrain.setDriveVelocity(100.0, percent);
    } else if (dtDrive < -30.0) {
      Drivetrain.setDriveVelocity(-100.0, percent);
    } else {
      Drivetrain.setDriveVelocity(0.0, percent);
    }
    while (true) {
      dtTurn = Controller1.Axis1.position();
      if (dtTurn > 30.0) {
        Drivetrain.setTurnVelocity(100.0, percent);
      } else if (dtTurn < -30.0) {
        Drivetrain.setTurnVelocity(-100.0, percent);
      } else {
        Drivetrain.setTurnVelocity(0.0, percent);
      }
      wait(5, msec);
    }  // Mentor_355v sees no exit condition for this loop
    if (Controller1.ButtonX.pressing()) {
      forkLift.setVelocity(100.0, percent);
    } else if (Controller1.ButtonB.pressing()) {
      forkLift.setVelocity(-100.0, percent);
    } else {
      forkLift.setVelocity(0.0, percent);
    }
    if (Controller1.ButtonR1.pressing()) {
      armMotors.setVelocity(100.0, percent);
    } else if (Controller1.ButtonR2.pressing()) {
      armMotors.setVelocity(-100.0, percent);
    } else {
      armMotors.setVelocity(0.0, percent);
    }
    if (Controller1.ButtonL1.pressing()) {
      hook.setVelocity(100.0, percent);
    } else if (Controller1.ButtonL2.pressing()) {
      hook.setVelocity(-100.0, percent);
    } else {
      hook.setVelocity(0.0, percent);
    }
    wait(5, msec);
  }
  return 0;
}
1 Like