Motors running by themselfs

Hello I am new to this forum but I am need some help trying to figure out what I am doing wrong with the user control program I made. When I down load the program onto the cortex the left front drive wheel would continously rotate even when I use or don’t use the controler. I committed out all of the left front drive motor out of the code now the left front drive motor would not rotate at all but the other three would rotate for no reason. Here is my driver control code.
task IntakeProgram ()
{
while(true)
{
if(vexRT(Btn6U) == 1)
{
motor[RIntakeM] = 127;
motor[LIntakeM] = 127;
}
else if(vexRT(Btn6D) == 1)
{
motor[RIntakeM] = -127;
motor[LIntakeM] = -127;
}
else
{
motor[RIntakeM] = 0;
motor[LIntakeM] = 0;
}
}
}
/*
task PresetGoal()
{
while(true)
{
if(nMotorEncoder[RRArmM] < 1000)
if(vexRT(Btn8L) == 1)
{
*/
task usercontrol()
{
int joy_x;
int joy_y;
int threshold = 10;
StartTask(IntakeProgram);
while(1 == 1)
{
joy_x = vexRT[Ch4];
joy_y = vexRT[Ch3];
if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y > 0))
{
motor[LRDriveM] = (joy_y + joy_x);
//motor[LFDriveM] = (joy_y + joy_x);
motor[RRDriveM] = (joy_y - joy_x);
motor[RFDriveM] = (joy_y - joy_x);
}
else if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y < 0))
{
motor[LRDriveM] = (joy_y - joy_x);
// motor[LFDriveM] = (joy_y - joy_x);
motor[RRDriveM] = (joy_y + joy_x);
motor[RFDriveM] = (joy_y + joy_x);
}
else if((abs(joy_x) > threshold) && (abs(joy_y) < threshold))
{
motor[LRDriveM] = joy_x;
// motor[LFDriveM] = joy_x;
motor[RRDriveM] = (-1 * joy_x);
motor[RFDriveM] = (-1 * joy_x);
}
else
{
motor[LRDriveM] = 0;
// motor[LFDriveM] = 0;
motor[RRDriveM] = 0;
motor[RFDriveM] = 0;
}
if(vexRT(Btn5U) == 1)
{
motor[LRArmM] = 127;
motor[LFArmM] = 127;
motor[RRArmM] = 127;
motor[RFArmM] = 127;
}
else if(vexRT(Btn5U) == 1)
{
motor[LRArmM] = -127;
motor[LFArmM] = -127;
motor[RRArmM] = -127;
motor[RFArmM] = -127;
}
else
{
motor[LRArmM] = -127;
motor[LFArmM] = -127;
motor[RRArmM] = -127;
motor[RFArmM] = -127;
}
}
}
If anybody could help me I would greatly appreciate it. I am new to RobotC so I’m sure I have some mistakes in my code.
Sincerly
Zach

Hi Zach

Welcome to the vexforums.

Can you post the #pragma statements from the top of the code as well so we know where the motors are plugged in.

Any chance you plugged a two wire motor into a three wire motor port?

I see a bug in your arm code, you check Btn5U twice (should it be Btn5D?) and never set the arm motors to 0.

Also, in the future, wrap your code in CODE tags. The button for that looks like a # symbol in the editor. Then your code looks like this:

