Automated Movement and Resultant Stuttering

Our robot has an articulated arm for manipulation of rings, and I am attempting to prepare it for worlds by programming in height presets. The height presets will be determined by button presses on panel 8 of joystick 1. The up button will result in the height necessary for high goals, the left button will be for movable goals, and the bottom button will be for picking up rings. The right button is to be an abort button. Thus far, I have only written the code for the high goal. The angle of the arm is determined by a potentiometer with the wrist of the arm determined by another.

Now, when I hit the up button on panel 8, it does activate the code in that segment, but at a painfully slow pace, almost as if the motors were set at 20 instead of 127. In fact, this movement is so slow that I didn’t notice it at first and inserted into the program a line of code to make the left drive wheels turn to see if anything was happening. This resulted in them turning, but the wheels did not turn smoothly. They stuttered. Why is this? See code (converted to C for reader convenience):

void OperatorControl ( unsigned long ulTime )
{
while ( 1 ) // Insert Your RC Code Below
{
ldrive = GetJoystickAnalog( 1 , 3 ) ;
rdrive = GetJoystickAnalog( 1 , 2 ) ;
SetMotor ( 2 , -ldrive ) ;
SetMotor ( 3 , rdrive ) ;
JoystickDigitalToMotor ( 1 , 5 , 2 , 127 , 1 , -127 , 1 ) ;
JoystickDigitalToMotor ( 1 , 5 , 2 , -127 , 1 , 127 , 10 ) ;
JoystickDigitalToMotor ( 1 , 7 , 2 , 127 , 1 , -127 , 4 ) ;
JoystickDigitalToMotor ( 1 , 7 , 4 , 127 , 3 , -127 , 7 ) ;
JoystickDigitalToMotor ( 1 , 6 , 2 , 127 , 1 , -127 , 6 ) ;
if ( GetJoystickDigital(1,8,2)==1 )
{
sethigh=1; setmid=0; setlow=0; armaligned=0; wristaligned=0;
}
if ( GetJoystickDigital(1,8,3)==1 )
{
sethigh=0; setmid=1; setlow=0; armaligned=0; wristaligned=0;
}
if ( GetJoystickDigital(1,8,1)==1 )
{
sethigh=0; setmid=0; setlow=1; armaligned=0; wristaligned=0;
}
if ( sethigh==1 )
{
SetMotor ( 2 , 127 ) ;
arm = GetAnalogInput ( 4 ) ;
wrist = GetAnalogInput ( 8 ) ;
if ( arm<298 )
{
SetMotor ( 1 , -127 ) ; //we have two motors driving the arm
SetMotor ( 10 , 127 ) ;
}
else if ( arm>305 )
{
SetMotor ( 1 , 127 ) ;
SetMotor ( 10 , -127 ) ;
}
else
{
SetMotor ( 1 , 0 ) ;
SetMotor ( 10 , 0 ) ;
armaligned=1;
}
if ( wrist<1015 ) //this code has not yet been written due to me wanting
//to test the arm out first to make sure I was on the right track…
{
}
else if ( wrist>1025 )
{
}
else
{
SetMotor ( 6 , 0 ) ;
wristaligned=1;
}
if ( armaligned==1 ) //if the arm is properly aligned, turn sethigh becomes 0
{
if ( wristaligned==1 )
{
sethigh=0;
}
}
}
}
}

a little further information as to the variables. Arm/wrist are the current values of the potentiometers of the two of them. sethigh/setmid/setlow are variables to store if the driver has pressed that button, effectively standing for preSET height HIGH goal.

Any ideas as to why on earth this thing would stutter/move so slowly? Is the cortex getting bogged down with code/requests to the potentiometers? I wouldn’t think this little code would do anything to it.

Well, I figured out how to fix the problem. The program was requesting both the status of the controller and the sethigh variable every tick which would at times send conflicting responses. The result of this is that every tick, the capability of driving would be halted then enabled. This is what caused the stuttering. By streamlining the code and adding more if statements, I was able to remedy it.

Ok, I was going to say it looked like you were using SetMotor and JoystickToMotor on the same motor and they were fighting each other.