Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ros_lib_kinetic
interrupts.cpp@2:0537a8007a39, 2018-02-08 (annotated)
- Committer:
- MikeGray92
- Date:
- Thu Feb 08 22:23:40 2018 +0000
- Revision:
- 2:0537a8007a39
- Parent:
- 1:1ac7d472cfa2
- Child:
- 4:89ebfa37663b
Code ready to be tested with ROS. ; -Tested external interrupt positioning for the lift; -remove unnecessary flags and functions
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MikeGray92 | 2:0537a8007a39 | 1 | #include "mbed.h" |
| group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 2 | #include <definitions.h> |
| group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 3 | |
| group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 4 | |
| MikeGray92 | 2:0537a8007a39 | 5 | //Stall Check Interrupt |
| MikeGray92 | 1:1ac7d472cfa2 | 6 | void hallInterrupt(){ |
| MikeGray92 | 1:1ac7d472cfa2 | 7 | if(prevPosition == currentPosition){ |
| MikeGray92 | 1:1ac7d472cfa2 | 8 | stall = true; |
| MikeGray92 | 1:1ac7d472cfa2 | 9 | } |
| MikeGray92 | 1:1ac7d472cfa2 | 10 | else{ |
| MikeGray92 | 1:1ac7d472cfa2 | 11 | prevPosition = currentPosition; |
| MikeGray92 | 1:1ac7d472cfa2 | 12 | stall = false; |
| MikeGray92 | 1:1ac7d472cfa2 | 13 | } |
| MikeGray92 | 1:1ac7d472cfa2 | 14 | } |
| MikeGray92 | 2:0537a8007a39 | 15 | |
| MikeGray92 | 2:0537a8007a39 | 16 | //External Interrupt Counter |
| MikeGray92 | 2:0537a8007a39 | 17 | class Hall_Counter_1 { |
| MikeGray92 | 2:0537a8007a39 | 18 | public: |
| MikeGray92 | 2:0537a8007a39 | 19 | Hall_Counter_1(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter |
| MikeGray92 | 2:0537a8007a39 | 20 | _interrupt.rise(this, &Hall_Counter_1::increment); // attach increment function of this counter instance |
| MikeGray92 | 2:0537a8007a39 | 21 | } |
| MikeGray92 | 2:0537a8007a39 | 22 | void increment() { |
| MikeGray92 | 2:0537a8007a39 | 23 | if(filter_hall1.read_ms() > 5){ |
| MikeGray92 | 2:0537a8007a39 | 24 | if(liftDirection.read() == LIFTUP){ |
| MikeGray92 | 2:0537a8007a39 | 25 | currentPosition++; |
| MikeGray92 | 2:0537a8007a39 | 26 | } |
| MikeGray92 | 2:0537a8007a39 | 27 | else{ |
| MikeGray92 | 2:0537a8007a39 | 28 | currentPosition--; |
| MikeGray92 | 2:0537a8007a39 | 29 | } |
| MikeGray92 | 2:0537a8007a39 | 30 | filter_hall1.reset(); |
| MikeGray92 | 2:0537a8007a39 | 31 | } |
| MikeGray92 | 2:0537a8007a39 | 32 | } |
| MikeGray92 | 2:0537a8007a39 | 33 | |
| MikeGray92 | 2:0537a8007a39 | 34 | private: |
| MikeGray92 | 2:0537a8007a39 | 35 | InterruptIn _interrupt; |
| MikeGray92 | 2:0537a8007a39 | 36 | }; |
| MikeGray92 | 2:0537a8007a39 | 37 | |
| MikeGray92 | 2:0537a8007a39 | 38 | Hall_Counter_1 hall_Counter_1(PC_7); |