task IntakeProgram ()
{
while(true)
{
if(vexRT(Btn6U) == 1)
{
motor[RIntakeM] = 127;
motor[LIntakeM] = 127;
}
else if(vexRT(Btn6D) == 1)
{
motor[RIntakeM] = -127;
motor[LIntakeM] = -127;
}
else
{
motor[RIntakeM] = 0;
motor[LIntakeM] = 0;
}
}
}
/*
task PresetGoal()
{
while(true)
{
if(nMotorEncoder[RRArmM] < 1000)
if(vexRT(Btn8L) == 1)
{
*/
task usercontrol()
{
int joy_x;
int joy_y;
int threshold = 10;
StartTask(IntakeProgram);
while(1 == 1)
{
joy_x = vexRT[Ch4];
joy_y = vexRT[Ch3];
if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y > 0))
{
motor[LRDriveM] = (joy_y + joy_x);
//motor[LFDriveM] = (joy_y + joy_x);
motor[RRDriveM] = (joy_y - joy_x);
motor[RFDriveM] = (joy_y - joy_x);
}
else if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y < 0))
{
motor[LRDriveM] = (joy_y - joy_x);
// motor[LFDriveM] = (joy_y - joy_x);
motor[RRDriveM] = (joy_y + joy_x);
motor[RFDriveM] = (joy_y + joy_x);
}
else if((abs(joy_x) > threshold) && (abs(joy_y) < threshold))
{
motor[LRDriveM] = joy_x;
// motor[LFDriveM] = joy_x;
motor[RRDriveM] = (-1 * joy_x);
motor[RFDriveM] = (-1 * joy_x);
}
else
{
motor[LRDriveM] = 0;
// motor[LFDriveM] = 0;
motor[RRDriveM] = 0;
motor[RFDriveM] = 0;
}
if(vexRT(Btn5U) == 1)
{
motor[LRArmM] = 127;
motor[LFArmM] = 127;
motor[RRArmM] = 127;
motor[RFArmM] = 127;
}
else if(vexRT(Btn5U) == 1)
{
motor[LRArmM] = -127;
motor[LFArmM] = -127;
motor[RRArmM] = -127;
motor[RFArmM] = -127;
}
else
{
motor[LRArmM] = -127;
motor[LFArmM] = -127;
motor[RRArmM] = -127;
motor[RFArmM] = -127;
}
}
}

Which is infinitely easier to read

Edit: And it will also preserve indentation when you copy from RobotC

Are the wheels moving at full speed, or just barely rotating? If they’re barely rotating, you need Analog Deadbands.

Basically, the VEX Joysticks aren’t calibrated perfectly, and are returning a value of something between +/- 10 even when you aren’t pushing them. That causes your motors to move.

This post has some code with a deadband implemented. It’s commented, and you should be able to make sense of it. Take a look and implement the fix in your code.

You should also calibrate the Joysticks. The instructions are on Page 9 of this document.

EDIT: And I missed that you have thresholds already programmed in. Never mind, sorry.

Did you read his code?. He has analog deadbands. It’s an unusual (to say the least) implementation of arcade control but that can be sorted out after his first problem is fixed.

Yeah, I missed that on the first read-through. I’ve since amended my post.
**
EDIT:** Possibly stupid idea here, but set your Threshold to 50. If that fixes the problem, calibrate the joystick like I said above. I can’t find anything functionally wrong with your drive code, and my only guess is that you somehow are always triggering one of the drive conditionals.

