I have a project were I'm feeding a stream of rotation data to the Teensie via a serial connection from a PC. That data is arriving at random speed but is generally delivered around 80 - 100 Hz. I then need to take that data and feed it live to several large stepper motors.
So far to do this I'm setting a target rotation for each motor directly from the incoming stream of serial data as well as keeping track of the current rotation for each motor, and when the rotation value is offset by more than a step, I fire off a single step in the required direction and increment the current rotation value. This works really well however the Teensie is so fast it will complete several loops on this logic too quickly then do nothing until the next packet arrives. I think this causes a lot of vibrations in the motor.
Are there libraries out there that would help smooth out the steps or is this stuff I need to program myself. I figure I could predict the average packet arrival time by averaging it over time, then spread the steps out over the predicted time interval to the next value. So say I get a difference of rotation of 2 degrees. I know the next packet will arrive in approx 10ms so I time my 20 steps 0.1ms apart instead of all at once. If a new rotation value arrives early and I haven't completed all the steps then it will retarget the next rotation and time it out based from the current achieved position. Alternatively I could go into calculating acceleration / velocities and smooth the steps based on trajectories etc.
I've done very little coding so I'm not really sure on the best way to do this stuff. Also controlling stepper motors smoothly is going to be important for my project.
Any advice?
So far to do this I'm setting a target rotation for each motor directly from the incoming stream of serial data as well as keeping track of the current rotation for each motor, and when the rotation value is offset by more than a step, I fire off a single step in the required direction and increment the current rotation value. This works really well however the Teensie is so fast it will complete several loops on this logic too quickly then do nothing until the next packet arrives. I think this causes a lot of vibrations in the motor.
Are there libraries out there that would help smooth out the steps or is this stuff I need to program myself. I figure I could predict the average packet arrival time by averaging it over time, then spread the steps out over the predicted time interval to the next value. So say I get a difference of rotation of 2 degrees. I know the next packet will arrive in approx 10ms so I time my 20 steps 0.1ms apart instead of all at once. If a new rotation value arrives early and I haven't completed all the steps then it will retarget the next rotation and time it out based from the current achieved position. Alternatively I could go into calculating acceleration / velocities and smooth the steps based on trajectories etc.
I've done very little coding so I'm not really sure on the best way to do this stuff. Also controlling stepper motors smoothly is going to be important for my project.
Any advice?