DC motor position control with potentiometer

Dependents:   Ackermann steering baseControl_ackermannCar

Committer:
worasuchad
Date:
Wed Nov 07 16:51:16 2018 +0000
Revision:
0:b20808175db0
DC motor position control with potentiometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
worasuchad 0:b20808175db0 1 #ifndef LAMBORSTEER_H
worasuchad 0:b20808175db0 2 #define LAMBORSTEER_H
worasuchad 0:b20808175db0 3
worasuchad 0:b20808175db0 4 #include "mbed.h"
worasuchad 0:b20808175db0 5
worasuchad 0:b20808175db0 6 #define MAX_SERVOS 2
worasuchad 0:b20808175db0 7 #define MIN_POT_VALUE 10
worasuchad 0:b20808175db0 8 #define MAX_POT_VALUE 1000 // 800
worasuchad 0:b20808175db0 9 #define MIN_ANGLE 10
worasuchad 0:b20808175db0 10 #define MAX_ANGLE 400 // 170
worasuchad 0:b20808175db0 11
worasuchad 0:b20808175db0 12 typedef unsigned char uint8_t;
worasuchad 0:b20808175db0 13
worasuchad 0:b20808175db0 14 typedef struct {
worasuchad 0:b20808175db0 15 int wanted_angle;
worasuchad 0:b20808175db0 16 int current_angle;
worasuchad 0:b20808175db0 17 uint8_t speed;
worasuchad 0:b20808175db0 18 } servo_status;
worasuchad 0:b20808175db0 19
worasuchad 0:b20808175db0 20 class LamborSteer
worasuchad 0:b20808175db0 21 {
worasuchad 0:b20808175db0 22 public:
worasuchad 0:b20808175db0 23 LamborSteer(PinName _cw_pin, PinName _ccw_pin, PinName _enablerPin, PinName _sensor_pin, int _offset);
worasuchad 0:b20808175db0 24 //void attach();
worasuchad 0:b20808175db0 25 void timer_int_routine();
worasuchad 0:b20808175db0 26 void detach();
worasuchad 0:b20808175db0 27 void write(int degrees);
worasuchad 0:b20808175db0 28 void update();
worasuchad 0:b20808175db0 29 servo_status read();
worasuchad 0:b20808175db0 30
worasuchad 0:b20808175db0 31 bool active;
worasuchad 0:b20808175db0 32 int index;
worasuchad 0:b20808175db0 33 private:
worasuchad 0:b20808175db0 34 int offset;
worasuchad 0:b20808175db0 35 uint8_t speed;
worasuchad 0:b20808175db0 36 int wanted_position;
worasuchad 0:b20808175db0 37 int tolerance;
worasuchad 0:b20808175db0 38 int constrained_value;
worasuchad 0:b20808175db0 39
worasuchad 0:b20808175db0 40 void write_pot_value(int degrees);
worasuchad 0:b20808175db0 41 void run_cw();
worasuchad 0:b20808175db0 42 void run_ccw();
worasuchad 0:b20808175db0 43 void stop();
worasuchad 0:b20808175db0 44 int get_position();
worasuchad 0:b20808175db0 45 long map(long x, long in_min, long in_max, long out_min, long out_max);
worasuchad 0:b20808175db0 46 DigitalOut cw_pin;
worasuchad 0:b20808175db0 47 DigitalOut ccw_pin;
worasuchad 0:b20808175db0 48 PwmOut enabler_pin;
worasuchad 0:b20808175db0 49 AnalogIn sensor_pin;
worasuchad 0:b20808175db0 50 };
worasuchad 0:b20808175db0 51
worasuchad 0:b20808175db0 52 static int s_index; // number of registered servo's
worasuchad 0:b20808175db0 53 static LamborSteer* _m_servos[2]; // array containing registered servo's
worasuchad 0:b20808175db0 54 #endif