Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Smooth acceleration and deceleration of a stepper motor


  • Please log in to reply
3 replies to this topic

#1 inxtremo

inxtremo

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 29 February 2012 - 07:15 AM

Good morning, after successfully communicate with my stepper motors via N+, FTDI Breakout Board and a WPF application i wonder how to accelerate and decelerate my steppers in a smooth way. On YouTube exists several examples, most on the Arduino plattform. I found a class for Arduino too, "AccelStepper", which make such things possible. But how to do that on a Netduino? Should i port an Arduino code snippet to C#? Most snippets i see using float numbers for the delay between 2 pulses, but on C# i can only use Thread.Sleep(int). Any suggestions on this? Thanks and best regards, Daniel

#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 05 March 2012 - 08:25 PM

Hi there, I am used to working on DSP designs where it is sometimes necessary to step through an array of values at a fractional rate. For example, generating a sine wave with an arbitrary frequency using a 256 point sine wave lookup table that is stored in an array. To do this you need an integer index to access the table, but the index needs to increment (or decrement) in non-integer steps :blink: This sounds like a similar problem as you are trying to solve. The solution for generating a sine wave is to store the floating point increment in a variable and add it to a running floating point counter when each sample period comes round. To fetch a value from the array, we simply use the integer part of the counter. In the background the fractional parts will eventually add up to an extra step every so often and this gives the impression that the table is being stepped through at a non-integer rate. How does this help you? Stepping though an array at a fractional rate is similar to stepping through time at a fractional rate. Create a floating point millisecond counter variable. Each time you need to implement a delay between steps, take your desired floating point millisecond delay value and add it to the counter. Then, take the integer part of the counter and use it for the next millisecond delay. Deduct that integer value from the counter. Doing this will average out the fractional parts that you can't express in a delay of integer milliseconds, and the result should be a smooth stepper movement. Hope this helps - Paul

#3 inxtremo

inxtremo

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 07 March 2012 - 06:45 AM

Hi there,

I am used to working on DSP designs where it is sometimes necessary to step through an array of values at a fractional rate.
For example, generating a sine wave with an arbitrary frequency using a 256 point sine wave lookup table that is stored in an array. To do this you need an integer index to access the table, but the index needs to increment (or decrement) in non-integer steps :blink:

This sounds like a similar problem as you are trying to solve.

The solution for generating a sine wave is to store the floating point increment in a variable and add it to a running floating point counter when each sample period comes round.
To fetch a value from the array, we simply use the integer part of the counter.
In the background the fractional parts will eventually add up to an extra step every so often and this gives the impression that the table is being stepped through at a non-integer rate.

How does this help you? Stepping though an array at a fractional rate is similar to stepping through time at a fractional rate.

Create a floating point millisecond counter variable.
Each time you need to implement a delay between steps, take your desired floating point millisecond delay value and add it to the counter.
Then, take the integer part of the counter and use it for the next millisecond delay.
Deduct that integer value from the counter.

Doing this will average out the fractional parts that you can't express in a delay of integer milliseconds, and the result should be a smooth stepper movement.

Hope this helps - Paul


Wow, thanks a lot.

I think at weekend i have the time to think about your answer in more detail. I´ll post my results.

So far, i re-implemented a method for trapezoidal acceleration i seen for the Arduino. Works fine but i´m sure there are lot of space to improve this.

Thanks and best regards,
Daniel

#4 ItsDan

ItsDan

    Advanced Member

  • Members
  • PipPipPip
  • 101 posts

Posted 07 March 2012 - 03:55 PM

Depending on what you mean by smooth, a sine curve is really one of the simplest ways to model any kind of non-linear change in a value.
Follow the adventures of the Box of Crappy Surplus

Total BOCS Traveled Distance: 9708 miles | States Visited: 5
Track the Box




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.