Usercontrol

Sighs My brain’s really tired but my code is not working. Even though it looks perfectly fine with out any compile errors, my usercontrol code does not work. I haven’t tested auton yet because I didn’t make an auton yet but the usercontrol just doesn’t function. It’s probably not an engineering problem and probably just my code. But I can’t see what’s wrong with it. Maybe my eyes are tired… I didn’t use the PID yet so that shouldn’t be the problem…

this is the usercontrol code.
I can’t attach the full code because its too long? And I can’t attach .c as a file so I attached it in a .doc


task usercontrol()
{
	// User control code here, inside the loop

	while (true)
	{
		int manualcontrol;
		/*--------------------------------------------------------------------------------------------------------------------------------*/
	/*	DR4B(1,0);
		wait1Msec(1000);
		float offsetLeft = SensorValue[leftDR4BPot];
		float offsetRight = SensorValue[rightDR4BPot];
		float wantedHeight = 0;
		float restHeight = 0;
		float coneHeight = 25; //needs to be set
		float stationaryGoalHeight = 500; //needs to be set
		float maxHeight = 950; //needs to be set
		float manualcontrol;
		DR4BTargetLeft = SensorValue[leftDR4BPot];
		DR4BTargetRight = SensorValue[rightDR4BPot];
		startTask(DR4BPID);

		int DR4BcontrolState = 0;
		*/
/*--------------------------------------------------------------------------------------------------------------------------------*/

		while (true)
		{

			/*NOTES:
			Main controller is Stacking and DR4B controls
			Partner is Drive and MOGO
			*/
			/*--------------------------------------------------------------------------------------------------------------------------------*/
			//DR4B
		/*	if(vexRT(Btn7U) == 1)//DR4B moves up 1 cone height
			{
				wantedHeight = coneHeight;
				coneHeight = coneHeight + 1;
			}
			if(vexRT(Btn7D) == 1)//DR4B moves down 1 cone height
			{
				wantedHeight = coneHeight - 1;
			}
			else if(vexRT(Btn7L) == 1)//DR4B moves to stationary goal height
			{
				wantedHeight = stationaryGoalHeight;
			}
			else if(vexRT(Btn7R) == 1)//DR4B moves all the way down
			{
				wantedHeight = 0;
			}
			else if(vexRT(Btn5U) == 1)//Calculation of offset and wanted height making Target height
			{
				DR4BTargetLeft = wantedHeight + offsetLeft;
				DR4BTargetRight = wantedHeight + offsetRight;
			}
			if(vexRT(Btn8R) == 1)//Recalibrate offset for when Potentiometer malfunctions
			{
				offsetLeft = SensorValue(leftDR4BPot);
				offsetRight = SensorValue(rightDR4BPot);
			}
			*/
			/*--------------------------------------------------------------------------------------------------------------------------------*/
			//DR4B Manualcontrol
			if(vexRT(Btn8L) == 1 && manualcontrol != 1)//Enable manual control
			{
				manualcontrol = 1;
			}
			if(vexRT(Btn8L) == 1 && manualcontrol == 1)//Disable manual control
			{
				manualcontrol = 0;
			}
			if(vexRT(Btn8U) == 1 && manualcontrol == 1)//Manual control DR4B moves up
			{
				motor[leftDR4B] = 90;
				motor[rightDR4B] = 90;
			}
			else if(vexRT(Btn8D) == 1 && manualcontrol == 1)//Manual control DR4B moves down
			{
				motor[leftDR4B] = -90;
				motor[rightDR4B] = -90;
			}
			else if(manualcontrol == 1 && (vexRT(Btn8D) == 0) && vexRT(Btn8U) == 0)
			{
				motor[leftDR4B] = 0;
				motor[rightDR4B] = 0;
			}

	/*--------------------------------------------------------------------------------------------------------------------------------*/
			//Stacking
		/*	if(vexRT(Btn6U) == 1)//Starts stacking process depending on arm encoder
			{
				stacking(1);
			}
		*/
	/*--------------------------------------------------------------------------------------------------------------------------------*/
			// Drive
			rightDrive(vexRT(Ch2Xmtr2));//Right side drive responds to right joystick (PID code not used here)
			leftDrive(vexRT(Ch3Xmtr2));//Left side driving responds to left joystick (PID code not used here)

	/*--------------------------------------------------------------------------------------------------------------------------------*/
			//MOGO
			if(vexRT(Btn6UXmtr2) == 1)//MoGO lift moves up
			{
				moGo(1,0);
			}
			else if(vexRT(Btn6DXmtr2) == 1)//MoGo lift moves down
			{
				moGo(0,1);
			}
			else// else stay
			{
				moGo(0,0);
			}

		}
	}

	//UNAUTOMATED STACKING
	/*--------------------------------------------------------------------------------------------------------------------------------*/
		  //Arm Control
			if(vexRT(Btn7UXmtr2) == 1)
			{
				armControl(0,1);
			}
			else if(vexRT(Btn7DXmtr2) == 1)
			{
				armControl(1,0);
			}
			else
			{
				armControl(0,0);
			}
	/*--------------------------------------------------------------------------------------------------------------------------------*/
		//Rollers
		if(vexRT(Btn7LXmtr2) == 1)
		{
			motor[claw] = 90;
		}
		else if(vexRT(Btn7RXmtr2) == 1)
		{
			motor[claw] = -90;
		}
		else
		{
			motor[claw] = 0;
		}
}	/*--------------------------------------------------------------------------------------------------------------------------------*/


