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