Moving code from ESP8266 to ESP32

A while ago I made a mashup of Dan Royer's code CNC 2 Axis Demo with my own code for trapezoidal motion stepper and servo control for ESP8266.

I assumed porting the code to the ESP32 would be trivial, and that was true for the most part: changes like library name being Wifi.h instead of Wifi8266.h were not a problem. UDP now does not like multicharacter writes but you can use print instead. So far so good.

However, when it came to the interrupt code I was stuck with the stepper interrupt causing an exception sometimes. And to make things weirder, the servo interrupt worked flawlessly (both of them had the IRAM_ATTR directive if you ask me).

Going little by little, I could narrow down the culprit to a floating point operation during the interrupt, that would cause problems sometimes but not always. Browsing around I found this post. Where the solution was simple: do not use floats within the interrupt routines but doubles. The reason was the float calculation would be performed by…

Sinusoidal functions for s-curve motion

While trapezoidal speed motion pattern is good and well. It is well known that the sudden changes in acceleration it requires, also known as jerk (jerk being the time derivative of the acceleration) is the cause of trouble in many machines.

That first model can be improved with another acceleration shape that will remove the sudden changes, thus improving the system performance.

However, will there are no sharp edges on the acceleration values, there is still a couple of points where there is a not so smooth change. So the next idea, while still within the use of a sinusoidal acceleration profiles is to change to this other acceleration profile:

This new curve has smoother transitions from zero to any other value, thus no more problems with the jerk. However, we still can think of a combination of this latter case and the initial one, where corners are smoothed out using a sinusoidal:
That is what they suggest in this paper

While I was not eager to use any complex math in my dcservo project, I wanted to extend the trapezoidal method with something a bit smoother. And once I have learned a single trigonometric function call in Arduino takes around 100 microseconds I think I can play with these patterns to see which one works best. 

What I have found surprising is that Arduino M0 trigonometric functions seem to be no faster than the 8-bit older boards.


Popular posts from this blog

VFD control with Arduino using RS485 link

4xiDraw: Another pen plotter

Software I2C for Arduino