Speed calculation
-
- Posts: 24
- Joined: Wed Jan 02, 2019 11:45 am
Speed calculation
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
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
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
-
- Posts: 24
- Joined: Wed Jan 02, 2019 11:45 am
Re: Speed calculation
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!
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
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