PM2_Lib

Dependencies:   LSM9DS1 RangeFinder FastPWM

SpeedController.h

Committer:
pmic
Date:
2021-04-07
Revision:
6:41dd03654c44
Parent:
5:6cd242a61e4c
Child:
10:fe74e8909d3f

File content as of revision 6:41dd03654c44:

#ifndef SpeedController_H_
#define SpeedController_H_
#include <cstdlib>
#include <mbed.h>
#include "EncoderCounter.h"
#include "LowpassFilter.h"
#include "ThreadFlag.h"
#include "FastPWM.h"

class SpeedController
{
public:

    SpeedController(float counts_per_turn, float kn, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter);
    SpeedController(float counts_per_turn, float kn, float kp, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter);

    virtual ~SpeedController();

    void     setDesiredSpeedRPM(float desiredSpeed);
    float    getSpeedRPM();
    void     setDesiredSpeedRPS(float desiredSpeed);
    float    getSpeedRPS();

private:

    static const float TS;
    static const float LOWPASS_FILTER_FREQUENCY;
    static const float MIN_DUTY_CYCLE;
    static const float MAX_DUTY_CYCLE;

    float counts_per_turn;
    float kn;
    float kp;
    float max_voltage;

    FastPWM&           pwm;
    EncoderCounter&    encoderCounter;
    short              previousValueCounter;
    LowpassFilter      speedFilter;
    float              desiredSpeed;
    float              actualSpeed;
    // float              actualAngle;

    ThreadFlag         threadFlag;
    Thread             thread;
    Ticker             ticker;

    void               run();
    void               sendThreadFlag();
};

#endif /* SpeedController_H_ */