View Single Post
  #7   Spotlight this post!  
Unread 04-02-2008, 16:20
popnbrown's Avatar
popnbrown popnbrown is offline
FIRST 5125 HOTH Lead Mentor
AKA: Sravan S
FRC #5125 (Hawks on the Horizon)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2007
Location: Illinois
Posts: 367
popnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond reputepopnbrown has a reputation beyond repute
Re: Programming the Infrared board

I understand your program Brad, however our IR Board sends a value of 0 to digital inputs 1, 2, 4 and a 1 to digital input 3. When the button for the corresponding inputs are pressed the values stay and do not change.

Instead of using the rc_dig_in variables that Kevin Watson uses. I use the WPILib function GetDigitalInput().
Code:
	
if(GetDigitalInput(IR_IN1))
	printf("IR #1\n");
else if(GetDigitalInput(IR_IN2))
	printf("IR #2\n");
else if(GetDigitalInput(IR_IN3))
	printf("IR #3\n");
else if(GetDigitalInput(IR_IN4))
	printf("IR #4\n");
I also understand that for the DigitalInputs to work I have to set whether they are used as inputs are outputs correct? so therefore I use SetDirection() for the used Digital Ports.
Code:
SetDirection(IR_IN1, INPUT);
SetDirection(IR_IN2, INPUT);
SetDirection(IR_IN3, INPUT);
SetDirection(IR_IN4, INPUT);
The port parameters all refer to macros, defined like:
Code:
#define IR_IN1 2
#define IR_IN2 3
#define IR_IN3 4
#define IR_IN4 5
One last thing, in CheckIR()
Code:
void CheckIR(void)
{
	unsigned char current = 0;
	unsigned char changed;
	if (rc_dig_in05) current |= 1;
	if (rc_dig_in06) current |= 2;
	if (rc_dig_in07) current |= 4;
	if (rc_dig_in08) current |= 8;
	
	changed = previous ^ current;
	irCommands |= (~previous) & current;
}
after each if statement could you not just do whatever each button does right after the statement, instead of using three different variables. For example,
Code:
void CheckIR(void)
{
	unsigned char current = 0;
	unsigned char changed;
	if (rc_dig_in05) Autonomous1(); //Autonomous1() is a function that does what command one is intended to be used for
	if (rc_dig_in06) current |= 2;
	if (rc_dig_in07) current |= 4;
	if (rc_dig_in08) current |= 8;
	
	changed = previous ^ current;
	irCommands |= (~previous) & current;
}
Thanks for your help ahead of time,
Sravan
Reply With Quote