![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
my new gear...
control_theory/nap.cpp@22:394337a4205a, 22 months ago (annotated)
- Committer:
- yootee
- Date:
- Sat Oct 15 07:52:25 2022 +0000
- Revision:
- 22:394337a4205a
- Parent:
- 6:e7f2335456c8
upgrade
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yootee | 0:1456b6f84c75 | 1 | #include <nap.hpp> |
yootee | 0:1456b6f84c75 | 2 | |
yootee | 0:1456b6f84c75 | 3 | NAP::NAP(float nap_time):nap_time_(nap_time){ |
yootee | 0:1456b6f84c75 | 4 | restart(); |
yootee | 0:1456b6f84c75 | 5 | } |
yootee | 0:1456b6f84c75 | 6 | |
yootee | 0:1456b6f84c75 | 7 | void NAP::take_a_nap(){ |
yootee | 0:1456b6f84c75 | 8 | while((now_time - prev_time) < (nap_time_*1000)){ |
yootee | 0:1456b6f84c75 | 9 | now_time = nap.read_ms(); |
yootee | 0:1456b6f84c75 | 10 | } |
yootee | 0:1456b6f84c75 | 11 | prev_time = now_time; |
yootee | 6:e7f2335456c8 | 12 | if(prev_time > 18000000){ |
yootee | 6:e7f2335456c8 | 13 | now_time = 0; |
yootee | 6:e7f2335456c8 | 14 | prev_time = 0; |
yootee | 6:e7f2335456c8 | 15 | nap.reset(); |
yootee | 6:e7f2335456c8 | 16 | nap.start(); |
yootee | 6:e7f2335456c8 | 17 | } |
yootee | 0:1456b6f84c75 | 18 | } |
yootee | 0:1456b6f84c75 | 19 | |
yootee | 0:1456b6f84c75 | 20 | void NAP::setNaptime(float nap_time){ |
yootee | 0:1456b6f84c75 | 21 | nap_time_ = nap_time; |
yootee | 0:1456b6f84c75 | 22 | } |
yootee | 0:1456b6f84c75 | 23 | |
yootee | 0:1456b6f84c75 | 24 | void NAP::restart(){ |
yootee | 0:1456b6f84c75 | 25 | nap.reset(); |
yootee | 0:1456b6f84c75 | 26 | nap.start(); |
yootee | 0:1456b6f84c75 | 27 | now_time = 0; |
yootee | 0:1456b6f84c75 | 28 | prev_time = 0; |
yootee | 0:1456b6f84c75 | 29 | } |