Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Tue Nov 21, 2017 8:27 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Nov 14, 2011 3:31 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
I am using the following equation to figure out the peak velocity of a trapezoidal motion profile when the duration, accel/decel and distance are known. I have attached an image file of the source equation, perhaps someone can check if I have written it out properly in Qlarity code.

I am getting strange result when I plug in different accel(ac) and decel(dc) values in to the equation. I expect that the result (the "speed" variable) will always be above 500, and get closer to 500 as the ac/dc values rise because a move of 10000(dist) counts that takes 20 seconds (dur) should have a speed of 500 if the accel/decel is instantaneous. I am getting results that are always near 500, but sometimes they are above and sometimes they are below, and it is not consistent as I raise the ac/dc values. Perhaps my equation is just bad, or perhaps I have written it poorly, or perhaps there's something going on with the precision of float variables??

Notes: I am using the equation at the bottom of the image I posted as the source for this code. It starts " Vs -> "
Vs = speed (peak velocity)
t = dur (total duration)
d = dist (total distance)

I have omitted all portions of the source equation that contain a multiple of (Vf) because it always equals zero for my purposes. Also, the ac and dc values can not be equal or you will get a division by zero error.


Code:
   dim dist as float
    init dist := 10000
    dim dur as float
    init dur := 20
    dim ac as float
    init ac :=1000
    dim dc as float
    init dc :=1100
    dim initspeed as float
    init initspeed :=0
    dim speed as float


speed=(1/(2*(ac-dc)))*((-2*ac*dc*Dur)-(2*dc*initspeed)+SQRT(power((-2*ac*dc*dur)-(2*dc*initspeed),2)-(4*(dc-ac)*((2*ac*dist*dc)+(dc*power(initspeed,2))))))


Attachments:
equation for velocity.png
equation for velocity.png [ 9.71 KiB | Viewed 1441 times ]
Top
 Profile  
 
PostPosted: Tue Nov 15, 2011 7:46 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
I probably don't have a direct answer here. I can give some tips on how I would approach the problem.

The first thing I would do with a long equation like this is to break it into little parts. Not only will it probably give more readable code, but you will also get the benefit of intermediate values that you can much more easily verify. Certainly in code like this it is very easy to transpose a sign or misplace a parenthesis. Something like

Code:
term1 = 1 / (2 * (ac-dc))
_2_ac_dc_t = 2 * ac * dc * t
_2_dc_vi = 2 * dc * initspeed
' etc

speed = term1 * (-_2_ac_dc_t - _2_dc_vi '... etc

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Tue Nov 15, 2011 7:47 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Also, the debugger here is your friend. Put a breakpoint on the line with the first calculation and step line by line and manually verify that each term is evaluated to what you expect.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group