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

Dependencies:   mbed Servo ros_lib_melodic ULN2003_StepperDriver Async_4pin_Stepper

Committer:
krogedal
Date:
Thu May 27 18:36:23 2021 +0000
Revision:
0:441289ea4e29
Child:
3:4b6080e86761
Set up basic motor control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krogedal 0:441289ea4e29 1 #ifndef KARBOT_MOTOR_CONTROL_H
krogedal 0:441289ea4e29 2 #define KARBOT_MOTOR_CONTROL_H
krogedal 0:441289ea4e29 3
krogedal 0:441289ea4e29 4 /* Karbot motor control class
krogedal 0:441289ea4e29 5 * Written by Simon Krogedal
krogedal 0:441289ea4e29 6 * 27/05/21
krogedal 0:441289ea4e29 7 * Team 9 4th Year project
krogedal 0:441289ea4e29 8 *
krogedal 0:441289ea4e29 9 * for NUCLEO-F401RE
krogedal 0:441289ea4e29 10 *
krogedal 0:441289ea4e29 11 */
krogedal 0:441289ea4e29 12
krogedal 0:441289ea4e29 13 #include "mbed.h"
krogedal 0:441289ea4e29 14 #include "encoder.h"
krogedal 0:441289ea4e29 15 #include "motor.h"
krogedal 0:441289ea4e29 16
krogedal 0:441289ea4e29 17 class MotorControl : public encoder { //controls the speed of an individual motor, helping the system keep symmetric with asymmetric components
krogedal 0:441289ea4e29 18 private:
krogedal 0:441289ea4e29 19 motor* mot;
krogedal 0:441289ea4e29 20
krogedal 0:441289ea4e29 21 double Kp, Ki, r_speed, r_clicks, max_speed, output, acc_err;
krogedal 0:441289ea4e29 22 bool dir, max_out; //driving direction and error flag
krogedal 0:441289ea4e29 23
krogedal 0:441289ea4e29 24 double getError(void);
krogedal 0:441289ea4e29 25
krogedal 0:441289ea4e29 26 void algorithm(void);
krogedal 0:441289ea4e29 27
krogedal 0:441289ea4e29 28 public:
krogedal 0:441289ea4e29 29 MotorControl(PinName a, PinName b, PinName i, int r, bool c, double p, motor* m, double ms, double kp, double ki, double ec);
krogedal 0:441289ea4e29 30
krogedal 0:441289ea4e29 31 void setSpeed(double s);
krogedal 0:441289ea4e29 32 void drive(void);
krogedal 0:441289ea4e29 33
krogedal 0:441289ea4e29 34 void stop(void);
krogedal 0:441289ea4e29 35
krogedal 0:441289ea4e29 36 void driveManual(void);
krogedal 0:441289ea4e29 37
krogedal 0:441289ea4e29 38 void samplecall(void);
krogedal 0:441289ea4e29 39
krogedal 0:441289ea4e29 40 void setK(double k);
krogedal 0:441289ea4e29 41
krogedal 0:441289ea4e29 42 void start(void); //this function is overridden to avoid bugs
krogedal 0:441289ea4e29 43 // double getError(void);
krogedal 0:441289ea4e29 44 double getOutput(void);
krogedal 0:441289ea4e29 45 bool checkFlag(void);
krogedal 0:441289ea4e29 46 };
krogedal 0:441289ea4e29 47
krogedal 0:441289ea4e29 48 #endif