Thread: Turn 90 Degrees
View Single Post
  #2   Spotlight this post!  
Unread 04-12-2004, 13:47
colt527 colt527 is offline
Registered User
AKA: Ken Colton
FRC #0527
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Long Island
Posts: 123
colt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to behold
Send a message via AIM to colt527
Re: Turn 90 Degrees

Well, it's not that simple. In the code there is no direct way to make the robot turn 90 degrees. You control the motors through the PWM variables. And in that you do not control how many times they turn directly. You control the amount of power that is sent to the individual motor. For example, if pwm01 and pwm02 control the left and right side of you mini-bot:

pwm01 = 0;
pwm02 = 255;

Your robot would go spining to the left, it would not stop until you set pwm01 and pwm02 back to 127. The easiest, but least accurate method of doing what you are talking about would be "dead reconing" in which you just set pwm01 = 0 and pwm02 = 255 for a certain amount of time, which you can control by using a simple incrementing variable.

Here is some source to help you out. I'm just typing it in here, so I don't know if I made a stupid syntax error, but the general logic should all be there.

Code:
long int timer = 0; //Declare this globally at the top of the file. Right under the includes.

... //Code left out for posting purposes. 

//Here is you main function you will be editing in. 
//This function gets called every 17ms, so you can make a simple timer based off that

void Process_Data_From_Master_uP(void)
{
  Getdata(&rxdata);   /* Get fresh data from the master microprocessor. */

  Default_Routine();  /* Optional.  See below. */

  /* Add your own code here. */

//Start 90 degree turn code
//All this is doing is saying send 12 volts to the motor hooked up to pwm07 and send -12 volts to the motor hooked up to pwm08 for 1 second. After 1 second is done make both motors neutral. 1 second = about 59 loops though the code since it updates every 17ms. If you use a stop watch to grab the amount of time it takes to turn 90 degrees you can use the following equation to figure out what to put in. 
//Number got on stop watch * 1000/17. Then just throw that in place of 59.

if(timer > 0 && timer < 59)
{
 pwm07 = 255;
 pwm08 = 0;
}
else
{
 pwm07 = 127;
 pwm08 = 127;
}

timer++;//Increment the timer variable by 1, this says 17ms has passed.

  printf("PWM OUT 7 = %d, PWM OUT 8 = %d\n",(int)pwm07,(int)pwm08);  /* printf EXAMPLE */

  Putdata(&txdata);             /* DO NOT CHANGE! */
}
I hope I helped, if its still confusing IM me at coltfive2seven on AIM

The next ways which are more advanced but still not 100% accurate would be to use a gyroscope, which sences angular rate. So if the robot is turning to the right then it would sence it. You could use that in combination with some guese and check to get a reasonable accurate 90 degree turn.
__________________
Mentor, Team 527 -- Plainedge Red Dragons
FIRST Volunteer
SUNY Stony Brook Computer Science 2010
kcolton@gmail.com

Last edited by colt527 : 04-12-2004 at 14:11.
Reply With Quote