-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing continuous sinusoidal velocity profile #2
Comments
Hi Tobie, If you want a sinusoidal speed pattern, I guess you'd need to change the lookup table on line7:
I wrote about this code in my blog: https://fightpc.blogspot.com/2018/04/how-to-get-sinusoidal-s-curve-for.html Maybe what you need is to regenerate the values so it comes back at the end to the same value as at the beginning. |
Yes, the table represents the distance traveled. So the value has to grow
monotonically.
Then a simple search finds the two values in between a given value is, so a
linear interpolation can be done.
…On Sat, May 1, 2021 at 7:31 AM Tobie Horswill ***@***.***> wrote:
Hi Miguel,
Thanks for the reply.
I plotted your current LUT into Excel to see what it looked like:
[image: image]
<https://user-images.githubusercontent.com/18149102/116771010-04b67180-aa16-11eb-91ac-aad347b9c8b3.png>
My first attempt based on a sine curve looked like this (2 pi sin(pi/1000
t):
[image: image]
<https://user-images.githubusercontent.com/18149102/116771036-3deee180-aa16-11eb-8bcb-b2888c315ac9.png>
This LUT resulted in this rather interesting but unexpected actual
velocity profile:
[image: image]
<https://user-images.githubusercontent.com/18149102/116771413-1fd6b080-aa19-11eb-810a-f20286b9dfa7.png>
That didn't work out like I expected because I believe I misunderstood the
purpose of your table...
I generated the velocity curve of the end result I wished to achieve but I
think your table actually describes the positionnal displacement between
time increments. Correct? So I guess I would need to generate the integral
of my sine curve in order to generate a LUT which describes the
displacement between time increments?
However, and I'm not sure if this was a fluke, but the velocity profile
that resulted from my sine table almost appears to be that of a cosecant
which I believe is the reciprocal of a sine curve. So I'm not sure if I
should be trying to integrate or instead reciprocate my first attempt ...
Any further thoughts are welcome,
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSBX54NFI5MJMBTRMLLTLOG4DANCNFSM433MIVCA>
.
|
But ... now that I think of it, the table contained only half of the
acceleration. I mean, for a trapezoid there is a speed-up section, a
coasting section (if possible) and a slow-down section. The values on the
table work for the speed-up. For the slow-down, they are to be applied
backward (so the table does not contain the full thing but half of it.
…On Sat, May 1, 2021 at 9:19 AM Miguel Sanchez ***@***.***> wrote:
Yes, the table represents the distance traveled. So the value has to grow
monotonically.
Then a simple search finds the two values in between a given value is, so
a linear interpolation can be done.
On Sat, May 1, 2021 at 7:31 AM Tobie Horswill ***@***.***>
wrote:
> Hi Miguel,
>
> Thanks for the reply.
>
> I plotted your current LUT into Excel to see what it looked like:
> [image: image]
> <https://user-images.githubusercontent.com/18149102/116771010-04b67180-aa16-11eb-91ac-aad347b9c8b3.png>
>
> My first attempt based on a sine curve looked like this (2 pi sin(pi/1000
> t):
> [image: image]
> <https://user-images.githubusercontent.com/18149102/116771036-3deee180-aa16-11eb-8bcb-b2888c315ac9.png>
>
> This LUT resulted in this rather interesting but unexpected actual
> velocity profile:
> [image: image]
> <https://user-images.githubusercontent.com/18149102/116771413-1fd6b080-aa19-11eb-810a-f20286b9dfa7.png>
>
> That didn't work out like I expected because I believe I misunderstood
> the purpose of your table...
>
> I generated the velocity curve of the end result I wished to achieve but
> I think your table actually describes the positionnal displacement between
> time increments. Correct? So I guess I would need to generate the integral
> of my sine curve in order to generate a LUT which describes the
> displacement between time increments?
>
> However, and I'm not sure if this was a fluke, but the velocity profile
> that resulted from my sine table almost appears to be that of a cosecant
> which I believe is the reciprocal of a sine curve. So I'm not sure if I
> should be trying to integrate or instead reciprocate my first attempt ...
>
> Any further thoughts are welcome,
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#2 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AADRZSBX54NFI5MJMBTRMLLTLOG4DANCNFSM433MIVCA>
> .
>
|
Of course, you can build a longer table that covers both acceleration and deceleration and just use a single loop to go through it all. |
Hello, Based on this information and what you mentioned above I came up whit this curve/table ( -A cos(wt) ). I've used a 2Pi amplitude, a Pi/1000 frequency and offset the whole curve vertically by Pi to generate the table. It appears very similar to the position curve in your last suggestion. I realized that I was only switching directions once per cycle instead of twice (duh!) which was adding to the confusion but something is still obviously wrong as the motion profile I'm getting is as follows: Very pretty but not what I'm looking for. Here's what I've done with your code (you can ignore the ClearCore stuff, it is the hardware platform I'm using) :
|
Ok, I just understood something else. Your lookup table doesn't exactly give the distance function of time but rather the time required between pulses to achieve the same profile. So it really is the inverse of the position (which, in hindsight, is exactly what you described in your blog post). |
A stepper pulse translates into a certain linear or angular motion
(depending on your application). When facing the problem of creating the
timing for each pulse you can focus on the time between pulses (the inverse
of which represents the speed) or the distance (or angle) covered. A given
absolute distance translates to a certain number of steps. So what I have
here is a function of the distance traveled (not a function of time). So I
can look it up to determine the time of the next step. I hope this serves
to explain it better so you can place your own table.
|
Hurrah! I thought your graph above looked a lot like a sin-¹ so I based my LUT on that, rescaled and shifted it until it fit within the required bounds and it works fine now! Next step is to make it dynamic so I can alter amplitude and period on the fly via OSC which shouldn't be too difficult using the N and kt variables you've already defined in your code :) You've been very generous first with your source code and then with your time. Thanks so much for your help! |
It looks great, congratulations! |
Hello Misan, thank for sharing your source code .but i dont know to how to create the table using wxmaxima with my velocity parameters ? |
Hi,
The code was intended for mapping the acceleration pulses of a velocity
s-curve. The idea is that the second part of the s-curve (third if you
count the coasting section as one) will be done by replaying the
acceleration phase backward. If you have previously saved the pulses time
in an array, you do not need to recalculate them when decelerating.
In my case, the goal was to obtain a velocity curve following (-cos(t)1)/2
but in order to get the time for the stepper pulses (a pulse equates to a
given space, not speed, I needed to work with the Integral of that space
that represented the actual space traveled over time).
If you want speed to be sin(t) then the integral of that and thus the space
traveled would be -cost(t), that is the function you use for the 'e' in my
code. My guess is the integration constant would be 1 so the distance
traveled at t=0 be 0 too.
I understand that such a speed pattern would leave the motor at the same
position at the end of it as it was at the start.
I am not sure how can help.
Kind regards,
Miguel Sánchez
…On Fri, Apr 30, 2021 at 7:09 AM Tobie Horswill ***@***.***> wrote:
Hello Misan,
Thanks for sharing this bit of code. I have been having lots of fun with
it!
I've adapted it a bit in order to mimic the behavior of a simple pendulum.
So I've gotten rid of the cruise portion and am flipping the direction pin
on every iteration of the loop. Now I would like to get rid of the last
part of the "S" in your brilliant "S" curve... If you look at this scope
capture I think you'll understand what I mean.
[image: image]
<https://user-images.githubusercontent.com/18149102/116650130-99ee3300-a94e-11eb-9f78-f0471a032973.png>
So I'd like for the velocity command curve to be as close as possible to a
true sinusoid but I'm not sure where in your Solve subroutine the returned
value gets flipped around to generate the end of the S curve. Or perhaps
this S shape is directly mapped in your lookup table?
Again many thanks and warm regards,
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSHH4SNZLX4LEB2AGHTTLI3PPANCNFSM433MIVCA>
.
|
The curve I create is representing the displacement during acceleration
versus time for a sinusoidal s-curve for the speed under the assumption
that t goes from 0..2*PI which yields a PI^2 distance traveled.
That would be green line in the graph below:
[image: image.png]
…On Sun, Nov 27, 2022 at 3:52 PM sdydjciv ***@***.***> wrote:
i tried in wxmaxima
e: (t-sin(t))/2*%pi;
fr(x):=find_root(e=x,t,0,2*%pi),number;
solve([for i:1 while i<=100 do display(fr(i*9.869604401089358/100))], [x]);
but in exel frequency doesn't like s curve
[image: dasdasf]
<https://user-images.githubusercontent.com/59269216/204141645-cd9bdb53-d0ae-4cde-8797-c99e2a0216b9.JPG>
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSCGVINUPICJRCY4EB3WKNYTZANCNFSM433MIVCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hi,
I reckon I just copied and pasted it into a text file. Then I used a few
searches and substitutions so it was in my desired format (x,t).
I guess you can write the desired output right from wxmaxima but I did not
dig into its file I/O functions:
https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html#File-Input-and-Output
…On Wed, Nov 30, 2022 at 2:59 PM sdydjciv ***@***.***> wrote:
I seem to have understood a bit and I want to ask how do you copy these
data into the array in the fastest way
[image: value]
<https://user-images.githubusercontent.com/59269216/204815240-bcf81598-9491-4a6d-a706-1a615de27846.JPG>
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSEQLVVCQSYQS6R7VZDWK5MTDANCNFSM433MIVCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
FYI, it turned out to be simpler for me to generate the arrays through
Excel functions and export the areas of interest containing the raw values
as CSV files.
This allowed me to iterate more quickly between Excel and C code through
the different versions until I got the motion profile I wanted.
[image: image.png]
On Wed, Nov 30, 2022 at 11:19 AM Miguel Sanchez ***@***.***>
wrote:
… Hi,
I reckon I just copied and pasted it into a text file. Then I used a few
searches and substitutions so it was in my desired format (x,t).
I guess you can write the desired output right from wxmaxima but I did not
dig into its file I/O functions:
https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html#File-Input-and-Output
On Wed, Nov 30, 2022 at 2:59 PM sdydjciv ***@***.***> wrote:
> I seem to have understood a bit and I want to ask how do you copy these
> data into the array in the fastest way
> [image: value]
> <
https://user-images.githubusercontent.com/59269216/204815240-bcf81598-9491-4a6d-a706-1a615de27846.JPG
>
>
> —
> Reply to this email directly, view it on GitHub
> <#2 (comment)>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AADRZSEQLVVCQSYQS6R7VZDWK5MTDANCNFSM433MIVCA
>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEKO53RM6SNYLO3FUTIAMGDWK55CNANCNFSM433MIVCA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi Tobie,
I reckon many times, the best tool is the one you know best. I feel at ease
with command line tools, but that is a bummer for many people. I am not an
Excel power user though. I reckon Excel features a solver, too, so it can
most likely be done within Excel.
However, the image you sent was lost somehow, so I can only see [image:
image.png] in your email.
Happy you get it working,
Miguel
On Wed, Nov 30, 2022 at 5:57 PM Tobie Horswill ***@***.***>
wrote:
… FYI, it turned out to be simpler for me to generate the arrays through
Excel functions and export the areas of interest containing the raw values
as CSV files.
This allowed me to iterate more quickly between Excel and C code through
the different versions until I got the motion profile I wanted.
[image: image.png]
On Wed, Nov 30, 2022 at 11:19 AM Miguel Sanchez ***@***.***>
wrote:
> Hi,
>
> I reckon I just copied and pasted it into a text file. Then I used a few
> searches and substitutions so it was in my desired format (x,t).
>
> I guess you can write the desired output right from wxmaxima but I did
not
> dig into its file I/O functions:
>
>
https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html#File-Input-and-Output
>
> On Wed, Nov 30, 2022 at 2:59 PM sdydjciv ***@***.***> wrote:
>
> > I seem to have understood a bit and I want to ask how do you copy these
> > data into the array in the fastest way
> > [image: value]
> > <
>
https://user-images.githubusercontent.com/59269216/204815240-bcf81598-9491-4a6d-a706-1a615de27846.JPG
> >
> >
> > —
> > Reply to this email directly, view it on GitHub
> > <#2 (comment)
>,
> > or unsubscribe
> > <
>
https://github.com/notifications/unsubscribe-auth/AADRZSEQLVVCQSYQS6R7VZDWK5MTDANCNFSM433MIVCA
> >
> > .
> > You are receiving this because you commented.Message ID:
> > ***@***.***>
> >
>
> —
> Reply to this email directly, view it on GitHub
> <#2 (comment)>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AEKO53RM6SNYLO3FUTIAMGDWK55CNANCNFSM433MIVCA
>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSEB4EA7AG6LBH4KFRDWK6BNVANCNFSM433MIVCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hello Misan,
Thanks for sharing this bit of code. I have been having lots of fun with it!
I've adapted it a bit in order to mimic the behavior of a simple pendulum. So I've gotten rid of the cruise portion and am flipping the direction pin on every iteration of the loop. Now I would like to get rid of the last part of the "S" in your brilliant "S" curve... If you look at this scope capture I think you'll understand what I mean.
So I'd like for the velocity command curve to be as close as possible to a true sinusoid but I'm not sure where in your Solve subroutine the returned value gets flipped around to generate the end of the S curve. Or perhaps this S shape is directly mapped in your lookup table?
Again many thanks and warm regards,
The text was updated successfully, but these errors were encountered: