Control project for the Lift-arm. Works with ROS Melodic

Dependencies:   mbed Servo ros_lib_melodic ULN2003_StepperDriver Async_4pin_Stepper

src/MotorControl.h

Committer:
krogedal
Date:
2021-05-27
Revision:
0:441289ea4e29
Child:
3:4b6080e86761

File content as of revision 0:441289ea4e29:

#ifndef KARBOT_MOTOR_CONTROL_H
#define KARBOT_MOTOR_CONTROL_H

/* Karbot motor control class
 * Written by Simon Krogedal
 * 27/05/21
 * Team 9 4th Year project
 * 
 * for NUCLEO-F401RE
 * 
 */
 
 #include "mbed.h"
 #include "encoder.h"
 #include "motor.h"
 
class MotorControl : public encoder {                                   //controls the speed of an individual motor, helping the system keep symmetric with asymmetric components
    private:
        motor*      mot;
        
        double      Kp, Ki, r_speed, r_clicks, max_speed, output, acc_err;
        bool        dir, max_out;                                       //driving direction and error flag
        
        double getError(void);
        
        void algorithm(void);
    
    public:
        MotorControl(PinName a, PinName b, PinName i, int r, bool c, double p, motor* m, double ms, double kp, double ki, double ec);
        
        void setSpeed(double s);
        void drive(void);
        
        void stop(void);
        
        void driveManual(void);
        
        void samplecall(void);
        
        void setK(double k);

        void start(void);       //this function is overridden to avoid bugs
//      double getError(void);
        double getOutput(void);
        bool checkFlag(void);
};

#endif