Skip to main content
15 events
when toggle format what by license comment
Aug 6, 2015 at 9:24 comment added Edgar Bonet There is no point in making LoopTime static, as it is set on every call to the function. The whole point of static is to make sure the contents of the variable is preserved between calls. Static locals are much like globals in this respect, only they have a restricted scope. On the other hand, Setpoint should probably be static, otherwise it seems it may be returned uninitialized. And the line Setpoint = Setpoint; has no effect.
Aug 5, 2015 at 14:46 answer added 2785528 timeline score: 1
Aug 3, 2015 at 8:04 comment added KoenR Hello Nick, yes you are right, when the function "starts up" it is calledwith Iteration -1. The amount of iterations it takes is depended on the DeltaPosition and the Velocity. Normally this will 500+
Jul 31, 2015 at 21:58 comment added Nick Gammon I understand better what you are attempting now. I gather you call the function with Iteration == -1 at some stage to "preload" the static variables, and then multiple times with other iteration values. To answer better we would need to know how often you do that. For example, do you do 1000 iterations before re-calculating the static variables? Or three iterations? Judging by the fact that you get PID.ActualPosition in the "preload" part, you must be calling it with Iteration == -1 reasonably often.
Jul 31, 2015 at 2:55 history edited Nick Gammon
Added more tags.
Jul 31, 2015 at 2:54 answer added Nick Gammon timeline score: 2
Jul 30, 2015 at 16:49 answer added BrettFolkins timeline score: 0
Jul 30, 2015 at 11:10 comment added KoenR That too, but I actually meant the calculations of the statics at iteration == -1. Won't this save? If not, I can make those local
Jul 30, 2015 at 11:04 comment added CharlieHanson So you mean you want to 'create' variables so that they already exist before you start the beefy calculations, thus saving time? I don't think it works like that. All the calculations after the if (iteration == 1) is going to get torn apart by the compiler and then rearranged as optimally as it thinks it can be. If you need execution of these to be quicker, you might be better off asking in StackOverflow, as this topic transcends Arduino and is definitely within the realm of programmers and compilers.
Jul 30, 2015 at 10:52 comment added KoenR No but my idea was to calculate some variables infront (iteration -1) how could i use those otherwise?
Jul 30, 2015 at 10:50 comment added KoenR I am still a newbie haha, hmm better replace that pow function...
Jul 30, 2015 at 10:48 comment added Nick Gammon pow(AccelerationLoops, 2) - you want fast speed but then you call a function that will be slow?
Jul 30, 2015 at 10:46 comment added Nick Gammon to increase the speed I added some static variables to it. - how does that increase the speed?
Jul 30, 2015 at 10:44 comment added CharlieHanson Why do you need static variables in the above example? I can't see them being any use here. If you just want a variable that you can change easily because you're 'tweaking' your code (e.g. changing LoopTime so you get as many loops per second without compromising accuracy) then pull that variable into global scope; you can #define <name> <value> or const <Type> <name> = <value>. These declarations/definitions get 'smoothed out' by the compiler and so don't take up any program memory.
Jul 30, 2015 at 10:31 history asked KoenR CC BY-SA 3.0