motors
Fork of motor by
Embed:
(wiki syntax)
Show/hide line numbers
motor.h
00001 #ifndef MOTOR_H 00002 #define MOTOR_H 00003 #include "mbed.h" 00004 #include "PwmOut.h" 00005 #include "USBSerial.h" 00006 00007 class Motor { 00008 public: 00009 Motor(); 00010 Motor(USBSerial *pc, PwmOut *pwm, DigitalOut *dir1, DigitalOut *dir2, DigitalIn *fault); 00011 00012 uint8_t pid_on; 00013 int16_t encTicks; 00014 volatile int16_t speed; 00015 uint8_t pgain, igain, dgain; 00016 00017 void setup(); 00018 /* 00019 * Run this to update speed 00020 */ 00021 void pid(int16_t encTicks); 00022 void pid2(int16_t encTicks); 00023 void init(); 00024 int16_t getSpeed(); 00025 void setSpeed (int16_t speed); 00026 void getPIDGain(char *gain); 00027 void forward(float pwm); 00028 void backward(float pwm); 00029 private: 00030 static const unsigned int PWM_PERIOD_US = 20000; 00031 00032 USBSerial *_pc; 00033 PwmOut *_pwm; 00034 DigitalOut *_dir1; 00035 DigitalOut *_dir2; 00036 DigitalIn *_fault; 00037 00038 union doublebyte { 00039 unsigned int value; 00040 unsigned char bytes[2]; 00041 }; 00042 00043 uint8_t enc_dir; 00044 uint8_t enc_last; 00045 uint8_t enc_now; 00046 00047 uint8_t dir; 00048 00049 int16_t currentPWM; 00050 uint8_t motor_polarity; 00051 00052 float pidSpeed0; 00053 float pidSpeed1; 00054 float pidError0; 00055 float pidError1; 00056 float pidError2; 00057 float pidSetpoint; 00058 00059 /* 00060 union doublebyte wcount; 00061 union doublebyte decoder_count; 00062 00063 uint8_t dir; 00064 */ 00065 00066 uint8_t fail_counter; 00067 uint8_t send_speed; 00068 uint8_t failsafe; 00069 uint8_t leds_on; 00070 00071 int16_t sp, sp_pid, der; 00072 int16_t intgrl, prop; 00073 //int16_t count, speed; 00074 int16_t csum; 00075 int16_t err, err_prev; 00076 00077 int16_t pwm, pwm_min, pwmmin; 00078 int16_t imax, err_max; 00079 uint8_t pid_multi, update_pid; 00080 00081 uint16_t stall_counter; 00082 uint16_t stallCount; 00083 uint16_t prevStallCount; 00084 uint16_t stallWarningLimit; 00085 uint16_t stallErrorLimit; 00086 uint8_t stallLevel; 00087 uint8_t stallChanged; 00088 //int16_t currentPWM; 00089 00090 00091 void reset_pid(); 00092 00093 }; 00094 #endif //MOTOR_H
Generated on Mon Oct 2 2023 09:25:36 by
1.7.2
