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.
Controller.h@3:a292bdaf03f6, 2021-03-16 (annotated)
- Committer:
- boro
- Date:
- Tue Mar 16 17:28:04 2021 +0100
- Revision:
- 3:a292bdaf03f6
- Parent:
- 0:5d4d21d56334
controller updated
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| boro | 0:5d4d21d56334 | 1 | #ifndef CONTROLLER_H_ |
| boro | 0:5d4d21d56334 | 2 | #define CONTROLLER_H_ |
| boro | 0:5d4d21d56334 | 3 | #include <cstdlib> |
| boro | 0:5d4d21d56334 | 4 | #include <mbed.h> |
| boro | 0:5d4d21d56334 | 5 | #include "EncoderCounter.h" |
| boro | 0:5d4d21d56334 | 6 | #include "LowpassFilter.h" |
| boro | 0:5d4d21d56334 | 7 | #include "ThreadFlag.h" |
| boro | 0:5d4d21d56334 | 8 | |
| boro | 0:5d4d21d56334 | 9 | class Controller |
| boro | 0:5d4d21d56334 | 10 | { |
| boro | 0:5d4d21d56334 | 11 | |
| boro | 0:5d4d21d56334 | 12 | public: |
| boro | 0:5d4d21d56334 | 13 | |
| boro | 0:5d4d21d56334 | 14 | Controller(PwmOut& pwmLeft, PwmOut& pwmRight, |
| boro | 0:5d4d21d56334 | 15 | EncoderCounter& counterLeft, EncoderCounter& counterRight); |
| boro | 0:5d4d21d56334 | 16 | |
| boro | 0:5d4d21d56334 | 17 | virtual ~Controller(); |
| boro | 0:5d4d21d56334 | 18 | void setDesiredSpeedLeft(float desiredSpeedLeft); |
| boro | 0:5d4d21d56334 | 19 | void setDesiredSpeedRight(float desiredSpeedRight); |
| boro | 0:5d4d21d56334 | 20 | float getSpeedLeft(); |
| boro | 0:5d4d21d56334 | 21 | float getSpeedRight(); |
| boro | 0:5d4d21d56334 | 22 | |
| boro | 0:5d4d21d56334 | 23 | private: |
| boro | 0:5d4d21d56334 | 24 | |
| boro | 3:a292bdaf03f6 | 25 | static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes] |
| boro | 0:5d4d21d56334 | 26 | static const float PERIOD; |
| boro | 0:5d4d21d56334 | 27 | static const float COUNTS_PER_TURN; |
| boro | 0:5d4d21d56334 | 28 | static const float LOWPASS_FILTER_FREQUENCY; |
| boro | 0:5d4d21d56334 | 29 | static const float KN; |
| boro | 0:5d4d21d56334 | 30 | static const float KP; |
| boro | 0:5d4d21d56334 | 31 | static const float MAX_VOLTAGE; |
| boro | 0:5d4d21d56334 | 32 | static const float MIN_DUTY_CYCLE; |
| boro | 0:5d4d21d56334 | 33 | static const float MAX_DUTY_CYCLE; |
| boro | 0:5d4d21d56334 | 34 | |
| boro | 0:5d4d21d56334 | 35 | PwmOut& pwmLeft; |
| boro | 0:5d4d21d56334 | 36 | PwmOut& pwmRight; |
| boro | 0:5d4d21d56334 | 37 | EncoderCounter& counterLeft; |
| boro | 0:5d4d21d56334 | 38 | EncoderCounter& counterRight; |
| boro | 0:5d4d21d56334 | 39 | short previousValueCounterLeft; |
| boro | 0:5d4d21d56334 | 40 | short previousValueCounterRight; |
| boro | 0:5d4d21d56334 | 41 | LowpassFilter speedLeftFilter; |
| boro | 0:5d4d21d56334 | 42 | LowpassFilter speedRightFilter; |
| boro | 0:5d4d21d56334 | 43 | float desiredSpeedLeft; |
| boro | 0:5d4d21d56334 | 44 | float desiredSpeedRight; |
| boro | 0:5d4d21d56334 | 45 | float actualSpeedLeft; |
| boro | 0:5d4d21d56334 | 46 | float actualSpeedRight; |
| boro | 0:5d4d21d56334 | 47 | float actualAngleLeft; |
| boro | 0:5d4d21d56334 | 48 | float actualAngleRight; |
| boro | 0:5d4d21d56334 | 49 | |
| boro | 0:5d4d21d56334 | 50 | ThreadFlag threadFlag; |
| boro | 0:5d4d21d56334 | 51 | Thread thread; |
| boro | 0:5d4d21d56334 | 52 | Ticker ticker; |
| boro | 0:5d4d21d56334 | 53 | |
| boro | 0:5d4d21d56334 | 54 | void sendThreadFlag(); |
| boro | 0:5d4d21d56334 | 55 | void run(); |
| boro | 0:5d4d21d56334 | 56 | |
| boro | 0:5d4d21d56334 | 57 | }; |
| boro | 0:5d4d21d56334 | 58 | |
| boro | 0:5d4d21d56334 | 59 | #endif /* CONTROLLER_H_ */ |