Page 1 of 1
Speed calculation
Posted: Fri Jan 04, 2019 8:00 pm
by Philosophix
I was thinking of calculating vehicle speed in a timer callback-function set to be called at 1 hz, but am unsure what I'm allowed to do inside the callback. Can I declare and use local variables, call other functions, ...? Or is there a better way to implement speed calculation when I know how many pulses the inductive sensor gives per distance unit?
Re: Speed calculation
Posted: Fri Jan 04, 2019 8:33 pm
by jickster
There are rules about ISRs:
https://docs.micropython.org/en/latest/ ... rules.html
Unless you have a time-sensitive action to take, you should consider using micropython.schedule
https://docs.micropython.org/en/latest/ ... n.schedule
With this, you can schedule a callback-function to be executed “as soon as possible” and it will be NOT in ISR context so there’s no restrictions like memory allocation.
Sent from my iPhone using Tapatalk Pro
Re: Speed calculation
Posted: Fri Jan 04, 2019 8:59 pm
by Philosophix
So I schedule a callback-function in the timer callback-function?
What do I do with the arg-argument of the schedule-function if I'm scheduling a function with no args?
Thanx!
Re: Speed calculation
Posted: Fri Jan 04, 2019 10:05 pm
by jickster
Philosophix wrote:So I schedule a callback-function in the timer callback-function?
What do I do with the arg-argument of the schedule-function if I'm scheduling a function with no args?
Thanx!
Pass in 0 like the timer example here
https://docs.micropython.org/en/latest/ ... #isr-rules
Sent from my iPhone using Tapatalk Pro