Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
motor.h
00001 #ifndef MOTOR_H 00002 #define MOTOR_H 00003 #include "mbed.h" 00004 #include "PwmOut.h" 00005 00006 class Motor { 00007 public: 00008 //Motor() = default; 00009 Motor(Serial *pc, PinName pwm, PinName dir1, PinName dir2, PinName fault, PinName encA, PinName encB); 00010 //Motor (const Motor& ) = default; 00011 00012 uint8_t pid_on; 00013 int16_t encTicks; 00014 volatile int16_t speed; 00015 float pgain, igain, dgain; 00016 00017 /* 00018 * Run this to update speed 00019 */ 00020 void pid2(int16_t encTicks); 00021 int16_t getSpeed(); 00022 void setSpeed (int16_t speed); 00023 void getPIDGain(char *gain); 00024 void forward(float pwm); 00025 void backward(float pwm); 00026 void pidTick(); 00027 private: 00028 static const unsigned int PWM_PERIOD_US = 2500; 00029 00030 Serial *_pc; 00031 PwmOut _pwm; 00032 DigitalOut _dir1; 00033 DigitalOut _dir2; 00034 DigitalIn _fault; 00035 InterruptIn _encA; 00036 InterruptIn _encB; 00037 00038 volatile int16_t ticks; 00039 volatile uint8_t encNow; 00040 volatile uint8_t encLast; 00041 void encTick(); 00042 00043 union doublebyte { 00044 unsigned int value; 00045 unsigned char bytes[2]; 00046 }; 00047 00048 uint8_t enc_dir; 00049 uint8_t enc_last; 00050 uint8_t enc_now; 00051 00052 uint8_t dir; 00053 00054 int16_t currentPWM; 00055 uint8_t motor_polarity; 00056 00057 float pidSpeed; 00058 float pidError; 00059 float pidErrorPrev; 00060 float pidSetpoint; 00061 00062 float i; 00063 00064 /* 00065 union doublebyte wcount; 00066 union doublebyte decoder_count; 00067 00068 uint8_t dir; 00069 */ 00070 00071 uint8_t fail_counter; 00072 uint8_t send_speed; 00073 uint8_t failsafe; 00074 uint8_t leds_on; 00075 00076 int16_t sp, sp_pid, der; 00077 int16_t intgrl, prop; 00078 //int16_t count, speed; 00079 int16_t csum; 00080 int16_t err, err_prev; 00081 00082 int16_t pwm, pwm_min, pwmmin; 00083 uint8_t update_pid; 00084 00085 uint16_t stall_counter; 00086 uint16_t stallCount; 00087 uint16_t prevStallCount; 00088 uint16_t stallWarningLimit; 00089 uint16_t stallErrorLimit; 00090 uint8_t stallLevel; 00091 uint8_t stallChanged; 00092 //int16_t currentPWM; 00093 00094 uint8_t counter; 00095 00096 00097 void reset_pid(); 00098 00099 }; 00100 #endif //MOTOR_H
Generated on Wed Jul 20 2022 23:15:26 by
1.7.2