PID in Driver Control help ROBOTC

Hi forum, I’m scratching my head trying to run a task function in the operator control.
Can you check the code if it is in the correct format to call the task.
From my initial test the task start and stop all the time.

Any suggestion will be appreciated.

Thanks

 
task usercontrol()
{
              // User control code here, inside the loop
              int ClawOpen;
              int ClawClose;
              int armRaiseM; // Arm raise middle
              int armRaiseH; // Arm raise high
              int armRaiseB; // Arm raise bottom
              armPidRequestedValue = SensorValue( PotArm ); // Set initial position of arm
              startTask( armPidController ); // Start arm PID task
              while (true)
              {
                           sLimit = SensorValue( ArmLimitSwitch );
                           aPot = SensorValue( PotArm );
 
                           //Display Arm angle
                           clearLCDLine(0);
                           clearLCDLine(1);
                           displayLCDCenteredString(0, "Driver Mode");
                           displayLCDNumber(1, 6, sLimit);
 
 
                           joyvalLR = vexRT Ch1 ]; //Get joystick value for left and right
                           joyvalFB = vexRT Ch2 ]; //Get joystick value for front and back
 
                           cubicForm( joyvalLR, 1);
                           cubicForm( joyvalFB, 2);
 
                           movBot ( rCubicFB, rCubicLR, rCubicSLR );
 
                           armRaiseB = vexRT  Btn7D ]; // Get joystick value to put the arm at the bottom
                           armRaiseM = vexRT  Btn7R ]; // Get joystic value to put the arm at middle position
                           armRaiseH = vexRT  Btn7U ]; // Get joystic value to put the arm at high position
 
                           // --------------Joystick Preset-------------------//
                           if ( armRaiseB == 1 )
                           {
                                         armPidRequestedValue = 750;
                           }
                           if ( armRaiseM == 1 )
                           {
                                         armPidRequestedValue = 1200;
                           }
                           if ( armRaiseH == 1 )
                           {
                                         armPidRequestedValue = 2500;
                           }
                           // --------------Joystick Preset-------------------//
 
                           // --------------Joystick Manual-------------------//
                           joyvalUD = vexRT Ch3 ]; // Get joystick value to raise and lower the arm
 
                           if ( (sLimit == 1 && vexRT Ch3 ] < 0 && aPot < 800) || (aPot > 2500 && vexRT Ch3 ] > 0))
                           {
                                         motor port3 ] = 0; // RBA
                                         motor port8 ] = 0; // LBA
                                         motor port4 ] = 0; // LTA
                                         motor port9 ] = 0; // RTA
                           }
                           else
                           {
                                         motor port3 ] = vexRT Ch3 ]; // RBA
                                         motor port8 ] = -(vexRT Ch3 ]); // LBA
                                         motor port4 ] = vexRT Ch3 ]; // LTA
                                         motor port9 ] = -(vexRT Ch3 ]); // RTA
                           }
                           // --------------Joystick Manual-------------------//
 
                           ClawOpen = vexRT Btn6D ]; // Get joystick value to open the claw
                           ClawClose = vexRT Btn6U ]; // Get joystic value to close the claw
 
                           if (ClawOpen == 1) // Open the Claw
                           {
                                         SensorValue[ClawLeft] = 1;
                                         SensorValue[ClawRight] = 1;
                           }
                           if (ClawClose == 1) // Close the Claw
                           {
                                         SensorValue[ClawLeft] = 0;
                                         SensorValue[ClawRight] = 0;
                           }
              }
}

Are you checking for manual joystick control within the armPidController task so that you are not fighting the task? If you have told PID to set the arm at 1200, then attempt to drive the arm away from that number via joystick control you will be sending conflicting values to the motors.

I had a similar set up on my toy robot that looked like this:


	// Start arm  control
	startTask(armControl);
	armTarget = 1000; // be sure this works with auton endings

	while (true)
	{
		// arm control on 8R+D
		if (vexRT[Btn8R] == 1) {armTarget = 3350;} // score
		if (vexRT[Btn8U] == 1) {armTarget = 2100;} // fence height
		if (vexRT[Btn8L] == 1) {armTarget = 1200;} // lift stars just above floor
		if (vexRT[Btn8D] == 1) {armTarget = 1000;} // gather height
		// arm fine tune on 6U+D
		if (vexRT[Btn6U] == 1 && SensorValue(arm_Pot) <= 2600) //  full speed if well below upper limit
		{
			set_armPower(100);
			armTarget = SensorValue(arm_Pot);
		}
		else if (vexRT[Btn6U] == 1 && SensorValue(arm_Pot) <= 3400) //  low speed near upper limit
		{
			set_armPower(50);
			armTarget = SensorValue(arm_Pot);
		}
		else if (vexRT[Btn6D] == 1 && SensorValue(arm_Pot) >= 820) // if above lower limit
		{
			set_armPower(-50);
			armTarget = SensorValue(arm_Pot);
		}

While driving it with the controller, the target value is constantly changing to keep the PD task happy and hold the arm at the end wherever it was stopped.

That was exactly it. The values were conflicting themselves and by following the concept of your code, we were finally able to do what we wanted! We used the joystick to send the values to a PID function and it’s working very well. Thank you very much.