Author Topic: Precision ratio between Stepper axes when the main loop timestep is too coarse  (Read 1903 times)

0 Members and 1 Guest are viewing this topic.

Offline MLMTopic starter

  • Contributor
  • Posts: 18
  • Country: us
    • Eric Eastwood
How can I keep a precision ratio between two axes when the main loop timestep is too big?

Say the main loop timestep is 0.1 seconds. If the stepper pulse width is 0.01 for x and 0.05 for y. Then with my current code, on each tick they both step(because 0.1 > (0.01 || 0.05)) and you end up with a uniform diagonal line instead of a line with 1/5 slope.


I can't just use a fixed timestep and run through/catch-up on the frames because my actual application, driving stepper motors, there needs to be real-world time between each movement. Each step moves a certain linear distance.

I tried using the overflow/error time but it doesn't correct it.

The problem isn't calculating a linear path, it is translating that into pulse steps.

I am going to be running on a Teensy 3.0/3.1. I am using the elapsedMicros type to write non-blocking code.

Demos:

Here is a barebones JavaScript simulation demo: http://jsfiddle.net/MadLittleMods/6n3s3p1d/6/

I am going to port over this code once it is working correctly. I am using JavaScript for easy prototyping and debugging.
« Last Edit: March 11, 2015, 06:49:19 pm by MLM »
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Bresenham's algorithm works very well, but you have to tailor the code for each octant that you work in.
 

Offline MLMTopic starter

  • Contributor
  • Posts: 18
  • Country: us
    • Eric Eastwood
I was able to get my barebones demo working somewhat accurately with some help from Luggage over in the SO JavaScript chat room.

Fixed demo: http://jsfiddle.net/MadLittleMods/6n3s3p1d/20/

The key was to remove any the same amount of extra time(whichever axis had more time one was more) from both axes.

While this fix helps a lot, I am not totally happy with the result the line is far from perfect.


Bresenham's algorithm works very well...
I am working on a demo now that uses Bresenham's line algorithm to see how it works and compare.



Here are some later iterations:

« Last Edit: June 21, 2016, 06:52:39 pm by MLM »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf