![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
45
Dependencies: mbed BufferedSerial LS7366LIB FastPWM
motor.h@0:c21936a3520a, 2020-03-23 (annotated)
- Committer:
- lsh2205
- Date:
- Mon Mar 23 08:38:40 2020 +0000
- Revision:
- 0:c21936a3520a
ss
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lsh2205 | 0:c21936a3520a | 1 | #ifndef _MOTOR_H_ |
lsh2205 | 0:c21936a3520a | 2 | #define _MOTOR_H_ |
lsh2205 | 0:c21936a3520a | 3 | |
lsh2205 | 0:c21936a3520a | 4 | #include "FastPWM.h" |
lsh2205 | 0:c21936a3520a | 5 | |
lsh2205 | 0:c21936a3520a | 6 | |
lsh2205 | 0:c21936a3520a | 7 | |
lsh2205 | 0:c21936a3520a | 8 | FastPWM pwm1(MOTOR_PWM1, -1); |
lsh2205 | 0:c21936a3520a | 9 | FastPWM pwm2(MOTOR_PWM2, -1); |
lsh2205 | 0:c21936a3520a | 10 | FastPWM pwm3(MOTOR_PWM3, -1); |
lsh2205 | 0:c21936a3520a | 11 | FastPWM pwm4(MOTOR_PWM4, -1); |
lsh2205 | 0:c21936a3520a | 12 | FastPWM pwm5(MOTOR_PWM5, -1); |
lsh2205 | 0:c21936a3520a | 13 | //FastPWM pwm6(MOTOR_PWM6, -1); |
lsh2205 | 0:c21936a3520a | 14 | |
lsh2205 | 0:c21936a3520a | 15 | void motor_init() |
lsh2205 | 0:c21936a3520a | 16 | { |
lsh2205 | 0:c21936a3520a | 17 | pwm1.period_us(2500); |
lsh2205 | 0:c21936a3520a | 18 | pwm2.period_us(2500); |
lsh2205 | 0:c21936a3520a | 19 | pwm3.period_us(2500); |
lsh2205 | 0:c21936a3520a | 20 | pwm4.period_us(2500); |
lsh2205 | 0:c21936a3520a | 21 | pwm5.period_us(2500); |
lsh2205 | 0:c21936a3520a | 22 | //pwm6.period_us(2500); |
lsh2205 | 0:c21936a3520a | 23 | } |
lsh2205 | 0:c21936a3520a | 24 | |
lsh2205 | 0:c21936a3520a | 25 | void motor_power(int motor_num,double percent) |
lsh2205 | 0:c21936a3520a | 26 | { |
lsh2205 | 0:c21936a3520a | 27 | percent=-percent; |
lsh2205 | 0:c21936a3520a | 28 | double output=offset[motor_num]; |
lsh2205 | 0:c21936a3520a | 29 | if(percent<-500) |
lsh2205 | 0:c21936a3520a | 30 | percent=-500; |
lsh2205 | 0:c21936a3520a | 31 | if(percent>500) |
lsh2205 | 0:c21936a3520a | 32 | percent=500; |
lsh2205 | 0:c21936a3520a | 33 | |
lsh2205 | 0:c21936a3520a | 34 | output = 1-(offset[motor_num] + percent)/2500; |
lsh2205 | 0:c21936a3520a | 35 | |
lsh2205 | 0:c21936a3520a | 36 | if(motor_num==0) |
lsh2205 | 0:c21936a3520a | 37 | pwm1.write(output); |
lsh2205 | 0:c21936a3520a | 38 | else if(motor_num==1) |
lsh2205 | 0:c21936a3520a | 39 | pwm2.write(output); |
lsh2205 | 0:c21936a3520a | 40 | else if(motor_num==2) |
lsh2205 | 0:c21936a3520a | 41 | pwm3.write(output); |
lsh2205 | 0:c21936a3520a | 42 | else if(motor_num==3) |
lsh2205 | 0:c21936a3520a | 43 | pwm4.write(output); |
lsh2205 | 0:c21936a3520a | 44 | else if(motor_num==4) |
lsh2205 | 0:c21936a3520a | 45 | pwm5.write(output); |
lsh2205 | 0:c21936a3520a | 46 | //else if(motor_num==5) |
lsh2205 | 0:c21936a3520a | 47 | // pwm6.write(output); |
lsh2205 | 0:c21936a3520a | 48 | } |
lsh2205 | 0:c21936a3520a | 49 | |
lsh2205 | 0:c21936a3520a | 50 | |
lsh2205 | 0:c21936a3520a | 51 | #endif |