Motors spinning while Program is off

Hello there. My team is facing an issue when using our drivetrain; one side of our drivetrain continues to spin even after we have stopped touching our controller and when the program has ended. This leads to us being unable to drive or control our drive train. I have attached a video to this post explaining and demonstrating the issue. Please reach out if anyone has any explanations or solutions to this problem. Thank you.

Video: https://drive.google.com/file/d/1chKxCKfZmlnYTCVEJHK-sn9uJ9Le-NVv/view?usp=sharing

Please post the program here or, if using VEXcode, use feedback when the program is open.

Is firmware up to date on the V5 brain ? Any error messages on the brain’s screen ?

The code I am using is in this reply. The brain’s software is up to date and has no errors appearing on the screen. Thank you for the reply.

#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>


#include "vex.h"

using namespace vex;

// Brain should be defined by default
brain Brain;


// START V5 MACROS
#define waitUntil(condition)                                                   \
  do {                                                                         \
    wait(5, msec);                                                             \
  } while (!(condition))

#define repeat(iterations)                                                     \
  for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS


// Robot configuration code.
motor MotorGroup1MotorA = motor(PORT1, ratio18_1, false);
motor MotorGroup1MotorB = motor(PORT2, ratio18_1, false);
motor_group MotorGroup1 = motor_group(MotorGroup1MotorA, MotorGroup1MotorB);

controller Controller1 = controller(primary);


// generating and setting random seed
void initializeRandomSeed(){
  int systemTime = Brain.Timer.systemHighResolution();
  double batteryCurrent = Brain.Battery.current();
  double batteryVoltage = Brain.Battery.voltage(voltageUnits::mV);

  // Combine these values into a single integer
  int seed = int(batteryVoltage + batteryCurrent * 100) + systemTime;

  // Set the seed
  srand(seed);
}



void vexcodeInit() {

  //Initializing random seed.
  initializeRandomSeed(); 
}


// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
  printf("VEXPlaySound:%s\n", soundName);
  wait(5, msec);
}



// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;

#pragma endregion VEXcode Generated Robot Configuration

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       {author}                                                  */
/*    Created:      {date}                                                    */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

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


competition Competition;



// "when started" hat block
//Set up Variables
bool PTO = false;
bool backClamp = false;

//Set up Base Motors
motor L1 = motor(PORT6, ratio6_1, true); //Left drive 1
motor L2 = motor(PORT7, ratio6_1, true);//Left drive 2
motor L3 = motor(PORT10, ratio6_1, true);//Left drive 3
motor Intake = motor(PORT5, ratio6_1, true);//Intake
motor L5 = motor(PORT4, ratio6_1, true); // Arm motor 1
motor R1 = motor(PORT1, ratio6_1, false);//Right drive 1
motor R2 = motor(PORT11, ratio6_1, false);//Right drive 2
motor R3 = motor(PORT3, ratio6_1, false);//Right drive 3
motor R5 = motor(PORT9, ratio6_1, false); // Arm motor 2

//Set up Motorgroups
motor_group mgl1 = motor_group(L1,L2,L3); // left drivetrain
motor_group mgr1 = motor_group(R1,R2,R3); // right drivetrain
motor_group mga = motor_group( R5, L5);  // arm 

//Set up Inertial
inertial inertial9 = inertial(PORT20);
//set up Optical
//Comented for test**** optical optical13 = optical(PORT13);
//Set up Smart Drives
smartdrive sd = smartdrive(mgl1, mgr1, inertial9, 259.3385, 320, 40, mm, 0.75);
//Set up Solenoids
digital_out Clamp = digital_out(Brain.ThreeWirePort.A);
digital_out IntPiston = digital_out(Brain.ThreeWirePort.B); 

//Set up variables
bool ArmVar = false;
bool ClampVar = false;
bool IntPistonVar = false;
bool IntVar = false;
// "when autonomous" hat block

