Go to Post Dean may have asked that every high school in America be involved with FIRST, but he never said [teams] all had to have separate high schools. - Amanda Morrison [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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.
  #2   Spotlight this post!  
Unread 21-03-2005, 07:54
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: UI Buttons

Your code looks fine to me. (but if I'm wrong... talk to my lawyer. )

I'm always confused about this, but I think that the buttons on the OI are reversed. (1/high for released, 0/low for pressed)

But... my whole post could be wrong.
__________________

  #3   Spotlight this post!  
Unread 21-03-2005, 12:30
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: UI Buttons

Quote:
Originally Posted by Ryan M.
Your code looks fine to me. (but if I'm wrong... talk to my lawyer. )

I'm always confused about this, but I think that the buttons on the OI are reversed. (1/high for released, 0/low for pressed)

But... my whole post could be wrong.
I know that the states for a limit switch are reverse that for the OI buttons... but i'm not sure which one is what.
__________________
http://www.mikesorrenti.com/
  #4   Spotlight this post!  
Unread 21-03-2005, 12:36
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,833
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: UI Buttons

Quote:
Originally Posted by MikeWasHere05
I know that the states for a limit switch are reverse that for the OI buttons... but i'm not sure which one is what.
From the OI a button will be 0 if unpushed, 1 if pushed.
The RC is reversed and will be 1 if unpushed, 0 if pushed. (because of the pull-up)
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #5   Spotlight this post!  
Unread 21-03-2005, 12:58
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: UI Buttons

Quote:
Originally Posted by Mark McLeod
From the OI a button will be 0 if unpushed, 1 if pushed.
The RC is reversed and will be 1 if unpushed, 0 if pushed. (because of the pull-up)

...yep! and to muddy the waters a bit:
Limit switches can usually be wired "normally open" or " normally closed". If you don't like the fact that the RC is "1 if unpushed and 0 if pushed", wire the limit switch "normally closed" and it will behave as the OI


...and a few random musings:
for your desiredposition == 2,
I'd suggest giving yourselves some "room to maneuver" when it comes to setting the motors to neutral. Hitting and holding exactly 1280, may result in a lot of racheting. You may want to make that a band...say > 1278 and < 1282 or something like that


Whenever you are in the home position, re-zero your encoder counter. There is always the chance of being off a few counts as the arm moves up and down and error can build up over a lot of use.

...just my 2cents
Eric
__________________

Don't PANIC!
S. P. A. M.
Closed Thread


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 20:49.

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