This is the code indented somewhat, if anyone wanted it. Eclipse is being stupid and leaving a huge gap to the left still.


	task IntakeProgram() {
		while (true) {
			if (vexRT(Btn6U) == 1) {
				motor[RIntakeM] = 127;
				motor[LIntakeM] = 127;
			} else if (vexRT(Btn6D) == 1) {
				motor[RIntakeM] = -127;
				motor[LIntakeM] = -127;
			} else {
				motor[RIntakeM] = 0;
				motor[LIntakeM] = 0;
			}
		}
	}
	/*
	 task PresetGoal()
	 {
	 while(true)
	 {
	 if(nMotorEncoder[RRArmM] < 1000)
	 if(vexRT(Btn8L) == 1)
	 {
	 */
	task usercontrol() {
		int joy_x;
		int joy_y;
		int threshold = 10;
		StartTask(IntakeProgram);
		while (1 == 1) {
			joy_x = vexRT[Ch4];
			joy_y = vexRT[Ch3];
			if ((abs(joy_x) > threshold) && (abs(joy_y) > threshold)
					&& (joy_y > 0)) {
				motor[LRDriveM] = (joy_y + joy_x);
				//motor[LFDriveM] = (joy_y + joy_x);
				motor[RRDriveM] = (joy_y - joy_x);
				motor[RFDriveM] = (joy_y - joy_x);
			} else if ((abs(joy_x) > threshold) && (abs(joy_y) > threshold)
					&& (joy_y < 0)) {
				motor[LRDriveM] = (joy_y - joy_x);
				// motor[LFDriveM] = (joy_y - joy_x);
				motor[RRDriveM] = (joy_y + joy_x);
				motor[RFDriveM] = (joy_y + joy_x);
			} else if ((abs(joy_x) > threshold) && (abs(joy_y) < threshold)) {
				motor[LRDriveM] = joy_x;
				// motor[LFDriveM] = joy_x;
				motor[RRDriveM] = (-1 * joy_x);
				motor[RFDriveM] = (-1 * joy_x);
			} else {
				motor[LRDriveM] = 0;
				// motor[LFDriveM] = 0;
				motor[RRDriveM] = 0;
				motor[RFDriveM] = 0;
			}
			if (vexRT(Btn5U) == 1) {
				motor[LRArmM] = 127;
				motor[LFArmM] = 127;
				motor[RRArmM] = 127;
				motor[RFArmM] = 127;
			} else if (vexRT(Btn5U) == 1) {
				motor[LRArmM] = -127;
				motor[LFArmM] = -127;
				motor[RRArmM] = -127;
				motor[RFArmM] = -127;
			} else {
				motor[LRArmM] = -127;
				motor[LFArmM] = -127;
				motor[RRArmM] = -127;
				motor[RFArmM] = -127;
			}
		}
	}

I agree with Ephemeral_Being, it could be the joystick.

I have had this problem multiple times although never with only one channel (usually all 4)
It could also be the motor controller. I have also had that happen to me before :rolleyes:
Try plugging in a different motor controller into that port (best done connected to a free-spinning motor)

best of luck.
Phillip.

edit:
you could try downloading an empty code and see if the motor still spins (empty meaning no setting of motors)
just a thought.

Possibly stupid idea here, but set your Threshold to 50. If that fixes the problem, calibrate the joystick like I said above. I can’t find anything functionally wrong with your drive code, and my only guess is that you somehow are always triggering one of the drive conditionals.

This is a good idea, the joystick may be bad, however, if that were the case I would expect more than one motor to misbehave.

I always detab (replace tabs with spaces) before posting.

He said that the other three started misbehaving after he commented out the one wheel. I don’t know. I’m just trying to come up with something, because I can’t find an issue with the code.

How did I not think of that? I’ll do that in the future, thanks.

I can post the #pragma statements after I get home from school. But all four of my drive motors are plugged into the power expander so they are all in a three wire motor port and thank you for pointing out that I have Btn5U twice and that I didn’t set my arm motors to 0.

I should of probably of said that I did use the sample program (arcade Advance) could using that possibly be a problem?

I have already calibrated the joy sticks but thanks:)

I also have an autonomous program at the very beginning of the program but I do have the program in the VEX competition template could I possibly need a competition switch?

I would believe it could be the joy sticks because all of our controllers are at least four years old and have been used quite a bit and I will change out the motor controllers too because I am pretty sure that those are about the same age and also been used about as much.
Thank you guys for all of your help.:slight_smile:
Zach

Robot C Debugger has a nice virtual competition switch you can use.

The other part of the code may be the root of the issue. Can you please post the rest of the code?

Do you by chance have the setting for continuing tasks between states set?

something like…


bStopTasksBetweenModes = false;

A task started in autonomous (or even pre_auton) may still be running and setting something for the motor to do. The competition control switch will not allow motors to run in disabled mode if you’re using the template proeprly. But once you get to the driver control part, the next time around the loop of that still running background task, it’ll just keep on humming setting motor values and whatever it’s coded to do in that other task.

If you say stopTask at the end of autonomous, it may never reach there since the competition switch just dumps you out of autonomous sot he stop task may not get hit.

