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@0:1a972ed770da, 2020-03-09 (annotated)
- Committer:
- oehlemar
- Date:
- Mon Mar 09 16:23:04 2020 +0000
- Revision:
- 0:1a972ed770da
LAB2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oehlemar | 0:1a972ed770da | 1 | /* |
oehlemar | 0:1a972ed770da | 2 | * Controller.h |
oehlemar | 0:1a972ed770da | 3 | * Copyright (c) 2020, ZHAW |
oehlemar | 0:1a972ed770da | 4 | * All rights reserved. |
oehlemar | 0:1a972ed770da | 5 | */ |
oehlemar | 0:1a972ed770da | 6 | |
oehlemar | 0:1a972ed770da | 7 | #ifndef CONTROLLER_H_ |
oehlemar | 0:1a972ed770da | 8 | #define CONTROLLER_H_ |
oehlemar | 0:1a972ed770da | 9 | |
oehlemar | 0:1a972ed770da | 10 | #include <cstdlib> |
oehlemar | 0:1a972ed770da | 11 | #include <mbed.h> |
oehlemar | 0:1a972ed770da | 12 | #include "EncoderCounter.h" |
oehlemar | 0:1a972ed770da | 13 | #include "Motion.h" |
oehlemar | 0:1a972ed770da | 14 | #include "LowpassFilter.h" |
oehlemar | 0:1a972ed770da | 15 | |
oehlemar | 0:1a972ed770da | 16 | /** |
oehlemar | 0:1a972ed770da | 17 | * This class implements a controller that regulates the |
oehlemar | 0:1a972ed770da | 18 | * speed of the two motors of the ROME2 mobile robot. |
oehlemar | 0:1a972ed770da | 19 | */ |
oehlemar | 0:1a972ed770da | 20 | class Controller { |
oehlemar | 0:1a972ed770da | 21 | |
oehlemar | 0:1a972ed770da | 22 | public: |
oehlemar | 0:1a972ed770da | 23 | |
oehlemar | 0:1a972ed770da | 24 | Controller(PwmOut& pwmLeft, PwmOut& pwmRight, EncoderCounter& counterLeft, EncoderCounter& counterRight); |
oehlemar | 0:1a972ed770da | 25 | virtual ~Controller(); |
oehlemar | 0:1a972ed770da | 26 | void setTranslationalVelocity(float velocity); |
oehlemar | 0:1a972ed770da | 27 | void setRotationalVelocity(float velocity); |
oehlemar | 0:1a972ed770da | 28 | float getActualTranslationalVelocity(); |
oehlemar | 0:1a972ed770da | 29 | float getActualRotationalVelocity(); |
oehlemar | 0:1a972ed770da | 30 | void setDesiredSpeedLeft(float desiredSpeedLeft); |
oehlemar | 0:1a972ed770da | 31 | void setDesiredSpeedRight(float desiredSpeedRight); |
oehlemar | 0:1a972ed770da | 32 | float getActualSpeedLeft(); |
oehlemar | 0:1a972ed770da | 33 | float getActualSpeedRight(); |
oehlemar | 0:1a972ed770da | 34 | |
oehlemar | 0:1a972ed770da | 35 | private: |
oehlemar | 0:1a972ed770da | 36 | |
oehlemar | 0:1a972ed770da | 37 | static const float PERIOD; |
oehlemar | 0:1a972ed770da | 38 | static const float PI; |
oehlemar | 0:1a972ed770da | 39 | static const float WHEEL_DISTANCE; |
oehlemar | 0:1a972ed770da | 40 | static const float WHEEL_RADIUS; |
oehlemar | 0:1a972ed770da | 41 | static const float COUNTS_PER_TURN; |
oehlemar | 0:1a972ed770da | 42 | static const float LOWPASS_FILTER_FREQUENCY; |
oehlemar | 0:1a972ed770da | 43 | static const float KN; |
oehlemar | 0:1a972ed770da | 44 | static const float KP; |
oehlemar | 0:1a972ed770da | 45 | static const float MAX_VOLTAGE; |
oehlemar | 0:1a972ed770da | 46 | static const float MIN_DUTY_CYCLE; |
oehlemar | 0:1a972ed770da | 47 | static const float MAX_DUTY_CYCLE; |
oehlemar | 0:1a972ed770da | 48 | |
oehlemar | 0:1a972ed770da | 49 | PwmOut& pwmLeft; |
oehlemar | 0:1a972ed770da | 50 | PwmOut& pwmRight; |
oehlemar | 0:1a972ed770da | 51 | EncoderCounter& counterLeft; |
oehlemar | 0:1a972ed770da | 52 | EncoderCounter& counterRight; |
oehlemar | 0:1a972ed770da | 53 | Motion translationalMotion; |
oehlemar | 0:1a972ed770da | 54 | Motion rotationalMotion; |
oehlemar | 0:1a972ed770da | 55 | float translationalVelocity; |
oehlemar | 0:1a972ed770da | 56 | float rotationalVelocity; |
oehlemar | 0:1a972ed770da | 57 | float actualTranslationalVelocity; |
oehlemar | 0:1a972ed770da | 58 | float actualRotationalVelocity; |
oehlemar | 0:1a972ed770da | 59 | short previousValueCounterLeft; |
oehlemar | 0:1a972ed770da | 60 | short previousValueCounterRight; |
oehlemar | 0:1a972ed770da | 61 | LowpassFilter speedLeftFilter; |
oehlemar | 0:1a972ed770da | 62 | LowpassFilter speedRightFilter; |
oehlemar | 0:1a972ed770da | 63 | float desiredSpeedLeft; |
oehlemar | 0:1a972ed770da | 64 | float desiredSpeedRight; |
oehlemar | 0:1a972ed770da | 65 | float actualSpeedLeft; |
oehlemar | 0:1a972ed770da | 66 | float actualSpeedRight; |
oehlemar | 0:1a972ed770da | 67 | Ticker ticker; |
oehlemar | 0:1a972ed770da | 68 | |
oehlemar | 0:1a972ed770da | 69 | void run(); |
oehlemar | 0:1a972ed770da | 70 | }; |
oehlemar | 0:1a972ed770da | 71 | |
oehlemar | 0:1a972ed770da | 72 | #endif /* CONTROLLER_H_ */ |
oehlemar | 0:1a972ed770da | 73 |