ROME2 Lab3

Controller.h

Committer:
oehlemar
Date:
2020-03-25
Revision:
2:fc9e2aebf9d5
Parent:
0:6a4d3264c067

File content as of revision 2:fc9e2aebf9d5:

/*
 * Controller.h
 * Copyright (c) 2020, ZHAW
 * All rights reserved.
 */

#ifndef CONTROLLER_H_
#define CONTROLLER_H_

#include <cstdlib>
#include <mbed.h>
#include "EncoderCounter.h"
#include "Motion.h"
#include "LowpassFilter.h"

/**
 * This class implements a controller that regulates the
 * speed of the two motors of the ROME2 mobile robot.
 */
class Controller {
    
    public:
        
                Controller(PwmOut& pwmLeft, PwmOut& pwmRight, EncoderCounter& counterLeft, EncoderCounter& counterRight);
        virtual ~Controller();
        void    setTranslationalVelocity(float velocity);
        void    setRotationalVelocity(float velocity);
        float   getActualTranslationalVelocity();
        float   getActualRotationalVelocity();
        void    setDesiredSpeedLeft(float desiredSpeedLeft);
        void    setDesiredSpeedRight(float desiredSpeedRight);
        float   getActualSpeedLeft();
        float   getActualSpeedRight();
        void    setX(float x);
        float   getX();
        void    setY(float y);
        float   getY();
        void    setAlpha(float alpha);
        float   getAlpha();
        
  private:
        
        static const float  PERIOD;
        static const float  PI;
        static const float  WHEEL_DISTANCE;
        static const float  WHEEL_RADIUS;
        static const float  COUNTS_PER_TURN;
        static const float  LOWPASS_FILTER_FREQUENCY;
        static const float  KN;
        static const float  KP;
        static const float  MAX_VOLTAGE;
        static const float  MIN_DUTY_CYCLE;
        static const float  MAX_DUTY_CYCLE;

        PwmOut&             pwmLeft;
        PwmOut&             pwmRight;
        EncoderCounter&     counterLeft;
        EncoderCounter&     counterRight;
        Motion              translationalMotion;
        Motion              rotationalMotion;
        float               translationalVelocity;
        float               rotationalVelocity;
        float               actualTranslationalVelocity;
        float               actualRotationalVelocity;
        short               previousValueCounterLeft;
        short               previousValueCounterRight;
        LowpassFilter       speedLeftFilter;
        LowpassFilter       speedRightFilter;
        float               desiredSpeedLeft;
        float               desiredSpeedRight;
        float               actualSpeedLeft;
        float               actualSpeedRight;
        float               x;
        float               y;
        float               alpha;
        Ticker              ticker;
        
        void    run();
};

#endif /* CONTROLLER_H_ */