View Single Post
  #5   Spotlight this post!  
Unread 07-08-2006, 18:44
CircularLogic CircularLogic is offline
Registered User
FRC #1546 (Chaos Inc)
Team Role: Leadership
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baldwin
Posts: 38
CircularLogic will become famous soon enoughCircularLogic will become famous soon enough
Re: Vex Encoder Code

Both, rtick and ltick (for the StartLeftEncoder function) are unsigned ints.

If I use GetRightTick() (which returns rtick), the function works fine. However, if I use GetLeftTick(), I get the odd pulsing again. I cant see any differences in my code between the two functions besides the names and the variable returned.


Code:
void StartRightEncoder(void)
{
	state = rc_dig_in05;
	if(oldstate != state)
	{
		rtick ++;
	}
	oldstate = state;
}

unsigned int GetRightTick(void)
{
	return rtick;
}

void ClearRightTick(void)
{
	rtick = 0;
}

void ClearLeftTick(void)
{
	ltick = 0;
}

unsigned int GetLeftTick(void)
{
	return ltick;
}

void StartLeftEncoder(void)
{
    	

    state1 = rc_dig_in06;
	if(oldstate1 != state)
	{
		ltick++;
	}
	oldstate1 = state1;
}



void Process_Data_From_Local_IO(void)
{
  StartRightEncoder();
  StartLeftEncoder();

	/* Add code here that you want to be executed every program loop. */

}



Those are all my functions and are all placed in User_Routines_Fast


Code:
if(GetRightTick() <= 300)
{
	

	pwm04 = 255;
	pwm03 = 0;

}
And that is the code that uses those functions in User_Routines. If I use the code posted directly above, it works fine (and by that i mean the wheel spins and stops at logical points). But if I change the If statement to ahve GetLeftTick <= 300, the motors pulse again. I had that problem with GetRightTick(), but that problem was resolved for some reason unknown to me.




And then when I use GetRightTick(), if i want my wheel to spin twice (which should be 180 ticks), I have to set the tick number to 308 to get close to two spins.


Its times like these that I wish someone had a vex encoder function posted on the internet.
__________________
Team 1546 Chaos Incorporated
2005- SBPLI Rookie All Stars
2006- SBPLI Sportsmanship award.

Gotta hand it to the straight line autonomous mode, the most effective defense out there.

Proud beyond belief of the accomplishments of the second year, 20th ranked, 6 wins and 6 losses Chaos Incorporated.
Reply With Quote