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@10:836e701d00a6, 2018-04-26 (annotated)
- Committer:
- MikeGray92
- Date:
- Thu Apr 26 18:33:11 2018 +0000
- Revision:
- 10:836e701d00a6
- Parent:
- 6:2ffa254e8f6e
Speed and Position controlled lift and gimbal
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 | |
| MikeGray92 | 6:2ffa254e8f6e | 4 | //Stall Checking Interrupt |
| MikeGray92 | 1:1ac7d472cfa2 | 5 | void hallInterrupt(){ |
| MikeGray92 | 1:1ac7d472cfa2 | 6 | if(prevPosition == currentPosition){ |
| MikeGray92 | 4:89ebfa37663b | 7 | stallcount++; |
| MikeGray92 | 1:1ac7d472cfa2 | 8 | } |
| MikeGray92 | 4:89ebfa37663b | 9 | else if(liftSpeed.read() > 0){ |
| MikeGray92 | 1:1ac7d472cfa2 | 10 | prevPosition = currentPosition; |
| MikeGray92 | 4:89ebfa37663b | 11 | stallcount = 0; |
| MikeGray92 | 1:1ac7d472cfa2 | 12 | } |
| MikeGray92 | 1:1ac7d472cfa2 | 13 | } |
| MikeGray92 | 2:0537a8007a39 | 14 | |
| MikeGray92 | 10:836e701d00a6 | 15 | //E-Stop Interrupt |
| MikeGray92 | 10:836e701d00a6 | 16 | void eStopOn(){ |
| MikeGray92 | 10:836e701d00a6 | 17 | eStopFlag = 1; |
| MikeGray92 | 10:836e701d00a6 | 18 | hallInt.detach(); |
| MikeGray92 | 10:836e701d00a6 | 19 | } |
| MikeGray92 | 10:836e701d00a6 | 20 | void eStopOff(){ |
| MikeGray92 | 10:836e701d00a6 | 21 | eStopFlag = 0; |
| MikeGray92 | 10:836e701d00a6 | 22 | hallInt.attach(&hallInterrupt, 0.03); |
| MikeGray92 | 10:836e701d00a6 | 23 | } |
| MikeGray92 | 10:836e701d00a6 | 24 | |
| MikeGray92 | 2:0537a8007a39 | 25 | //External Interrupt Counter |
| MikeGray92 | 2:0537a8007a39 | 26 | class Hall_Counter_1 { |
| MikeGray92 | 2:0537a8007a39 | 27 | public: |
| MikeGray92 | 2:0537a8007a39 | 28 | Hall_Counter_1(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter |
| MikeGray92 | 2:0537a8007a39 | 29 | _interrupt.rise(this, &Hall_Counter_1::increment); // attach increment function of this counter instance |
| MikeGray92 | 2:0537a8007a39 | 30 | } |
| MikeGray92 | 2:0537a8007a39 | 31 | void increment() { |
| MikeGray92 | 2:0537a8007a39 | 32 | if(filter_hall1.read_ms() > 5){ |
| MikeGray92 | 2:0537a8007a39 | 33 | if(liftDirection.read() == LIFTUP){ |
| MikeGray92 | 2:0537a8007a39 | 34 | currentPosition++; |
| MikeGray92 | 2:0537a8007a39 | 35 | } |
| MikeGray92 | 2:0537a8007a39 | 36 | else{ |
| MikeGray92 | 2:0537a8007a39 | 37 | currentPosition--; |
| MikeGray92 | 2:0537a8007a39 | 38 | } |
| MikeGray92 | 2:0537a8007a39 | 39 | filter_hall1.reset(); |
| MikeGray92 | 2:0537a8007a39 | 40 | } |
| MikeGray92 | 2:0537a8007a39 | 41 | } |
| MikeGray92 | 2:0537a8007a39 | 42 | |
| MikeGray92 | 2:0537a8007a39 | 43 | private: |
| MikeGray92 | 2:0537a8007a39 | 44 | InterruptIn _interrupt; |
| MikeGray92 | 2:0537a8007a39 | 45 | }; |
| MikeGray92 | 2:0537a8007a39 | 46 | |
| MikeGray92 | 2:0537a8007a39 | 47 | Hall_Counter_1 hall_Counter_1(PC_7); |