Motors control

Hi. I am trying to build a two wheels robot during the summer and I am looking for a way to have control over how many revolution does a motor rotates, such that I can have precise control over how far does my robot moves. For example, I want to be able to rotate my wheels for 20.4 revolutions, such that my robot will go 1.5 meters forward.

I understand that it can be done using stepper motors, as long as I keep the speed low enough such that there is no skipped step. This solution is simple, but a stepper motor is too slow and heavy for my application.

Another approach is to use a DC motors with feedback loop control. They are usually quite small, doesn't consume a lot of power, and offers fast rotational speed but I am unable to fully understand what components are needed nor how to control a servomotor using a microcontroller. Do I simply buy a small DC motor, an encoder and try to model the motor's transfer characteristics function and design my close loop control system, using my microcontroller's PWM as the input to the system? That sounds fun and all but I don't know if I can figure them out all by myself... Is there any tutorial I can follow as for how to do the modelling? Oh also, does it has anything to do with a "continuous servo"?

Thanks!

dominicfhk: Hi. I am trying to build a two wheels robot during the summer and I am looking for a way to have control over how many revolution does a motor rotates, such that I can have precise control over how far does my robot moves. For example, I want to be able to rotate my wheels for 20.4 revolutions, such that my robot will go 1.5 meters forward.

Fast answer: Use a wheel encoder. More in a bit...

dominicfhk: I understand that it can be done using stepper motors, as long as I keep the speed low enough such that there is no skipped step. This solution is simple, but a stepper motor is too slow and heavy for my application.

This is called "open-loop" control, and is only reliable in certain instances; provided your weight is low enough, you don't care about extreme accuracy, or a whole host of other reasons - it can work well. Even for a small robot (they do make fairly small servos - heck, just the other day, I saw one smaller than a person's thumbnail!).

dominicfhk: Another approach is to use a DC motors with feedback loop control. They are usually quite small, doesn't consume a lot of power, and offers fast rotational speed but I am unable to fully understand what components are needed nor how to control a servomotor using a microcontroller. Do I simply buy a small DC motor, an encoder and try to model the motor's transfer characteristics function and design my close loop control system, using my microcontroller's PWM as the input to the system? That sounds fun and all but I don't know if I can figure them out all by myself... Is there any tutorial I can follow as for how to do the modelling?

That's a lot of words - personally, I think you are over-thinking this problem. What it sounds like you are talking about there is "closed-loop speed control" via comparing the output of an encoder to the PWM being input. Yes - you could do this - but that's for speed control - not position control. That said - both are really similar...

dominicfhk: Oh also, does it has anything to do with a "continuous servo"?

Not much - a "continuous rotation" servo is simply an R/C servo which has been modified in such a way so that it's servo position control system has been neutered, so that when you feed in a certain position - it tries to reach that position by rotating the servo in the direction needed to get to that position, but because it's feedback system has been disabled (and internal stops removed), the motor continues to rotate in one direction - never reaching it's goal state. In effect, it becomes a somewhat easier-to-control DC gear motor.

Now - if your goal is to build your robot, and not focus on the hows and whys of DC motor control theory - then going the "continuous rotation servo" route might be your best bet. Servos are available in a lot of styles, and depending on how big you plan on making the robot, there is likely a servo that will work for you. Most standard size and smaller servos can be easily found in a modified "continuous rotation" variant; but the larger servos will have to be modified yourself. Also, if you go for a large robot (more than 1-2 kg in size), you will want servos that have ball-bearings (preferably dual bearings on the output shaft) and metal gears. Going the route of a servo-based robot will allow you to concentrate on getting a small robot working, rather than being focused on getting it's wheels turning.

However - if you want to DIY the whole lot of it - then what you need are wheel encoders - one for each wheel.

At it's most basic, you will want to measure how far a wheel turns. To do that, there are a variety of options. But for all options, they boil down to monitoring the rotation of a shaft by counting pulses, generally via an optical system.

The simplest way to do this is to mount on the wheel an encoder disk (printed from your computer, perhaps), and point a photo-transistor and IR LED combo (also known as a side-looking photo-detector pair) at the encoder and monitor it that way. Here is a site to use for the encoders - to show you what you need/want:

http://www.robotoid.com/printable-templates.html (toward the bottom)

This is just one instance - I'll provide some more links in a bit.

Anyhow - as your wheel turns, and the white/dark stripes pass by - they will impart a "pulsing" on the photo-transistor from the reflection of the IR LED - which you can monitor with your Arduino.

