(多分)全部+フライトピン+新しい加速度

Dependencies:   mbed

Committer:
394
Date:
Mon Oct 22 01:28:54 2018 +0000
Revision:
7:1c1b782263cf
Parent:
0:a01fda36fde8
10/22; 10:29

Who changed what in which revision?

UserRevisionLine numberNew contents of line
394 7:1c1b782263cf 1 #ifndef MBED_MOTOR_H
seangshim 0:a01fda36fde8 2 #define MBED_MOTOR_H
seangshim 0:a01fda36fde8 3
seangshim 0:a01fda36fde8 4 #include "mbed.h"
seangshim 0:a01fda36fde8 5
seangshim 0:a01fda36fde8 6 /** Interface to control a standard DC motor
seangshim 0:a01fda36fde8 7 * with an H-bridge using a PwmOut and 2 DigitalOuts
seangshim 0:a01fda36fde8 8 */
seangshim 0:a01fda36fde8 9 class Motor {
seangshim 0:a01fda36fde8 10 public:
seangshim 0:a01fda36fde8 11
seangshim 0:a01fda36fde8 12 /** Create a motor control interface
seangshim 0:a01fda36fde8 13 *
seangshim 0:a01fda36fde8 14 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
seangshim 0:a01fda36fde8 15 * @param fwd A DigitalOut, set high when the motor should go forward
seangshim 0:a01fda36fde8 16 * @param rev A DigitalOut, set high when the motor should go backwards
seangshim 0:a01fda36fde8 17 * @param set if the motor driver is able to do braking 0 false 1 true.
seangshim 0:a01fda36fde8 18 */
seangshim 0:a01fda36fde8 19 Motor(PinName pwm, PinName fwd, PinName rev, int brakeable);
seangshim 0:a01fda36fde8 20
seangshim 0:a01fda36fde8 21 /** Set the speed of the motor
seangshim 0:a01fda36fde8 22 *
seangshim 0:a01fda36fde8 23 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0.
seangshim 0:a01fda36fde8 24 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
seangshim 0:a01fda36fde8 25 */
seangshim 0:a01fda36fde8 26 float speed(float speed);
seangshim 0:a01fda36fde8 27
seangshim 0:a01fda36fde8 28 /** Set the the motor to coast
seangshim 0:a01fda36fde8 29 *
seangshim 0:a01fda36fde8 30 * @param void
seangshim 0:a01fda36fde8 31 * @return motor coasts until another instruction is recived.
seangshim 0:a01fda36fde8 32 */
seangshim 0:a01fda36fde8 33
seangshim 0:a01fda36fde8 34 void coast(void);
seangshim 0:a01fda36fde8 35
seangshim 0:a01fda36fde8 36 /** Set the motor to dynamicaly brake
seangshim 0:a01fda36fde8 37 *
seangshim 0:a01fda36fde8 38 * @param float 0 - 1.0 provides some control over how hard the motor brakes.
seangshim 0:a01fda36fde8 39 * @return duty applied to motor driver. -1 is error, motor driver can't brake.
seangshim 0:a01fda36fde8 40 */
seangshim 0:a01fda36fde8 41
seangshim 0:a01fda36fde8 42 float stop(float duty);
seangshim 0:a01fda36fde8 43 /** return the current state of the motor
seangshim 0:a01fda36fde8 44 *
seangshim 0:a01fda36fde8 45 * @param void
seangshim 0:a01fda36fde8 46 * @return state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error.
seangshim 0:a01fda36fde8 47 */
seangshim 0:a01fda36fde8 48 float state(void);
seangshim 0:a01fda36fde8 49
seangshim 0:a01fda36fde8 50 protected:
seangshim 0:a01fda36fde8 51 PwmOut _pwm;
seangshim 0:a01fda36fde8 52 DigitalOut _fwd;
seangshim 0:a01fda36fde8 53 DigitalOut _rev;
seangshim 0:a01fda36fde8 54 int Brakeable; // cna the motor driver break
seangshim 0:a01fda36fde8 55 int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
seangshim 0:a01fda36fde8 56
seangshim 0:a01fda36fde8 57 };
seangshim 0:a01fda36fde8 58
394 7:1c1b782263cf 59 #endif