motor.h
00001
00002
00003
00004
00005
00006 #ifndef MOTOR_H
00007 #define MOTOR_H
00008
00009 #include "mbed.h"
00010
00011 #define UNASSIGNED_PWM_PIN LED4
00012 #define UNASSIGNED_MS_PIN p20
00013 #define NUM_MOTORS 7
00014
00015
00016 #define PWM_PERIOD 64
00017 #define UPDATE_PERIOD 5000
00018
00019 class Motor
00020 {
00021 public:
00022 virtual ~Motor();
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 virtual bool setControlParameters(uint8_t length, uint8_t *data) = 0;
00041
00042 virtual uint8_t * readControlParameters(uint8_t & length) = 0;
00043
00044 virtual long readTargetPosition() = 0;
00045
00046 virtual long readTargetVelocity() = 0;
00047
00048
00049
00050
00051
00052
00053 virtual void updateMotor() = 0;
00054
00055 uint8_t readMicroswitch();
00056 long readEncoder();
00057 float readPWMDuty();
00058 void setEncoder(long position);
00059 virtual void setDestination(long encoderPosition, long duration);
00060 void setPWMDuty(float duty);
00061
00062 protected:
00063 Motor();
00064 Motor(bool internal_pwm, uint8_t external_speed_pin,
00065 PinName internal_speed_pin, PinName microswitch_pin,
00066 PinMode microswitch_mode);
00067
00068 uint8_t external_speed_pin_;
00069 bool internal_pwm_;
00070 uint8_t external_speed_;
00071
00072 PwmOut speed_;
00073
00074 DigitalIn microswitch_;
00075
00076
00077 bool update_in_progress_;
00078
00079 long encoder_;
00080
00081 long desired_encoder_;
00082
00083 long desired_distance_;
00084
00085 Timer move_duration_;
00086
00087 float desired_move_duration_;
00088 };
00089
00090 #endif