Automatic robot when not coded to be automatic

Hi, I finished designing and coding a robot, but I came up to a problem when coding the robot - the robot moves by itself even when it is not supposed to in the code. It just starts powering motors as soon as I turn it on.

#pragma config(Motor,  port1,           LeftMotor,     tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor,  port8,           LiftMotor2,    tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port9,           LiftMotor,     tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port10,          RightMotor,    tmotorVex393_HBridge, openLoop, reversed, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
	while (true) {
		motor[LeftMotor] = vexRT[Ch3];
		motor[RightMotor] = vexRT[Ch2];
		motor[LiftMotor] = 0.5 * (vexRT[Btn5U] - vexRT[Btn5D]); 
		motor[LiftMotor2] = 0.5* (vexRT[Btn5U] - vexRT[Btn5D]);
	}

}

The main problem is the LiftMotor and LiftMotor2 (the motors in ports 8 and 9). The Right and Left Motors work fine and do not start moving as soon as the robot is turned on.

Whenever you’re using buttons, use if, else if, and else statements. To add on, the buttons have value of 1 when pressed and 0 when released. If you were wanting to program the buttons, try something like this:


if(vexRT[Btn5U]==1){
motor[LiftMotor]=127;
motor[LiftMotor2]=127;
}
else if(vexRT[Btn5D]==1){
motor[LiftMotor]=-127;
motor[LiftMotor2]=-127;
}
else{
motor[LiftMotor]=0;
motor[LiftMotor2]=0;
}

I just tried the code (changed it to match how i reversed the motors) but it still did the same thing again. Could it be something with the wiring?

Not necessary actually. As you said, the buttons have a value of 1 when pressed and 0 when released. Buttons can be used in mathematical computations as @Laura used them.

At what speed do you want your lift motors to operate? Your code seems to imply ±63, but your code seems like it would actually run the motors at 0 all the time.

Try changing your


0.5 *

to


63 *

and see if it helps.

My problem isn’t my motor speed. Its the fact that the lift motors are moving all by themselves without my even touching the joystick, even though I’ve coded them to move only if the 5U/D buttons are pressed.

Do you all need to see a video of what is happening? I feel like I’m confusing all of you (sorry!)

True, true true. But it seems like the motor power will only have a value of 0.5, -0.5, or 0 out of 125 with how she did it. Other than that, since it’s going all the time it sounds like a hardware issue.

But the RobotC compiler may be doing something unexpected with the 0.5. Motor speeds are integer values from -127 to +127. Using an integer in that range instead of 0.5 may well fix the problem.

Nope, it still didn’t work. I’m guessing its something involving wiring but I’m not sure if it is though, could it?
If you guys want a video to see what’s happening (if it can help in any way) here it is: - YouTube

The video shows that you have no motor controllers. Motor controllers aren’t needed for 1 and 10, but 2-9 it needs a controller. Make sure you add them!

Thanks! That solved the problem, and I’ll remember that for sure.

So just for a simple explanation as to what was going on.

3 wire ports on the cortex output
Signal (communication of how much % of full power to send and what direction)
VCC (full power)
Gnd (ground)

On the 2 wire ports it sends
Power (output you select)
Gnd

The motor controller takes the communication and the full power line and produces the correct power for the motor. The cortex just has 2 of them built into ports 1 and 10.

What would have made the problem very obvious would be if you said that running no code at all made the motors turn on. (they would have)