ROME2 Robot Firmware

Controller.h

Committer:
boro
Date:
2020-03-16
Revision:
0:4beb2ea291ec

File content as of revision 0:4beb2ea291ec:

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

#ifndef CONTROLLER_H_
#define CONTROLLER_H_

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

/**
 * This class implements the coordinate transformation, speed control and
 * the position estimation of a mobile robot with differential drive.
 */
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        setX(float x);
        float       getX();
        void        setY(float y);
        float       getY();
        void        setAlpha(float alpha);
        float       getAlpha();
        float       getangleRight();
        float       getangleLeft();
        void        startMeasure();
        
    private:
        
        static const uint32_t   STACK_SIZE = 4096;  // stack size of thread, given in [bytes]
        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               actualAngleRight;
        float               actualAngleLeft;
        float               x;
        float               y;
        float               alpha;
        Signal              signal;
        Thread              thread;
        Ticker              ticker;
        bool                startMeasurement;
        
        void        sendSignal();
        void                run();
};

#endif /* CONTROLLER_H_ */