int onauton_autonomous_0() {
  //Get mobile goal a
  sd.driveFor(reverse, 10, inches);
  sd.turnFor(left,20, degrees);
  sd.driveFor(reverse,50,inches);
  Clamp.set(true);
  //Get ring 1
  sd.turnFor(right,20,degrees);
  Intake.spin(forward);
  sd.driveFor(forward, 20,inches);
  //Get ring 2
  sd.turnFor(left,80, degrees);
  sd.driveFor(forward,54,inches);
  sd.turnFor(left,100,degrees);
  Clamp.set(false);
  //Touch ladder
  sd.driveFor(forward,20,inches);
  return 0;
}
//optical sensor function
//int ringcolor() {
  //double ringhue = optical13.hue();
  //if(ringhue<=10.0 || ringhue>=350.0) {
     
  //}

// "when driver control" hat block
int ondriver_drivercontrol_0() {
  Intake.setVelocity(80,percent);
  while (true){
    mgl1.setVelocity(((Controller1.Axis3.position() + Controller1.Axis1.position()) * fabs(Controller1.Axis3.position() + Controller1.Axis1.position()) / 100)*.8, percent);
    mgr1.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position()) * fabs(Controller1.Axis3.position() - Controller1.Axis1.position()) / 100)*.8, percent);

    mgl1.spin(forward);
    mgr1.spin(forward);

    Brain.Screen.print(L1.velocity(percent));
    Brain.Screen.print(",");
    Brain.Screen.print(L2.velocity(percent));
    Brain.Screen.print(",");
    Brain.Screen.print(L3.velocity(percent));
    Brain.Screen.newLine();









    if (Controller1.ButtonR2.pressing()) {
      Intake.spin(forward);
    }
    else if (Controller1.ButtonR1.pressing()){
      Intake.spin(reverse);
    }
    else{
      Intake.stop();
    }

    if (Controller1.ButtonUp.pressing()) {
      mga.spin(forward);
    }
    else if (Controller1.ButtonDown.pressing()){
      mga.spin(reverse);
    }
    else{
      mga.stop();
    }


    if (Controller1.ButtonX.pressing()){
      ClampVar = !ClampVar;
      Clamp.set(ClampVar);
      waitUntil((!Controller1.ButtonX.pressing()));
      Brain.Screen.print(ClampVar);
      
    }

    if (Controller1.ButtonRight.pressing()){
      IntPistonVar = !IntPistonVar;
      IntPiston.set(IntPistonVar);
      
      waitUntil((!Controller1.ButtonRight.pressing()));
      Brain.Screen.print(IntPistonVar);
    }

    if (Controller1.ButtonY.pressing()){ // arm control
      mga.spin(forward);
    }

    if (Controller1.ButtonB.pressing()) {
      mga.spin(reverse);
    }
  }
  return 0;
}






void VEXcode_driver_task() {
  // Start the driver control tasks....
  vex::task drive0(ondriver_drivercontrol_0);
  while(Competition.isDriverControl() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  drive0.stop();
  return;
}

void VEXcode_auton_task() {
  // Start the auton control tasks....
  vex::task auto0(onauton_autonomous_0);
  while(Competition.isAutonomous() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  auto0.stop();
  return;
}


int main() {
  vex::competition::bStopTasksBetweenModes = false;
  Competition.autonomous(VEXcode_auton_task);
  Competition.drivercontrol(VEXcode_driver_task);

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

}

My best guess is that you have a hardware issue with either the V5 brain, a smart cable or one (or more) motors. I don’t see an issue with the code and a simple test here did not show any issues with the code or vexos (not that I really expected it to, but I had to check).

Try first to determine which motor (or motors) are still running. Is it all three on one side of the drivetrain or just one of them.

Assuming you determine just one motor is still running, try replacing the smart cable first.

If that doesn’t help, move that motor to another port on the V5 brain and reconfigure the code for that port.

If the issue still exists, swap out the motor.

Let us know if any of this helps.

2 Likes