ROME2 Robot Firmware

Committer:
boro
Date:
Mon Mar 16 13:12:31 2020 +0000
Revision:
0:4beb2ea291ec
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boro 0:4beb2ea291ec 1 /*
boro 0:4beb2ea291ec 2 * Controller.h
boro 0:4beb2ea291ec 3 * Copyright (c) 2018, ZHAW
boro 0:4beb2ea291ec 4 * All rights reserved.
boro 0:4beb2ea291ec 5 */
boro 0:4beb2ea291ec 6
boro 0:4beb2ea291ec 7 #ifndef CONTROLLER_H_
boro 0:4beb2ea291ec 8 #define CONTROLLER_H_
boro 0:4beb2ea291ec 9
boro 0:4beb2ea291ec 10 #include <cstdlib>
boro 0:4beb2ea291ec 11 #include <mbed.h>
boro 0:4beb2ea291ec 12 #include "EncoderCounter.h"
boro 0:4beb2ea291ec 13 #include "Motion.h"
boro 0:4beb2ea291ec 14 #include "LowpassFilter.h"
boro 0:4beb2ea291ec 15 #include "Signal.h"
boro 0:4beb2ea291ec 16
boro 0:4beb2ea291ec 17 /**
boro 0:4beb2ea291ec 18 * This class implements the coordinate transformation, speed control and
boro 0:4beb2ea291ec 19 * the position estimation of a mobile robot with differential drive.
boro 0:4beb2ea291ec 20 */
boro 0:4beb2ea291ec 21 class Controller {
boro 0:4beb2ea291ec 22
boro 0:4beb2ea291ec 23 public:
boro 0:4beb2ea291ec 24
boro 0:4beb2ea291ec 25 Controller(PwmOut& pwmLeft, PwmOut& pwmRight, EncoderCounter& counterLeft, EncoderCounter& counterRight);
boro 0:4beb2ea291ec 26 virtual ~Controller();
boro 0:4beb2ea291ec 27 void setTranslationalVelocity(float velocity);
boro 0:4beb2ea291ec 28 void setRotationalVelocity(float velocity);
boro 0:4beb2ea291ec 29 float getActualTranslationalVelocity();
boro 0:4beb2ea291ec 30 float getActualRotationalVelocity();
boro 0:4beb2ea291ec 31 void setX(float x);
boro 0:4beb2ea291ec 32 float getX();
boro 0:4beb2ea291ec 33 void setY(float y);
boro 0:4beb2ea291ec 34 float getY();
boro 0:4beb2ea291ec 35 void setAlpha(float alpha);
boro 0:4beb2ea291ec 36 float getAlpha();
boro 0:4beb2ea291ec 37 float getangleRight();
boro 0:4beb2ea291ec 38 float getangleLeft();
boro 0:4beb2ea291ec 39 void startMeasure();
boro 0:4beb2ea291ec 40
boro 0:4beb2ea291ec 41 private:
boro 0:4beb2ea291ec 42
boro 0:4beb2ea291ec 43 static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes]
boro 0:4beb2ea291ec 44 static const float PERIOD;
boro 0:4beb2ea291ec 45 static const float PI;
boro 0:4beb2ea291ec 46 static const float WHEEL_DISTANCE;
boro 0:4beb2ea291ec 47 static const float WHEEL_RADIUS;
boro 0:4beb2ea291ec 48 static const float COUNTS_PER_TURN;
boro 0:4beb2ea291ec 49 static const float LOWPASS_FILTER_FREQUENCY;
boro 0:4beb2ea291ec 50 static const float KN;
boro 0:4beb2ea291ec 51 static const float KP;
boro 0:4beb2ea291ec 52 static const float MAX_VOLTAGE;
boro 0:4beb2ea291ec 53 static const float MIN_DUTY_CYCLE;
boro 0:4beb2ea291ec 54 static const float MAX_DUTY_CYCLE;
boro 0:4beb2ea291ec 55
boro 0:4beb2ea291ec 56 PwmOut& pwmLeft;
boro 0:4beb2ea291ec 57 PwmOut& pwmRight;
boro 0:4beb2ea291ec 58 EncoderCounter& counterLeft;
boro 0:4beb2ea291ec 59 EncoderCounter& counterRight;
boro 0:4beb2ea291ec 60 Motion translationalMotion;
boro 0:4beb2ea291ec 61 Motion rotationalMotion;
boro 0:4beb2ea291ec 62 float translationalVelocity;
boro 0:4beb2ea291ec 63 float rotationalVelocity;
boro 0:4beb2ea291ec 64 float actualTranslationalVelocity;
boro 0:4beb2ea291ec 65 float actualRotationalVelocity;
boro 0:4beb2ea291ec 66 short previousValueCounterLeft;
boro 0:4beb2ea291ec 67 short previousValueCounterRight;
boro 0:4beb2ea291ec 68 LowpassFilter speedLeftFilter;
boro 0:4beb2ea291ec 69 LowpassFilter speedRightFilter;
boro 0:4beb2ea291ec 70 float desiredSpeedLeft;
boro 0:4beb2ea291ec 71 float desiredSpeedRight;
boro 0:4beb2ea291ec 72 float actualSpeedLeft;
boro 0:4beb2ea291ec 73 float actualSpeedRight;
boro 0:4beb2ea291ec 74 float actualAngleRight;
boro 0:4beb2ea291ec 75 float actualAngleLeft;
boro 0:4beb2ea291ec 76 float x;
boro 0:4beb2ea291ec 77 float y;
boro 0:4beb2ea291ec 78 float alpha;
boro 0:4beb2ea291ec 79 Signal signal;
boro 0:4beb2ea291ec 80 Thread thread;
boro 0:4beb2ea291ec 81 Ticker ticker;
boro 0:4beb2ea291ec 82 bool startMeasurement;
boro 0:4beb2ea291ec 83
boro 0:4beb2ea291ec 84 void sendSignal();
boro 0:4beb2ea291ec 85 void run();
boro 0:4beb2ea291ec 86 };
boro 0:4beb2ea291ec 87
boro 0:4beb2ea291ec 88 #endif /* CONTROLLER_H_ */
boro 0:4beb2ea291ec 89
boro 0:4beb2ea291ec 90