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@2:f381fc3a8eaf, 2020-02-26 (annotated)
- Committer:
- wengefa1
- Date:
- Wed Feb 26 14:20:16 2020 +0000
- Revision:
- 2:f381fc3a8eaf
Motor Controller added
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wengefa1 | 2:f381fc3a8eaf | 1 | /* |
| wengefa1 | 2:f381fc3a8eaf | 2 | * Controller.h |
| wengefa1 | 2:f381fc3a8eaf | 3 | * Copyright (c) 2020, ZHAW |
| wengefa1 | 2:f381fc3a8eaf | 4 | * All rights reserved. |
| wengefa1 | 2:f381fc3a8eaf | 5 | */ |
| wengefa1 | 2:f381fc3a8eaf | 6 | |
| wengefa1 | 2:f381fc3a8eaf | 7 | #ifndef CONTROLLER_H_ |
| wengefa1 | 2:f381fc3a8eaf | 8 | #define CONTROLLER_H_ |
| wengefa1 | 2:f381fc3a8eaf | 9 | |
| wengefa1 | 2:f381fc3a8eaf | 10 | #include <cstdlib> |
| wengefa1 | 2:f381fc3a8eaf | 11 | #include <mbed.h> |
| wengefa1 | 2:f381fc3a8eaf | 12 | #include "EncoderCounter.h" |
| wengefa1 | 2:f381fc3a8eaf | 13 | #include "LowpassFilter.h" |
| wengefa1 | 2:f381fc3a8eaf | 14 | |
| wengefa1 | 2:f381fc3a8eaf | 15 | /** |
| wengefa1 | 2:f381fc3a8eaf | 16 | * This class implements a controller that regulates the |
| wengefa1 | 2:f381fc3a8eaf | 17 | * speed of the two motors of the ROME2 mobile robot. |
| wengefa1 | 2:f381fc3a8eaf | 18 | */ |
| wengefa1 | 2:f381fc3a8eaf | 19 | class Controller { |
| wengefa1 | 2:f381fc3a8eaf | 20 | |
| wengefa1 | 2:f381fc3a8eaf | 21 | public: |
| wengefa1 | 2:f381fc3a8eaf | 22 | |
| wengefa1 | 2:f381fc3a8eaf | 23 | Controller(PwmOut& pwmLeft, PwmOut& pwmRight, EncoderCounter& counterLeft, EncoderCounter& counterRight); |
| wengefa1 | 2:f381fc3a8eaf | 24 | virtual ~Controller(); |
| wengefa1 | 2:f381fc3a8eaf | 25 | void setDesiredSpeedLeft(float desiredSpeedLeft); |
| wengefa1 | 2:f381fc3a8eaf | 26 | void setDesiredSpeedRight(float desiredSpeedRight); |
| wengefa1 | 2:f381fc3a8eaf | 27 | float getSpeedLeft(); |
| wengefa1 | 2:f381fc3a8eaf | 28 | float getSpeedRight(); |
| wengefa1 | 2:f381fc3a8eaf | 29 | float getDesSpeedLeft(); |
| wengefa1 | 2:f381fc3a8eaf | 30 | float getDesSpeedRight(); |
| wengefa1 | 2:f381fc3a8eaf | 31 | |
| wengefa1 | 2:f381fc3a8eaf | 32 | private: |
| wengefa1 | 2:f381fc3a8eaf | 33 | |
| wengefa1 | 2:f381fc3a8eaf | 34 | static const float PERIOD; |
| wengefa1 | 2:f381fc3a8eaf | 35 | static const float COUNTS_PER_TURN; |
| wengefa1 | 2:f381fc3a8eaf | 36 | static const float LOWPASS_FILTER_FREQUENCY; |
| wengefa1 | 2:f381fc3a8eaf | 37 | static const float KN; |
| wengefa1 | 2:f381fc3a8eaf | 38 | static const float KP; |
| wengefa1 | 2:f381fc3a8eaf | 39 | static const float MAX_VOLTAGE; |
| wengefa1 | 2:f381fc3a8eaf | 40 | static const float MIN_DUTY_CYCLE; |
| wengefa1 | 2:f381fc3a8eaf | 41 | static const float MAX_DUTY_CYCLE; |
| wengefa1 | 2:f381fc3a8eaf | 42 | |
| wengefa1 | 2:f381fc3a8eaf | 43 | PwmOut& pwmLeft; |
| wengefa1 | 2:f381fc3a8eaf | 44 | PwmOut& pwmRight; |
| wengefa1 | 2:f381fc3a8eaf | 45 | EncoderCounter& counterLeft; |
| wengefa1 | 2:f381fc3a8eaf | 46 | EncoderCounter& counterRight; |
| wengefa1 | 2:f381fc3a8eaf | 47 | short previousValueCounterLeft; |
| wengefa1 | 2:f381fc3a8eaf | 48 | short previousValueCounterRight; |
| wengefa1 | 2:f381fc3a8eaf | 49 | LowpassFilter speedLeftFilter; |
| wengefa1 | 2:f381fc3a8eaf | 50 | LowpassFilter speedRightFilter; |
| wengefa1 | 2:f381fc3a8eaf | 51 | float desiredSpeedLeft; |
| wengefa1 | 2:f381fc3a8eaf | 52 | float desiredSpeedRight; |
| wengefa1 | 2:f381fc3a8eaf | 53 | float actualSpeedLeft; |
| wengefa1 | 2:f381fc3a8eaf | 54 | float actualSpeedRight; |
| wengefa1 | 2:f381fc3a8eaf | 55 | Ticker ticker; |
| wengefa1 | 2:f381fc3a8eaf | 56 | |
| wengefa1 | 2:f381fc3a8eaf | 57 | void run(); |
| wengefa1 | 2:f381fc3a8eaf | 58 | }; |
| wengefa1 | 2:f381fc3a8eaf | 59 | |
| wengefa1 | 2:f381fc3a8eaf | 60 | #endif /* CONTROLLER_H_ */ |
| wengefa1 | 2:f381fc3a8eaf | 61 |