I've been modifying the default code to try to get a basic "joystick sensitivity reducer" working. I'm not planning on using this in our final robot as it significantly reduces the amount of power we can use. What it's supposed to do is subtract 127 from the joystick value and divide the result by two. Here's the code:
Code:
/* Variable declarations (at top of program) below */
unsigned char joystick_input = 127;
char joystick_input_2 = 0;
char drive_output = 0;
unsigned char drive_output_2 = 127;
/*******************************************************************************
* FUNCTION NAME: Slow_Drive
* PURPOSE: "Halves" the input from the controllers.
* CALLED FROM: Default_Routine
* ARGUMENTS: unsigned char joystick_input - input joystick value
* RETURNS: unsigned char drive_output_2
*******************************************************************************/
unsigned char Slow_Drive(unsigned char joystick_input)
{
joystick_input_2 = joystick_input - 127;
drive_output = joystick_input_2 / 2;
drive_output_2 = drive_output + 127;
return drive_output_2;
}
void Default_Routine(void)
{
pwm01 = Slow_Drive(p1_y);
printf("Slow_Drive for pwm01 = %d",joystick_input); /* printfs are for debugging purposes */
pwm02 = Slow_Drive(p2_y);
printf("Slow_Drive for pwm02 = %d",joystick_input);
/* pwm01 and pwm02 below removed, rest of code left intact */
}
Whenever I put the code on the robot I get a "code violation" (flashing red program LED) or the robot controller will go back into program mode. Right now I'm thinking the problem might be with variable types, but where? Or does anyone see any particular problems? I know I may not have commented enough so feel free to ask any questions. Any advice appreciated - thanks!