For the joystick, check the debugger to see what the joystick channel values are as well as the motor values. That will tell if you have a mis-calibrated joystick and it’s time to get the paperclip out to reset it and that whole procedure. We had one joystick stuck really badly being 36 off and recalibration did not help - it was broken.

Have you performed an exorcism? I mean a forced firmware reload?

Here is entire code

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1,    Gyro,           sensorGyro)
#pragma config(Sensor, in2,    FIntakeLS,      sensorReflection)
#pragma config(Sensor, in3,    RIntakeLS,      sensorReflection)
#pragma config(Sensor, in4,    AutoPot,        sensorPotentiometer)
#pragma config(Sensor, dgtl1,  RUS,            sensorSONAR_mm)
#pragma config(Sensor, dgtl3,  FUS,            sensorSONAR_mm)
#pragma config(Sensor, dgtl5,  BLimitSwitch,   sensorTouch)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           RRArmM,        tmotorVex393, openLoop, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor,  port2,           RFArmM,        tmotorVex393, openLoop)
#pragma config(Motor,  port3,           RIntakeM,      tmotorVex393, openLoop)
#pragma config(Motor,  port4,           RRDriveM,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port5,           RFDriveM,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port6,           LIntakeM,      tmotorVex393, openLoop)
#pragma config(Motor,  port7,           LRDriveM,      tmotorVex393, openLoop)
#pragma config(Motor,  port8,           LFDriveM,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           LFArmM,        tmotorVex393, openLoop)
#pragma config(Motor,  port10,          LRArmM,        tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)
#pragma competitionControl(Competition).
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c"
void pre_auton()
{
  bStopTasksBetweenModes = true;
}
task autonomous()
{
	 SensorType[in1] = sensorNone;
	 SensorType[in1] = sensorGyro;
	 int degrees10 = 900;
	 nMotorEncoder[RRArmM] = 0; //Clears The Integrated Arm Encoder
	 if(SensorValue(RIntakeLS) < 200)
	 {
	   motor[RIntakeM] = 127;
	   motor[LIntakeM] = 127;
	 }
	 else(SensorValue(RIntakeLS) == 200);
	 {
	   motor[RIntakeM] = 0;
	   motor[LIntakeM] = 0;
	 }
  while(SensorValue(FUS) < 557.022) //Moves Robot Forward Torwards The Wall in mm
  {
  	motor[LRDriveM] = 127;
  	motor[LFDriveM] = 127;
  	motor[RRDriveM] = 127;
  	motor[RFDriveM] = 127;
  }
  while(SensorValue(FUS) > 540) //Backs The Robot Away From The Wall
  {
  	motor[LRDriveM] = -127;
  	motor[LFDriveM] = -127;
  	motor[RRDriveM] = -127;
  	motor[RFDriveM] = -127;
  }
	while(abs(SensorValue[Gyro]) < 1200) //Turns The Robot Counterclockwise 120 Deg.
	{
		motor[LRDriveM] = -127;
		motor[LRDriveM] = -127;
		motor[RRDriveM] = 127;
		motor[RFDriveM] = 127;
	}
		motor[LRDriveM] = 10; //Brief Brake To Eliminate Drift
		motor[LRDriveM] = 10;
		motor[RRDriveM] = -10;
		motor[RFDriveM] = -10;
	while(SensorValue[RUS] < 100) //Moves Robot Forward towards The Bump
	{
		motor[LRDriveM] = 127;
		motor[LFDriveM] = 127;
		motor[RRDriveM] = 127;
		motor[RFDriveM] = 127;
	}
	if(nMotorEncoder[RRArmM] < 100)
	{
		motor[RRArmM] = 127;
		motor[RFArmM] = 127;
		motor[LRArmM] = 127;
		motor[LFArmM] = 127;
	}
	else(nMotorEncoder[RRArmM] = 100);
	{
		motor[RRArmM] = 0;
		motor[RFArmM] = 0;
		motor[LRArmM] = 0;
		motor[LFArmM] = 0;
	}

	AutonomousCodePlaceholderForTesting();  // Remove this function call once you have "real" code.
}

