Electronics > Electronics
Beginner question: Speed control of robot wheels
abbyboy86:
--- Quote from: jwatte on February 14, 2013, 09:57:09 PM ---
--- Quote ---that degree was 4 years back and I dont think I remember much now![/quote[
I don't want to sound down on you or anything, but my experience is this: If you forget an education in 4 years, you will probably fail at robotics, and probably also fail at life!
The voltage regulator should only be between the input voltage, and the VCC of the microcontroller. Set it to output whatever the microcontroller wants for input (typically 5V or 3.3V, but the data sheet will tell you for sure) and add a bypass capacitor and perhaps two capacitors around the voltage regulator.
To regulate the speed of a motor, you use PWM output from the microcontroller. To go faster, make the PWM duty cycle longer. The H-bridge needs to be able to keep up with the frequency of the PWM. If the frequency is 200 Hz, almost anything except relays will keep up, but response will be somewhat slow, and it will be noisy. Modern MOSFET based H-bridges with fast-switching gate drives can keep up at 20 kHz and above, at which point the PWM will be inaudible.
The PWM functions of a microcontroller typically are tied to whatever timer peripherals they have. The details vary be family (ARM, AVR, PIC, MSP, etc) and are described in the data sheet of the microcontroller.
--- End quote ---
Thank you I will try these methods.. About the past 4 years, Ive been busy doing and learning lots of stuff man.. Its been great.. And I m coming back to tech stuff as well !
--- End quote ---
newInRobotics:
--- Quote from: jwatte on February 14, 2013, 09:57:09 PM ---I don't want to sound down on you or anything, but my experience is this: If you forget an education in 4 years, you will probably fail at robotics, and probably also fail at life!
--- End quote ---
That's a harsh thing to say as well as totally inappropriate in engineering forum (and probably any other type of communication in the matter of fact), as that particular comment did not add any value nor answered any of abbyboy86's questions, however, based on perception of Yours alone, it implied that abbyboy86 is/will be a failure in life.
To back up my rambling - I don't remember majority of things that I learnt in uni (graduated 2 years ago) simply because I don't use them every day and my memory is terrible (or worse than I would like it to be); every time I have to write Windows app, or some software for microcontroller, or design a circuit, or use/come up with some clever algorithm I cannot take a step without referring to manual/reference/guide of some sort. Au contraire to what You said - I, for one, am not a failure in life: I have good wife, home, car, well paid job (which has little to do with what I did in uni), can afford to visit another country at least twice a year and have spare time and budget to explore other things I enjoy. So, if Your definition of failure is a person who forgets things over time, then world is full of failures and You can consider Yourself an elephant :)
jwatte:
--- Quote ---Rea1,Rea2,Rea3,Rea4=0;
--- End quote ---
This code will read the values of Rea1, Rea2, and Rea3, and throw ignore those values, and will set the value of Rea4 to 0. That's probably not what you want.
--- Quote ---while(!0)
Rea1,Rea2=5;
Rea3,Rea4=0;
--- End quote ---
This code will read the value of Rea1 and ignore it, and set Rea2 to 5, forever. It will never reach the code that reads the value of Rea3 and ignores it, and sets Rea4 to 0.
--- Quote --- while (!0)
l_rev();
r_forw();
--- End quote ---
This code will call the function l_rev() forever, and will never get to the code that calls the function r_forw().
There are multiple similar problems in the code. I suggest starting smaller -- try just a single action, and make it actually run on the robot. Then add a single second action, and verify that it all works as expected. Slowly grow the set of features, verifying between each step. That is going to make debugging much easier.
I also highly recommend ALWAYS wrapping braces {} around all while() and if() statements, even when you only have one statement. The reason is that you will then never be confused when you try to add a second statement, and it doesn't work the way you want.
Also, in robotics, you pretty much never want to do something "forever" -- you always want some kind of time-out after which you stop, no matter what.
--- Quote ---Rea1,Rea2,Rea3,Rea4=0;
--- End quote ---
If I needed this kind of statement, I would write this as:
--- Code: ---Rea1=0, Rea2=0, Rea3=0, Rea4=0;
--- End code ---
However, I'd be much more likely to write it as:
--- Code: ---void setReas(int a, int b, int c, int d) {
Rea1 = a;
Rea2 = b;
Rea3 = c;
Rea4 = d;
}
...
setReas(0, 0, 0, 0);
--- End code ---
--- Quote --- while (!0)
l_rev();
r_forw();
--- End quote ---
I would write this as:
--- Code: ---#define TIMEOUT 1000
...
unsigned long now = millis();
while (millis() - now < TIMEOUT) {
l_rev();
r_forw();
}
--- End code ---
This assumes you have a function "millis()" which returns a clock of milliseconds of size unsigned long. If your libraries are different, you need to adjust appropriately.
abbyboy86:
<quote>
void setReas(int a, int b, int c, int d) {
Rea1 = a;
Rea2 = b;
Rea3 = c;
Rea4 = d;
}
...
setReas(0, 0, 0, 0);
</quote>
Thank you very much for this code and the other advice.. I will change my code now...
Navigation
[0] Message Index
[*] Previous page
Go to full version