Another possibility - rather than using a reflection-based system - is to use a slotted system - put the detector pair on either side of a slotted disc of some sort (again - you could print out an encoder on plastic transparency, for instance) and monitor that (this is basically how old computer mice worked - if you wanted, you could get parts for such a system from an old PC mouse). You could also count pulses using one or more magnets passing by a reed-switch, or a hall-effect sensor.

Note that if you are using a gearbox on the motor (which you will likely be doing) - that the closer you put the encoder to the output of the motor, the greater the resolution you could potentially obtain - so if your motor needs to rotate 2000 times to make the wheel one revolution - you could monitor the motor shaft output and know that you need to count 2000 pulses for the wheel to have moved one rotation. That said, you would need to write your code properly to count that fast (hint - you would want to use interrupts). In fact, some gear-motors do have encoders already on the output shaft (just be prepared to pay a good amount for them - even surplus). I should also note that there is nothing stopping you from having encoders on both the motor shaft -and- the wheel; you could monitor slip/backlash of your robot drive system that way.

Also note that in the counting of pulses - if you measure the time between pulses, and compare that (in some manner) with your PWM signal - you also get your original speed servo system idea as well (this could also be expanded to a form of slip/traction control if you wanted).

So - you would have this system set up - then to monitor the wheel position - you would turn on your h-bridge (or whatever you are using to control the motor), then start counting the pulses from the encoder system. When your counter reaches the number of pulses for the amount of rotation you need, turn off the h-bridge. That's the basic algorithm (note - in real life this probably won't work perfectly - because motor rotors have mass and inertia - so you might need to create some system to speed up and slow down the motor as you start from and reach the ends of travel - it all depends on how much accuracy you require; for most hobby designs, it is overkill - but, if you want - look into PID control loops).

Finally - those links:

http://thedenneys.org/pub/robot/encoders/

http://code.google.com/p/wheel-encoder-generator/

http://www.societyofrobots.com/sensors_encoder.shtml

http://www.geology.smu.edu/~dpa-www/robo/Encoder/pitt_html/encoders.html

Those are for starters - you can find more via googling... Good luck! :D

Thank you very much for your response! I have been googling motor control for quite some time. Combined with you help, and I think I know how to keep track of position... Basically I amplify the IR pulse signal using an OpAmp to trigger an ISR to increment my wheel's counter by one, such that I can use the counter value inside my program to compute for the distance traveled... Okay so if I am to control and monitor two motors at once, I should have two encodes attached to each of the wheels for triggering two independent ISR functions to increment "L_wheel_counter" and "R_wheel_counter", am I right? What if the two interpret signals go to high at the same clock cycle? Does the Arduino has a built-in interrupt controller? Or am I better off using two Arduino to drive each motor?

Thanks!

The Arduino has two pins that can directly generate interrupts (look for “attachInterrupt()”), and
also has “pin change interrupts” which can be configured to detect changes on any pin or pins
you like.

For the sorts of signalling rates wheel encoders generate you won’t need more than one Arduino
to monitor them (the chances of two encoders changing on the same clock cycle are remote, and
interrupts get queued anyway so this is not an issue).

Consider using a Shmitt trigger (like a 7414) versus an op amp to clean up the pulses from the IR detector. Fewer parts and easier to implement.

Hi. I am trying to build a two wheels robot during the summer and I am looking for a way to have control over how many revolution does a motor rotates, such that I can have precise control over how far does my robot moves. For example, I want to be able to rotate my wheels for 20.4 revolutions, such that my robot will go 1.5 meters forward.

Bare in mind that any wheel slippage on the surface on which the bot rolls will impact the effectiveness of the wheel encoders for position determination.

interrupts get queued anyway so this is not an issue

Oh nice! So the Arduino does have an interrupt controller and even if two interrupt signals are triggered at the same clock cycle, the Arduino can still register both interrupts and jump into the two ISR functions one after another?

Bare in mind that any wheel slippage on the surface on which the bot rolls will impact the effectiveness of the wheel encoders for position determination.

I am not sure how do-able is it going to be but I have been thinking about using a compass or gyro to help checking the robot's heading and turning. However I also understand that gyro is a noisy and expensive device and compass is pretty unresponsive. Are there a better way to counter the effect of wheel slipping? Add two more wheels with only encoders on them and take the average maybe?

Thanks!

Hey people, this may interest you because you will can remote control the motor.

I saw this link yesterday http://www.vm-cinema.com/Pre-order/ because I was looking for innovative accessories to make my shot more easily. The product principle delighted me and made me want to know more about it. I’m in a hurry to be on Sunday, July the 14th to reach the Indiegogo page.