0

I am trying to draw a circle or anything that could be close to a curve (Sine for example) using two motors on a 2 dimensions axes. Basically I am running a raspberry Pi and the Adafruit motor HAT with two nema17 steppers motors.

I would like to achieve something 'smooth' but it seems that I can only get really "aliased" results and I am wondering if this is because I am driving steppers motors. (But I believe 3D printers use steppers motors and achieve some good results)

Doing some math, I can work out the speed of each motor : X = R cos(t) and Y = R sin(t) so Vx = -R sin(t) and Vy = R cos(t)

But I am not sure this is the best approach as I am not sure I can drive the speed on stepper motor but only doing some delays between the steps.

I also thought about calculating all x and y positions of a curve, but again I am not sure the precision of my build is high enough.

To complete, I am using the Adafruit Library : https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library so I am not really digging into the hardware code but just using the functions the library offers. Basically, I can run each motor separately for x amount of steps. And this is the stepper card : https://www.adafruit.com/product/2348

The build (this is very DIY) : https://www.youtube.com/watch?v=uqSTZiI4KuY

batmat
  • 225
  • 1
  • 5
  • 17
  • 1
    If your stepper motors are rather high-geared so that one step is e.g. 1mm then you will have great difficulty getting something that appears smooth. OTOH if one step is e.g. 0.1mm (or less) then you should be able to get smooth lines. You will also have to make lots of steps - if you try to approximate a circle with e.g. 8 samples then you will get an octagonal shape. To get any more precise help you will have to post your code. – DisappointedByUnaccountableMod Oct 26 '16 at 22:03
  • I have added details to my question. I believe I can have some good resolution, I think 1 step < 0,1mm. – batmat Oct 27 '16 at 18:02
  • If you only run one motor at once then inevitably you will get short horizontal or vertical lines, especially with inevitable shaking due to motor start/stop. To get diagonal lines you must run both motors at the same time - each at a rate corresponding to the slope of the line you are trying to draw - and preferably keep the motors running continuously, modulating their speed rather than starting/stopping. – DisappointedByUnaccountableMod Oct 28 '16 at 08:07
  • I can run both motors at the same time but what do you mean by "each at a rate corresponding to the slope of the line you are trying to draw" ? – batmat Oct 28 '16 at 19:47

1 Answers1

0

First some specifications would be in order:

  1. How looks your motor control?

    what do yo controlling (speed, +/- pulses, ???) Do you have any correction unit present (if you drive wrongly will it kick in and correct the values so motor does not lose position)? Do you have motion control processors or do you generate the pulses your self?

  2. What is your target precision and step resolutions?

Now some insight:

I do not think your approach is good because you can not drive your motors with any speed instead you should maintain speeds ratio between the motor so the movement slope is what you need. These are main reasons for the aliasing and distortion I am usually dealing with:

  1. Step resolution

    If you manage to drive speed smoothly then for curves you can sometimes ignore the step resolution as it will smoothly be override by inertia and construction flexibility. So unless you got really big steps that should not be much of an issue.

  2. Vibrations

    This is the biggest problem because you can not drive stepper motor with any speed you want. Each motor is different and also matters what the motor is mechanically connected to (both stator and rotor). Stepper motors does usually have resonance area in low frequencies so starting motor should be done these areas are either avoided (if possible) or driven through as quick as you can.

    If you are working in this area then the motor is creating specific vibrations messing all for example instead of straight line you got something like sin-waves instead. This area also present other problems like you are losing a lot of energy and the useful torque is just fraction of the normal operation level making all computation of dynamics almost impossible.

    If you want to identify which frequencies are the problem then drive your motor with constant frequency for example 50Hz for few seconds then 100,150,200, 250,... and when you start hearing the noise or the motor will start jumping/vibrating you are near the resonance area. The closer you get the worse it gets!

    If you do this with unattached motor you will get the resonance frequency of the motor. But there can be also one or more resonance areas of the mechanic itself so you should do this also within the mechanic on its load.

  3. control unit

    If you got separated motion processors for each motor (like many CNC do) then making curves is not possible in the best precision the mechanics and gears can provide. Because separate motion control units can do just lines perfectly (and only in best case scenario) as the bit-stream needed for curves must be generated synchronously which is not possible on such setup. In such case if you approximate your curve by many lines the output looks usually better. If you drive such setup with curve instead the output will oscillate around the desired shape especially if you got different mechanical properties per each axis.

    If you generate the pulses on your own then you should be OK. Motion control with curve interpolation is not an easy stuff. I do it by generating control points along the curve I want to "render" then compute the speeds so the motors does not loose position and the stuff is not done faster then the speed of the tool attached to the CNC. After that I interpolate the curve in steps resolution and generate control stream with +/- control bits present for each driven motor and that is then synchronously send to motors. But the stuff I put into few lines of text is so complex it could fill entire books. I am coding this stuff for my work for more then a decade (as it pays my bills) and I am still a rookie in the field.

  4. Electrical fault

    Sometimes cold joint and or high noise can cause a lot of unforseen problems especially on home made HW. Newbies usually ignore stuff like shielding,length and placement of cables, EMC or RF noise,power/digital/blocking grounds etc. To be sure your electrics is OK you can test it. Hook up a counter to your motor control and see if the count of pulses is as it should be. Also using oscilloscope to probe some pins for noise durring operation does not hurt. The motors and the Motor drivers can generate a lot of noise which sometimes can distort the motion control or sended data.

    But before you start poking around read this:

So my advice is detect which is the cause of the distortions you got and then remove it if you can ...

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thank you, this is a very complete response, I understand all your points for aliasing and resolution, I have added some details to my question. – batmat Oct 27 '16 at 18:07
  • @batmat looks like no motion control processor unit is present (in HW) but I have no experience with the Adafruit lib so I can not decide if there is a SW control layer or not but I strongly doubt it so you can most likely ignore the stuff in bullet #3. – Spektre Oct 27 '16 at 19:37