Shop OBEX P1 Docs P2 Docs Learn Events
Is the DC motor not precise? — Parallax Forums

Is the DC motor not precise?

lardomlardom Posts: 1,659
edited 2011-01-12 16:43 in General Discussion
I'm learning to control a gearhead DC motor with a quadrature encoder. I'm also learning the L293. Unlike my experience with a stepper or a servo I'm finding it difficult to make it stop at the position I want it to. I haven't exhausted all my ideas on how to do it but I would like to know if I should expect a certain amount of slop in a gearhead DC motor? Is PID (which I haven't tried yet) a necessary part of controlling these motors? :nerd:

Comments

  • ercoerco Posts: 20,260
    edited 2011-01-10 09:57
    Don't give up. You can get VERY precise control. I build my own encoders (oops, tach sensors) and can stop on a dime. The encoder lets you know where you are, it's up to your code and controller to get the motor to stop properly. No one ever listens when I extol the virtues of dynamic braking, but that's one of the best features of DC motors.

    PID is nice, but not necessary.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2011-01-10 10:14
    You should be able to get very precise control with a geared DC motor and an encoder. Keep in mind that a servo is just a geared DC motor as well with an analog potentiometer for feedback instead of an optical encoder.

    Where are you placing your encoder and what kind of encoder are you using? Is it connected to the motor shaft or is is connected to the final output shaft? What is the resolution of the encoder? If possible I like to place the encoder on the motor shaft for the best control. There are lots of variables so if you can give us some more details we should be able to help.

    Robert
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-01-10 13:38
    ...If possible I like to place the encoder on the motor shaft for the best control. ...

    Robert,

    I'm curious: why does placing the encoder on the motor shaft (and not the output shaft) provide better control? I would think that, so long as some sort of software allowance is made for backlash, that you would want to know where the output shaft is located more than the motor shaft.

    lardom,

    As for slop in the gearhead: unless the gears have some sort of fancy anti-backlash system, you will probably always see some amount of slop. See, for example:
    http://en.wikipedia.org/wiki/Backlash_(engineering)
    Whether or not such mechanical backlash is a problem for you is, of course, dependent on your application. It should be something you can easily measure and allow for in your software. However, I'm just guessing your problem is probably a control issue, not so much a mechanical one.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-10 13:42
    Incremental encoders are almost always placed on the motor shafts of gearmotors, because you get more resolution that way (at the expense of requiring faster response in the encoder firmware). Backlash can easily be compensated for in software by adding the amount of the backlash to each stroke that entails a change of direction from the previous one.

    -Phil
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-01-10 13:52
    Incremental encoders are almost always placed on the motor shafts of gearmotors, because you get more resolution that way...

    Phil, I believe you, but I also wonder if gears are always mounted perfectly, and if they are always cut perfectly, plus if there's a lot of load, you might get torsional deformations, so do you always benefit from the greater resolution?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-10 14:18
    Part of the solution comes from spec'ing the right components, I suppose. For example, if you're getting enough torsional deformation to compromise performance, you probably need a more robust gearmotor. If backlash is an issue and causes too much slap or can't be adequately compensated for, a worm-gear or toothed-belt drive might be a better choice.

    -Phil
  • ercoerco Posts: 20,260
    edited 2011-01-10 14:22
    @Phil: I'm wide open for another engaging encoder debate. I love your informed insight, you're a lot smarter than me. I'm trying to figure out this software fix for backlash that you often espouse.

    Based on my mechanical experience, lots of geartrain backlash only adds uncertainty to what the wheel position really is. Knowing the motor position to one part in a million can't really improve that situation. Even if you reverse the motor position briefly to take up the slack, the whole geartrain oscillates and the final wheel position is still uncertain. I'm a mechanical engineer, and I'm sold on the requirement for a sound, minimum backlash geartrain. In that case, a wheel encoder works perfectly fine, assuming that the disk resolution is sufficient to meet the accuracy needs.

    A while back, Jay Kickliter had a thread about building a balancing robot using motors with lots of backlash. I kinda had my doubts then, and at last report he threw in the towel on those . Based on recent experiments with my poor man's balancer, I've gotta say that backlash in that application is the kiss of death. That's all about accurate position control, and given how often the motor reverses direction just to hold position, a geartrain with significant backlash would wear rapidly and make a bad situation worse.

    Your thoughts, Professor? :)
  • kwinnkwinn Posts: 8,697
    edited 2011-01-10 14:23
    There is always a tradeoff involved in deciding where to put the encoder on a gear motor, and the optimal position depends on the resolution of the optical encoder, the backlash in the gearbox, as well as the torsional deformation.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-10 14:41
    Another factor is price. A 16-slot encoder on the back of a 100:1 gearmotor will be a lot less expensive than a 1600-slot encoder on the front -- and a lot easier to mount, too.

    My first NC mill was one I built from a Sherline unit and stepper motors. It had no encoders and lots of backlash, which varied over time with wear on the leadscrew thrust washers. Before each milling job, I obtained backlash readings from each axis, which got plugged into the firmware. At each direction reversal, the backlash got taken up before the stroke that caused the reversal was executed. Yes, it was a PITA, but it worked.

    -Phil
  • ercoerco Posts: 20,260
    edited 2011-01-10 15:07
    In the case of your NC mill, I see your point. The bed is big and heavy and the velocities are relative slow, so you have time to deal with the backlash.

    I always speak in terms of a moderate-speed robotic system with demands for dynamic course correction and keeping diff-drive wheels synchronized, in which case backlash ain't your best friend!
  • kwinnkwinn Posts: 8,697
    edited 2011-01-10 15:24
    Another factor is price. A 16-slot encoder on the back of a 100:1 gearmotor will be a lot less expensive than a 1600-slot encoder on the front -- and a lot easier to mount, too.

    My first NC mill was one I built from a Sherline unit and stepper motors. It had no encoders and lots of backlash, which varied over time with wear on the leadscrew thrust washers. Before each milling job, I obtained backlash readings from each axis, which got plugged into the firmware. At each direction reversal, the backlash got taken up before the stroke that caused the reversal was executed. Yes, it was a PITA, but it worked.

    -Phil

    Price is definitely an important consideration. In the case you are describing you also have to consider the backlash and how much it varies with speed and load. A 400 slot encoder on the front might be better than a 16 slot encoder on the motor if there is 1 degree of backlash.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-10 15:45
    Regardless of where the encoder is, you still have to take backlash into consideration. Even when it's on the load side of the gearbox, you need to take it up as quickly as possible after changing direction. The problem of course, is how to do that. For maximum performance, do you run the motor at top speed until you get the first encoder transition, then cut the power and begin your velocity ramping from there? Or does that cause too much gear slap, which could shorten the lifetime of the gearmotor? With the encoder mounted on the motor and a way to monitor motor current, you should be able to tell when the backlash has been taken up (i.e. the motor current wil rise), and you will know how many encoder counts it took to do it. With that information, one could perform predictive backlash take-up in a way that minimized wear on the gears but still had little impact on performance.

    -Phil
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2011-01-10 18:41
    There is one reason in particular why I personally feel it is best to keep the encoder attached directly to the motor shaft. Since it is attached to the actual part you are controlling with your electronics there isn't any backlash between the encoder (feedback) and the armature (control) unless the encoder come loose. There may be some backlash in the actual drive train but that won't affect the actual control and it can be very precise. Every time you move the encoder further out in the gearing you keep adding more backlash for each gear, etc you add in between. If you have a low res encoder out there that is course enough then the slop doesn't mater. However if you stick a nice hi-res encoder out at the wheel and there is slop in the gears then it can be very difficult (if not impossible) to control.

    Robert
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2011-01-10 18:50
    What about an encoder on both? One could directly measure all kinds of things then.
  • lardomlardom Posts: 1,659
    edited 2011-01-11 09:25
    Erco, I will try dymanic braking.
    RobotWorkShop, The motor has a built-in hall effect encoder. I'm using "Quadrature Decoder" by Luke Haywas which is excellent and "SN754410.spin" by Javier R. Movellan which I've tweaked.
    Now that I know that these motors are very precise I will continue working at it. I will build an H-bridge because I think I'm getting stuck at the L293D. The motor coasts when I want it to brake at a certain value. My most recent test was to abruptly reverse direction which gets closer but still goes past the limit I specified.
  • zoopydogsitzoopydogsit Posts: 174
    edited 2011-01-11 10:43
    Hi Larry,

    You can get very precise control. Remember a lot of mid range dot matrix printers used to use DC motors with optical encoder feedback. They would produce 100+ characters per second in each direction, where each character was 7+ pixels wide with all of the collumns of characters visually lining up. Some printer vendors today still use DC motors with optical feedback on their carrage rails for image printing. So the control can be achieved.

    From looking at the L293 data sheet it has a fast motor stop. I've not used it, but it would be worth a try. Part of the problem may be that you are driving the motor flat out and then trying to stop it. You may want to look at ways of throttling it back (maybe pulsing it (but very quick long duration pulsing) aka PWM). This may give you more control. You may want to do some kind of predictive motor control, ie. drive it slower when you get closer to the target.

    One of the things to note with DC motors is an alignment position and crash stop. Normally you'd have an alignment point, on start, it would position itself to this point, some techniques use a switch or optical feedback (ie. photo interupter ( a TX & RX sensor pair) and something to break the beam between the two, other techniques just bang a couple of times against a physical stop and expect it to be at the zero mark. The method you use will depend on the outcome you are trying to achieve, and whether you need to position relative to the alignment point. A crash stop can be useful in case some how you loose your positioning, rather than smashing at the other end of the carriage rail, you again have a sensor that you read (ie. photo interupter/ hall effect sensor / switch) that detects that it's beyond normal operational limits so you can recall it to the callibration point (alignment position).
  • lardomlardom Posts: 1,659
    edited 2011-01-12 08:52
    Hi Zoopy. There is a lot of useful information here so I will refer back from time to time. This motor is my biggest challenge by far. I discovered steppers were simpler. I also found the ULN2803 to be easier than the L293D. I studied the L293D datasheet and I'm still not sure why I can't produce a fast stop. If I build H-bridge I can reduce the number of unknowns. I like the idea of an 'enable' pin and I may upgrade to the L298 once I figure this stuff out.
    I absolutely appreciate the help of this forum.
  • ercoerco Posts: 20,260
    edited 2011-01-12 11:29
    Larry: If you're open to experimentation, check out my thread at http://forums.parallax.com/showthread.php?106382 that details my H-bridge using relays. Low-tech, but quick & simple to build and understand, and it provides both coasting and full dynamic braking. Short of applying reverse voltage, nothing stops a motor like a braking relay. L298s and other motor controller chips are a PITA to use and deliver mushy performance. They can't deliver full voltage or full braking like relays can. For speed control, I add a third SPDT relay to switch between high & low speeds. Stops on a dime and gives you 5 cents change.
  • lardomlardom Posts: 1,659
    edited 2011-01-12 12:13
    Thanks Erco. I'll see if I can pick up a couple of relays at RadioShack today. Experimentation is part of the fun. If I ever dreamed there were no challenges left I would wake up in a cold sweat...
  • ercoerco Posts: 20,260
    edited 2011-01-12 13:10
    Another option is simply to add an SPST braking relay to whatever speed control you fancy. I did this to my Scribbler (keeping the built-in motor drivers), and the results speak for themselves: http://www.youtube.com/watch?v=hGQEzz8CNIQ In this configuration, the relay is installed inline with one of the motor leads: the motor lead goes to the relay Common terminal, and the NC contact goes to wherever that motor lead used to be connected to. Wire the NO contact to the other motor lead and you're done. Now the motor operates exactly as before until you trigger the relay, which turns on motor braking.

    Or switch the NC & NO leads for power-off (failsafe) dynamic braking.

    Even with a continuously variable speed control, I usually use pick two motor speeds (fast and slow) that suit my evil purposes. For encoder control of a motor, I run it at fast speed as I count encoder pulses. Switch to the slower speed as my stop approaches, then brake at the right time.

    You can leave the speed controller on the low speed while the motor is braked, since the motor is disconnected from it. That way you resume turning the motor on slow speed just by turning the braking relay off.
  • lardomlardom Posts: 1,659
    edited 2011-01-12 16:43
    Erco, I just bought a couple of SPDT relays so I'll build the circuit in your schematic. My current project is robotic and I've seen some of your robot videos so I know it's worth trying.
Sign In or Register to comment.