View Single Post
  #1   Spotlight this post!  
Unread 25-02-2007, 20:00
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
Trouble with Autonomous

Well the title of the thread actually isnt exactly my problem. Autonomous works however one of my functions doesn't work. We are trying to get our robot to rotate (a 0 degree turn). I'm using WPILib so we have to write totally new code.

Well anways here is the function Rotate():
Code:
 
void Rotate(char direction, int degrees, char speed)
{
	int time = (1000 * (degrees/ 300));
	char RightMotor = NEUTRAL + (speed * direction * (SPEED_TO_PWM));
	char LeftMotor = NEUTRAL + (speed * direction * (SPEED_TO_PWM));
        //the SPEED_TO_PWM = 127/10 which converts the speed to PWM value

	printf("Rotate()\r");

	SetPWM(LEFT_WHEEL, LeftMotor);
	SetPWM(LEFT_FRONT_WHEEL, LeftMotor);
	SetPWM(RIGHT_WHEEL, RightMotor);
	SetPWM(RIGHT_FRONT_WHEEL, RightMotor);
	
	printf("time: %d\r", time);
	
	Wait(time);
	
	SetPWM(LEFT_WHEEL, NEUTRAL);
	SetPWM(LEFT_FRONT_WHEEL, NEUTRAL);
	SetPWM(RIGHT_WHEEL, NEUTRAL);
	SetPWM(RIGHT_FRONT_WHEEL, NEUTRAL);
       //NEUTRAL = 127

}
now the main problem is the time. When I pass for example:
Code:
Rotate(-1, 30, 10)
the time displays as 0. I find it really odd. However I ran time as a constant:
Code:
time = 300;
and the function worked perfectly. So the real problem here is one of the variables involved in the time equation and I dont know which one or what is wrong.

Any help would be appreciated