Control project for the Lift-arm. Works with ROS Melodic
Dependencies: mbed Servo ros_lib_melodic ULN2003_StepperDriver Async_4pin_Stepper
Diff: src/MotorControl.h
- Revision:
- 5:71c2f193a7f9
- Parent:
- 4:9edb248c6431
--- a/src/MotorControl.h Mon May 31 16:47:02 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -#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" - -/* This class controls the speed of an individual motor, helping the system keep - * symmetric with asymmetric components. It is based on the encoder class - * and contains a pointer to a motor object. With two of these the motion - * controller can drive the robot to the desired points. - */ -class MotorControl : public encoder { - private: - motor* mot; // motor object - - double Kp, // Proportional gain - Ti, // Integral gain time - r_speed, // Speed set point - r_clicks, // Same but in the "encoder language" - max_speed, // The max speed of the motor (not used) - output, // PWM output duty cycle - prev_error; // Previous error, used for intergral control - - bool dir, // Drivign direction (not used) - max_out; // Flag triggered when output is saturated (not used) - - double getError(void); // Calculate current error - - void algorithm(void); // Control algorithm - - public: - // Constructor takes encoder pins and constants, and a motor object and contorller gains - MotorControl(PinName a, PinName b, PinName i, int r, bool c, double p, motor* m, double ms, double kp, double ti, double ec); - - void setSpeed(double s); // Set the speed of the wheel - void drive(void); // Drive at set speet - void stop(void); // Stop motor - void driveManual(void); // Drive at set speed in open loop - void samplecall(void); // Sample encoder and update read speed value - void setK(double k); // Set gain (used for Z-N tuning - void start(void); // This function is overridden to avoid bugs - double getOutput(void); // Returns current duty cycle - bool checkFlag(void); // Check whether max out flag is set -}; - -#endif \ No newline at end of file