Go to Post Our team is using a video camera with frame-by-frame analysis to figure out all the characteristics of the foam ball. If the Boeing engineer says it's possible, I'm going to believe him. - sciencenerd [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 02-21-2006, 12:41 AM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Relay Programming Questions...

We need one button to change multiple relays several times, what would be a good way to go about doing this? Does anybody have any code that will do this?
  #2   Spotlight this post!  
Unread 02-21-2006, 01:13 AM
MichaelGoldfarb MichaelGoldfarb is offline
Registered User
AKA: Goldfarb
FRC #0312 (Heatwave)
Team Role: Programmer
 
Join Date: Aug 2004
Rookie Year: 2003
Location: St. Pete, FL
Posts: 11
MichaelGoldfarb is an unknown quantity at this point
Send a message via AIM to MichaelGoldfarb Send a message via MSN to MichaelGoldfarb
Re: Relay Programming Questions...

The best way to do this is with a simple state machine. You can do this by using one variable to act as a counter, and then incrementing that counter every program loop. With just simple if/else statements you can change the sate of several outputs and then reset your counter and await activation again.

If you are still stuck I'll post an example for you.
__________________
I'm crazy!
  #3   Spotlight this post!  
Unread 02-21-2006, 01:46 AM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Re: Relay Programming Questions...

I figured that out...I actually got it to work, but it works once and then not again. I made sure it was resetting the counters.

This is the code i wrote...
This is in the Default_Routine:

if(p1_sw_trig)
{
counter1++;
if(counter1 == 14)
{
shoot_level = 1;
counter1 = 0;
}
}
else if(!p1_sw_trig)
{
counter1 = 0;
}

if(shoot_level > 0)
{
shoot_level_runner();
shoot_level++;
printf("%d\n", shoot_level);

}
if(shoot_level == 61)
{
shoot_level = 0;
counter1 = 0;
}

This is the funtion it calls:

void shoot_level_runner(void)
{
if(shoot_level == 1)
{
relay4_rev = 1; // top ram out
}
if(shoot_level == 20)
{
relay3_fwd = 1; // bottom ram out
}
if(shoot_level == 40)
{
relay3_rev = 1; // bottom ram in
}
if(shoot_level == 60)
{
relay4_fwd = 1; // top ram in
}
}

Why does it only work once???
  #4   Spotlight this post!  
Unread 02-21-2006, 02:38 AM
MichaelGoldfarb MichaelGoldfarb is offline
Registered User
AKA: Goldfarb
FRC #0312 (Heatwave)
Team Role: Programmer
 
Join Date: Aug 2004
Rookie Year: 2003
Location: St. Pete, FL
Posts: 11
MichaelGoldfarb is an unknown quantity at this point
Send a message via AIM to MichaelGoldfarb Send a message via MSN to MichaelGoldfarb
Re: Relay Programming Questions...

From what I see you need to reset the state of the relays. Once they receive a value they will stay that way until that output is modified.
__________________
I'm crazy!
  #5   Spotlight this post!  
Unread 02-21-2006, 03:52 AM
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Relay Programming Questions...

You have no logic to turn the relays off. You have to do a relay4_fwd = 0 when you set the reverse on, and so on.
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
  #6   Spotlight this post!  
Unread 02-21-2006, 08:33 AM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Re: Relay Programming Questions...

Could somebody help me code that? I don't understand. What do I need to change?
  #7   Spotlight this post!  
Unread 02-21-2006, 09:38 AM
bush's Avatar
bush bush is offline
Registered User
AKA: Aaron
FRC #0710 (Pine Crest School)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Fort Lauderdale, Florida
Posts: 42
bush has a spectacular aura aboutbush has a spectacular aura about
Send a message via AIM to bush
Re: Relay Programming Questions...

I briefly read over your code, and I'm not exactly sure what you're trying to do. Explain what you want in words, and I'll try to help you out with your code.
  #8   Spotlight this post!  
Unread 02-21-2006, 09:47 AM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Re: Relay Programming Questions...

Basically we are controlling our feeding mechanism to our flywheels. We have 2 rams, an upper and a lower. By defualt, the lower ram is extended holding up a stack of balls. When we press the joystick trigger, we want to fire the top ram which will then hold up the stack of balls. Then retract the lower ram which will drop only one ball into the flywheels. Then extend the the lower ram again and then retract the top ram, so as the stack drops and we can repeat. Does that explain it?
  #9   Spotlight this post!  
Unread 02-21-2006, 11:22 AM
Matt Krass's Avatar
Matt Krass Matt Krass is offline
"Old" and Cranky. Get off my lawn!
AKA: Dark Ages
FRC #0263 (Sachem Aftershock)
Team Role: Mentor
 
Join Date: Oct 2002
Rookie Year: 2002
Location: Long Island, NY
Posts: 1,187
Matt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond repute
Send a message via AIM to Matt Krass
Re: Relay Programming Questions...

Shameless plug:
http://www.chiefdelphi.com/forums/sh...507#post455507

Those might make it easier to set up your relays, less confusing logic to deal with. It's a series of macros to set relays FWD, REV, and OFF, one-liners, saves some headaches.

Good luck!
__________________
Matt Krass
If I suggest something to try and fix a problem, and you don't understand what I mean, please PM me!

I'm a FIRST relic of sorts, I remember when we used PBASIC and we got CH Flightsticks in the KoP. In my day we didn't have motorized carts, we pushed our robots uphill, both ways! (Houston 2003!)
  #10   Spotlight this post!  
Unread 02-21-2006, 11:35 AM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Re: Relay Programming Questions...

Telling it what to do isn't the problem. It works fine except it only does it once, then it won't do it again. Also, when I do an if statement, like this:
if(counter3 == 1)
{
relay3_fwd = !relay3_fwd;
}
It always executes this statement, whether or not counter3 = 1. Even with a printf I found that counter3 was equal to 0 and it still executed this statement.
  #11   Spotlight this post!  
Unread 02-21-2006, 12:44 PM
bush's Avatar
bush bush is offline
Registered User
AKA: Aaron
FRC #0710 (Pine Crest School)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Fort Lauderdale, Florida
Posts: 42
bush has a spectacular aura aboutbush has a spectacular aura about
Send a message via AIM to bush
Re: Relay Programming Questions...

Try this...

Declare/initialize these variables at the top of Default_Routine

Code:
static unsigned char shooting = 0;
static unsigned char counter1 = 0;
And add the following anywhere in the body of Default_Routine

Code:
if (p1_sw_trig) shooting = 1;
if (shooting)
{
	switch (counter1)
	{
		case 0: //TOP RAM OUT
			relay4_fwd = 0;
			relay4_rev = 1;
			break;
		case 20: //BOTTOM RAM IN
			relay3_fwd = 1;
			relay3_rev = 0;
			break;
		case 40: //BOTTOM RAM OUT
			relay3_fwd = 0;
			relay3_rev = 1;
			break;
		case 60: //TOP RAM IN
			relay4_fwd = 1;
			relay4_rev = 0;
			shooting = 0;
			counter1 = 0;
			break;
		default:
			counter1++;
	}
}

Last edited by bush : 02-21-2006 at 12:47 PM.
  #12   Spotlight this post!  
Unread 02-21-2006, 01:04 PM
comwiz7's Avatar
comwiz7 comwiz7 is offline
Registered User
AKA: Joey
FRC #1323 (Madtown Robotics 1323)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Madera
Posts: 66
comwiz7 will become famous soon enoughcomwiz7 will become famous soon enough
Send a message via MSN to comwiz7
Re: Relay Programming Questions...

I have already tried the exact same thing you are doing with this and surprisingly, it didn't work. But with lots of trys we finally found something that did:
if(!p4_sw_trig){
if(counter1 > 9 & counter1 < 61)
{
counter1++;
}
else if(counter1 < 10 || counter1 > 60)
{
counter1 = 0;
}
} else if(p4_sw_trig){
if(counter1 < 1000)
counter1++;
}
if(counter1 == 10)
{
relay4_fwd = !relay4_fwd;
}
if(counter1 == 30)
{
relay3_fwd = !relay3_fwd;
}
if(counter1 == 50)
{
relay3_fwd = !relay3_fwd;
}
if(counter1 == 60)
{
relay4_fwd = !relay4_fwd;
}

I don't know why this worked and that didn't but it works and I'm happy. Thanks, everybody, for helping out.
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
A few simple programming questions; Oumonkey Programming 18 02-17-2006 02:24 PM
#1 The Journey of a FIRST Graduate: Questions Ken Leung General Forum 12 07-27-2005 06:24 PM
Problems and questions about programming hedgehogger Programming 4 01-15-2005 06:18 PM
Default mapping relay questions Jared Stofflett Programming 1 02-25-2004 07:06 PM
A few questions on programming the Control System Avarik Control System 21 02-08-2004 11:42 AM


All times are GMT -5. The time now is 10:12 AM.

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