Go to Post With a little time and practice, I think that most people would find that there is no magic involved in programming. - Dave Scheck [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 17-02-2008, 15:56
SidneySalvo SidneySalvo is offline
Registered User
FRC #1691
 
Join Date: Jan 2008
Location: Sidney
Posts: 22
SidneySalvo is an unknown quantity at this point
IR board code

I'm am the programmer for team 1691 and I'm am currently working on programming the ir board. I think that the sort of thing that i want to do is have one button coorespond with just going around the track, one for knocking the trackball off of the left spot, one for knocking it off of the middle, and the last for knocking it off of the right spot. i was wondering if any one out that has done something along these lines could send me a sample of their program?
as you know the ship date is on tuesday, so the sooner you can respond the better off i will be.

Thank you for any help you can bring to the table.
__________________
The Universe is filled with magical things, patiently waiting for our wits to grow sharper.
  #2   Spotlight this post!  
Unread 17-02-2008, 16:06
seanl's Avatar
seanl seanl is offline
"The Everything person"
FRC #0867 (Absolute Value)
Team Role: Leadership
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Arcadia, CA
Posts: 267
seanl will become famous soon enoughseanl will become famous soon enough
Re: IR board code

just do
if((pick the digital io you want)==1)
{
// add code here
}
__________________
, Sean

TEAM 867
-electrical
-pneumatics
-programming



2008 Autodesk Visualization Grand Prize Winner
  #3   Spotlight this post!  
Unread 17-02-2008, 17:39
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: IR board code

Actually, that will always run as the IR returns 1 unless the signal matches. You will need to have an equivalency check with 0, and probably code to avoid running without the IR connected. I'll post an example once I get back to my code...

As for the actual autonomous mode... Are you basically looking for a complete code to base yours off or something specific you need an example of? If you're looking for something in general, I can post an example of our team's state machine stuff... Once again when I get the laptop back.
  #4   Spotlight this post!  
Unread 17-02-2008, 18:03
SidneySalvo SidneySalvo is offline
Registered User
FRC #1691
 
Join Date: Jan 2008
Location: Sidney
Posts: 22
SidneySalvo is an unknown quantity at this point
Re: IR board code

That is pretty much what i was thinking. we are short on time and we have one way or another fried our ir board, so we are making a code in hopes of getting it fixed with the help of other teams at our regional.
__________________
The Universe is filled with magical things, patiently waiting for our wits to grow sharper.
  #5   Spotlight this post!  
Unread 17-02-2008, 18:28
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: IR board code

If the IR board's gone, then that would significantly change the strategy... Maybe you'll be able to purchase another before the actual regional, so in case you get one working, this is what we used for the IR board:
Code:
// IR Inputs
#define IR_DIG_1 		rc_dig_in04
#define IR_DIG_2 		rc_dig_in05
#define IR_DIG_3 		rc_dig_in06
#define IR_DIG_4 		rc_dig_in07
#define IR_DISCONNECTED	(IR_DIG_1 && IR_DIG_2 && IR_DIG_3 && IR_DIG_4)
#define IR_1 		(IR_DIG_1 && !IR_DISCONNECTED)
#define IR_2 		(IR_DIG_2 && !IR_DISCONNECTED)
#define IR_3 		(IR_DIG_3 && !IR_DISCONNECTED)
#define IR_4 		(IR_DIG_4 && !IR_DISCONNECTED)
That way the you can use if (IR_1) or the like to use your routines. If you want each to run a seperate routine, you're better off setting a variable and then using a switch, something like this:
Code:
	static int routine = 0;
	if(IR_1){
		routine=1;
	}
	if(IR_2){
		routine=2;
	}
	if(IR_3){
		routine=3;
	}
	if(IR_4){
		routine=4;
	}
	
	switch (routine){
		case (1):
			routine_1();
			break;
		case (2):
			routine_2();
			break;
		case (3):
			routine_3();
			break;
		case (4):
			routine_4();
			break;
		default:
			routine_0();
			break;
	}
Even if you don't get your IR board functional, you can still try a state machine sort of thing. You can get fancy with this sort of thing as well. You'd start by breaking whatever you want to do into a typedef, which looks something like this:
Code:
typedef enum{
AUTO_DRIVE_1
AUTO_TURN
AUTO_DRIVE_2
AUTO_COMPLETE
} auto_state;
In case you're not familiar with enumeration, this will make AUTO_DRIVE_1 a macro of 0, AUTO_TURN a macro of 1, etc. That way you can reference a switch statement with it. This would be the bulk of your case state machine:
Code:
usigned char do_half_lap (void){
    static unsigned char current_state = 0; //This is the current progress
    switch (current_state){
        case (AUTO_DRIVE_1):
        current_state += drive_x_dist(100);
        break;
        case (AUTO_TURN):
        current_state += turn_90_degrees();
        break;
        case (AUTO_DRIVE_2):
        current_state += drive_x_dist(50);
        break;
        case (AUTO_COMPLETE):
        return 1;
        break;
     }
}
return 0;
All of the example functions would return an unsigned char, 1 or 0, based on completeness, like do_half_lap. This means the state is getting pushed up to the next level each time one of the steps is complete. Of course, this means you need to make the subfunctions. If you want, these can be state machines as well!

I'll leave the subfunction implementation code up to you; but it should be pretty easy. Let me know if any of this is too complicated. Keep in mind these are all samples and haven't been tested. I advise not copy/pasting anything and writing your own with this as a reference.

Last edited by psy_wombats : 17-02-2008 at 19:30.
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
Problems integrating CMUCAM code and IFI Default Code Windward Programming 2 06-02-2007 16:48
problems using gyro/adc code with camera default code tanstaafl Programming 7 22-01-2006 23:09
Lights in Joystick board or control board rcubes85 Control System 15 26-02-2005 23:40
Team THRUST - Kevin's Code and Camera Code Combine Chris_Elston Programming 3 31-01-2005 22:28
Perf Board = BS2-IC Carrier Board? indieFan Electrical 2 16-09-2004 08:28


All times are GMT -5. The time now is 01:50.

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