Hi everyone,
I'm writing to get some help on a program I'm writing to control stepper motors. I've already got a version of the program working where my program (developed in C#) will send a string of data (over serial) over to the arduino board with information about how to control up to four steppers (using the AccelStepper library: GitHub - adafruit/AccelStepper: A small fork of AccelStepper v1.3 with AF_motor (Adafruit motor shield) support!). This process works pretty well, however my arduino code currently calls non-blocking move functions... so every time the serial data is available, it reads it in and then immediately tries to move the motors to those positions. However, it may not have reached the destination it had previously been trying to get to, before this next command had been issues. This non-blocking sequence is helpful in some instances, like when you move a slider and you want the stepper to try to keep up with the most current position. However, it's a bit troublesome if trying to control precisely the movement path of a motor (say for a CNC machine) where it needs to move to every position before moving onto the next instruction.
So, I think I need to rethink the workflow a bit. First, I'm pretty sure I'll need to use blocking commands (the Accel Stepper library has both)... however, more importantly I need the Arduino to send a call back to my application letting it know that it just completed the last move and it's ready to receive the next one. The issue I see is that my applications update cycle is relatively slow (and it's scene dependent... meaning the more stuff I have going on in the scene, the slower the refresh rate will be)... Typically the fastest I've been able to get it to run is 60Hz, but usually closer to 30Hz. So, if I'm trying to get smooth motor control, this may be a problem, because my application will send a command and then wait for the call back... The arduino will execute the command and then send the call back and wait for the next command from GH. However, there is probably going to be a delay of several milliseconds between those two actions... and this could cause somewhat jerky motion.
I'm wondering if anyone has any suggestions about how to resolve this. Are there any ways to issue a callback to another application and have it basically be instantaneous? The other issue I see is how can I control up to 4 motors in parallel if using blocking commands? If it's a blocking function, wouldn't it have to move one motor, then the next, then the next, etc. Is there a way to be able to control motors in parallel and still know when the stepper has completed moving to its destination? If it would help, I can post the arduino code that I have so far... but currently it's just implementing the non-blocking functions and doesn't implement the call back function at all. Thanks for the help.