|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Turn 90 Degrees
Hey guys, recently my team (237) gave me the Robovation kit. I'm still looking around the source code, but i'm starting to understand it. Right now I'm trying to make a function that'll make it turn 90 degrees. I have a good idea on how to do it via the programming aspect, but im mind blocked on the math part.
Heres a pic I drew in paint. ![]() Whats the formula to figure out how many times the wheel needs to turn to go 90 degrees? I'm sure I can just go manually turn it and figure it out, but the formula would be better when I need to have it turn other angles. I probably didn't make much sense... it's a saturday.Last edited by Mike : 04-12-2004 at 20:03. |
|
#2
|
|||
|
|||
|
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! */
}
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. Last edited by colt527 : 04-12-2004 at 14:11. |
|
#3
|
|||||
|
|||||
|
Re: Turn 90 Degrees
Quote:
|
|
#4
|
||||
|
||||
|
Re: Turn 90 Degrees
The way that is more accurate than dead reckoning but not as complex as a gyroscope is an encoder. You can use either an optical sensor, like the Banner sensor in the KOP, or a potentiometer that has no stop (multi-turn, you call that?). Either one of these will count the revolutions of the wheel, which makes it easier to measure how far it has gone. To implement the optical sensor, you'd have to paint white dots on the wheels so the sensor can have something to count. You wouldn't have to do that, and you'd have less error with a pot, but it's a little trickier to figure out how to mount a pot on the EDU bot. There are numerous coding examples on these forums that will explain how you can program this.
|
|
#5
|
|||||
|
|||||
|
Re: Turn 90 Degrees
...Shouldn't this be under Programming?
|
|
#6
|
|||||
|
|||||
|
Re: Turn 90 Degrees
Quote:
EDIT: Mods feel free to move it if I was wrong |
|
#7
|
|||
|
|||
|
Re: Turn 90 Degrees
|
|
#8
|
||||
|
||||
|
Re: Turn 90 Degrees
Thanks, Tom. I knew there was a thread around here somewhere.
![]() |
|
#9
|
|||||
|
|||||
|
Re: Turn 90 Degrees
Quote:
Somehow measure the amount of time it takes for the wheel to spin one revolution at speed x. Set it to run at speed x for the needed amount of length/time. EDIT: thats not exactly what im going to do, I can't explain it... but it'll work Last edited by Mike : 04-12-2004 at 16:18. |
|
#10
|
||||
|
||||
|
Re: Turn 90 Degrees
Quote:
Code:
#define COUNT 20 //determine this number experimentally
void turn90(void)
{
int i=0;
int last=0;
while(i<COUNT)
{
pwm01=255;
pwm02=0;
if(rc_ana_in01<last)
i++;
last=rc_ana_in01;
}
pwm01=127;
pwm02=127;
}
Last edited by jgannon : 04-12-2004 at 22:01. |
|
#11
|
|||||
|
|||||
|
Re: Turn 90 Degrees
Quote:
You keep on mentioning "the pot"... whats that? A member on my team said that doing it this way wouldn't be reliable, because as the battery dies it won't be able to spin the wheel as fast as it did before. Will this fix that? I'd rather ask questions then just copy/paste... =/ |
|
#12
|
||||
|
||||
|
Re: Turn 90 Degrees
Quote:
Quote:
Quote:
|
|
#13
|
|||||
|
|||||
|
Re: Turn 90 Degrees
Quote:
![]() |
|
#14
|
|||
|
|||
|
Re: Turn 90 Degrees
A potentiometer.. or "pot" for short is a electrical component that increases or decreases resistance to flow based on the position of a lead which is attached to a cylinder. A common use for these are volume controls or light dimmer switches.
We can use these on our robots by utilizing the analog input pins. These pins are able to read an analog value, which will give you the amount of voltage flowing into them, rather than just a 1 or 0 from a digital input. As the resistance increases in the pot, the analog value on the RC goes down because more voltage is being dropped in the pot. So, using that value we can figure out how far something is rotated. The difference between a multi turn pot and an encoder is that one is analog and one is digital. A multi turn pot works on the same basis as a regular pot, but it is able to revolve many times. An encoder is basically a switch that gets turned on a set number of times in a full rotation. |
|
#15
|
||||
|
||||
|
Re: Turn 90 Degrees
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Six Degrees of John V-Neun | Amanda Morrison | Chit-Chat | 47 | 24-07-2007 18:11 |
| G4 wont turn on! | MattK | General Forum | 14 | 26-08-2003 09:44 |
| College Advisor turn outs | Guyute | General Forum | 4 | 20-06-2003 13:35 |
| Yaw Rate Sensor to 90 degrees? | Bruce C. | Programming | 4 | 11-02-2003 00:36 |
| PWM | Antonio | Technical Discussion | 21 | 06-01-2003 14:44 |