leroy code 3.0.docx (13 KB)

These are the compile errors. Its just that I didn’t use the PID yet…
compile error leroy 3.0.PNG

I see a couple of problems.
You have two nested while loops, the code for arm control and claw is outside both of them and will never run.
The logic controlling the manualcontrol variable is broken. Both of these conditions will be true, if Btn8L is pressed, each time around the loop.

if(vexRT(Btn8L) == 1 && manualcontrol != 1)//Enable manual control
  {
    manualcontrol = 1;
  }
  if(vexRT(Btn8L) == 1 && manualcontrol == 1)//Disable manual control
  {
    manualcontrol = 0;
  }

The first test will set manualcontrol to 1, the second test will then set it back to 0.

@jpearman Thank you for replying. I will fix the arm control and claw but I don’t get the logics of manualcontrol.

What I wanted was to:

  1. if button 8l is pressed and manualcontrol is not on, set manual control on.
  2. if button 8l is pressed again(when manual control is on) the disable manual control.

Please specify on what you mean.

Sorry, TT
Thank you,

Rougescaless

So lets look at the code you have

if(vexRT(Btn8L) == 1 && manualcontrol != 1)//Enable manual control
  {
    manualcontrol = 1;
  }
if(vexRT(Btn8L) == 1 && manualcontrol == 1)//Disable manual control
  {
    manualcontrol = 0;
  }

Lets assume you press 8 Left button and manual control is 0

The first if statement says “if button pressed and manual control is not 1” if that is true then you set manual control to 1
So now the variable manual control is 1
The next statement says “if button pressed and manual control is 1” if that is true, and it will be as you just changed the variable, then set manual control back to 0. The only time you will leave manual control set to one is if you happen to release the button between the two tests which will happen occasionaly.

Here is an old example of one way to toggle a variable.
https://vexforum.com/t/christopher-dock-stemrobotics-scrimmage-results/15266/1

@jpearman okay. I looked at the other thread and I understood what you mean. The DR4B manual control now is made as a toggle button and the arm and rollers are both inside the one while loop. But after I tested it, the only things that works are the tank drives. This might be an engineering problem with the wires etc. But I think its the code because of my bad coding skills. Any ideas? I will try to check my code again.
Thank you,