Thread: UI Buttons
View Single Post
  #1   Spotlight this post!  
Unread 21-03-2005, 07:20
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
UI Buttons

Hi,
We have buttons we want to use to automatically bring our arm to three different positions, using a limit switch (to bring the arm to position zero) and an encoder to accurately "guess" the middle and drop positions. Here is the code we will be using with three buttons on the ui. We are having trouble getting these buttons to work. they seem to turn to 1 instead of 0 when some of them are pressed, because we tested a joystick in the same port, and that is the behavior the exhibited. here is the code we are using, please let me know of possible problems. thanks!!!

Code:
static unsigned int desired_position = 1;		
static unsigned int current_position = 1;	//always must start out at -10 

degrees
unsigned int speed_fwd = 64;
unsigned int speed_rev = 190; 
static int go_home = 0;				//intialize the arm position to 

zero position
if (go_home == 0)
{
	pwm01 = speed_rev;
	if (rc_dig_in06 == 0)                 //is arm all the way back? (limit switch)
	{
		go_home = 1;
		pwm01 = 127;
	}
}
		


/* the arm will have 3 positions.
1: home position (-10 degrees)
2: load position (strait up or 0 degrees)
3: forward position (18 degrees)*/

if (p4_sw_trig == 1)
{
	desired_position = 1;
}
if (p4_sw_top == 1)
{
	desired_position = 2;
}
if (p4_sw_aux1 == 1)
{
	desired_position = 3;
}


if (desired_position == 1)			//check states of encoder, and act 

accordingly
{
	if (desired_position == current_position)
	{
		pwm01 = 127;
	}
	else
	{
		if (Get_Left_Encoder_Count() > 0)
		{
			pwm01 = speed_rev;
		}
		else
		{
			pwm01 = 127;
			desired_position = 1;
			current_position = 1;
			Set_Left_Encoder_Count(0);
		}
	}
}
if (desired_position == 2)
{
	if (desired_position == current_position)
	{
		pwm01 = 127;
	}
	else
	{
		if (Get_Left_Encoder_Count() < 1280)
		{
			pwm01 = speed_fwd;
		}
		else if (Get_Left_Encoder_Count() > 1280)
		{
			pwm01 = speed_rev;
		}
		else
		{
			pwm01 = 127;
			desired_position = 2;
			current_position = 2;
			Set_Left_Encoder_Count(1280);
		}
	}
}
if (desired_position == 3)			
{
	if (desired_position == current_position)
	{
		pwm01 = 127;
	}
	else
	{
		if (Get_Left_Encoder_Count() < 2304)
		{
			pwm01 = speed_fwd;
		}
		else
		{
			pwm01 = 127;
			desired_position = 3;
			current_position = 3;
			Set_Left_Encoder_Count(2304);
		}
	}
}
(some of the code lines are wrapped to the next line)
thanks in advance.

Last edited by stephenthe1 : 21-03-2005 at 07:22.