task IntakeProgram ()
{
	while(true)
	{
		if(vexRT(Btn6U) == 1)
		{
			motor[RIntakeM] = 127;
			motor[LIntakeM] = 127;
		}
		else if(vexRT(Btn6D) == 1)
		{
			motor[RIntakeM] = -127;
			motor[LIntakeM] = -127;
		}
		else
		{
			motor[RIntakeM] = 0;
			motor[LIntakeM] = 0;
		}
	}
}
/*
task PresetGoal()
{
	while(true)
	{
		if(nMotorEncoder[RRArmM] < 1000)
		if(vexRT(Btn8L) == 1)
		{
*/
task usercontrol()
{
	 int joy_x;
  int joy_y;
  int threshold = 10;
	StartTask(IntakeProgram);
  while(1 == 1)
  {
    joy_x = vexRT[Ch4];
    joy_y = vexRT[Ch3];
    if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y > 0))
    {
      motor[LRDriveM] = (joy_y + joy_x);
      //motor[LFDriveM] = (joy_y + joy_x);
      motor[RRDriveM] = (joy_y - joy_x);
      motor[RFDriveM] = (joy_y - joy_x);
    }
    else if((abs(joy_x) > threshold) && (abs(joy_y) > threshold) && (joy_y < 0))
    {
      motor[LRDriveM] = (joy_y - joy_x);
     // motor[LFDriveM] = (joy_y - joy_x);
      motor[RRDriveM] = (joy_y + joy_x);
      motor[RFDriveM] = (joy_y + joy_x);
    }
    else if((abs(joy_x) > threshold) && (abs(joy_y) < threshold))
    {
      motor[LRDriveM] = joy_x;
     // motor[LFDriveM] = joy_x;
      motor[RRDriveM] = (-1 * joy_x);
      motor[RFDriveM] = (-1 * joy_x);
    }
    else
    {
      motor[LRDriveM] = 0;
    //  motor[LFDriveM] = 0;
      motor[RRDriveM] = 0;
      motor[RFDriveM] = 0;
    }
    if(vexRT(Btn5U) == 1)
    {
    	motor[LRArmM] = 127;
    	motor[LFArmM] = 127;
    	motor[RRArmM] = 127;
    	motor[RFArmM] = 127;
    }
    else if(vexRT(Btn5U) == 1)
    {
    	motor[LRArmM] = -127;
    	motor[LFArmM] = -127;
    	motor[RRArmM] = -127;
    	motor[RFArmM] = -127;
    }
    else
    {
    	motor[LRArmM] = -127;
    	motor[LFArmM] = -127;
    	motor[RRArmM] = -127;
    	motor[RFArmM] = -127;
    }
  }
}

Could you tell me how to find out the joy stick values I am new to RobotC:o
I have not tried to download new firmware yet but I will deffinety try that thank you for the tips.
Zach

Hmm. I don’t see anything off hand that would be causing the problem.

Start the debugger once you download the program to your robot via Vexnet.

The robot menu has a debugger window sub menu. If you expand the menu level to expert mode you will see a few more debugger options.

You can choose the motor screen to see what values are being sent to the drive motors you say are going off their rockers.

Pop up the local variables window and you will see joy_x and joy_y. If you have trouble viewing them, just move joy_x and joy_y to global variables and pop up that one.

Debug lines can also do the trick. Add this line near the joystick variables.

writeDebugLineString(“joy_x %d joy_y %d”, joy_x, joy_y);

or something like this… This allows you to see the time (since you don’t seem to wait in your loop it will loop around quite quickly.

writeDebugLineString(“time %d |ch4 |%d |ch3 |%d”, nPgmTime, VexRT[Ch2], VexRT[Ch3]);

So to slow it down a bit add this line to wait 25 milliseconds somewhere in the while loop (usually at the end of it):

wait1Msec(25);