Go to Post ...and that is exactly why Dave is the coolest nerd I know. - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming motors with joystick buttons TMHStitans Programming 5 21-03-2005 21:07
#433 Firebirds Buttons!!! looneylin Chit-Chat 17 19-03-2005 23:56
Using the extra buttons on the joystick. Code\\Pilot Programming 7 04-12-2004 19:30
[ECDU]: Buttons Corey Balint FIRST-related Organizations 0 05-10-2004 22:01
Where do the stop buttons go??? archiver 2001 0 24-06-2002 00:35


All times are GMT -5. The time now is 09:38.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi