HoSeung Choi / step_motor

Dependents:   ft_robot1

Committer:
d2_h10s
Date:
Mon Aug 31 15:09:14 2020 +0000
Revision:
1:3122058b3a2e
Parent:
0:283fc48ef873
for braille teams

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d2_h10s 0:283fc48ef873 1 #include "mbed.h"
d2_h10s 0:283fc48ef873 2 #include "mStepper.h"
d2_h10s 0:283fc48ef873 3
d2_h10s 1:3122058b3a2e 4
d2_h10s 0:283fc48ef873 5 typedef enum {go = 0,back = 1,left = 2,right = 3, both = 4} Direction; //global enumerator
d2_h10s 0:283fc48ef873 6 typedef enum {CW = 0, CCW = 1} Clock;
d2_h10s 0:283fc48ef873 7
d2_h10s 0:283fc48ef873 8 class Robot{
d2_h10s 0:283fc48ef873 9 private:
d2_h10s 0:283fc48ef873 10 float vel; // velocity per max
d2_h10s 0:283fc48ef873 11 mStepper LM, RM; // left motor, right motor
d2_h10s 0:283fc48ef873 12 DigitalOut l_enb, r_enb; // left enable pin, right enable pin
d2_h10s 0:283fc48ef873 13
d2_h10s 0:283fc48ef873 14 public:
d2_h10s 0:283fc48ef873 15 Robot(PinName l_dir, PinName l_step, PinName _l_enb, PinName r_dir, PinName r_step, PinName _r_enb);
d2_h10s 0:283fc48ef873 16
d2_h10s 0:283fc48ef873 17 void enable(uint8_t _dir); // enable certain motor
d2_h10s 0:283fc48ef873 18 void disable(uint8_t _dir); // diable certain motor
d2_h10s 0:283fc48ef873 19
d2_h10s 0:283fc48ef873 20 uint8_t isRun(); // if motor's distance to go is left return true or not return 0
d2_h10s 0:283fc48ef873 21
d2_h10s 0:283fc48ef873 22 void run(uint8_t _dir); // drive motor
d2_h10s 0:283fc48ef873 23 void run_speed(uint8_t _dir);
d2_h10s 0:283fc48ef873 24 void stop(uint8_t _dir); // stop motor, direction is left or right or both
d2_h10s 0:283fc48ef873 25
d2_h10s 0:283fc48ef873 26 void move_cm(uint8_t _dir, float _distance_cm); // move constant distance
d2_h10s 0:283fc48ef873 27 void move_speed(uint8_t _dir, float _vel); // move max speed * percent
d2_h10s 0:283fc48ef873 28
d2_h10s 0:283fc48ef873 29 void turn_deg(uint8_t _dir, float _ang); // robot turn left or right
d2_h10s 0:283fc48ef873 30 void turn_LM(uint8_t _dir, float _ang, float _vel); // turn only left motor, default percent of velocity is 100%
d2_h10s 0:283fc48ef873 31 void turn_RM(uint8_t _dir, float _ang, float _vel); // turn only right motor, default percent of velocity is 100%
d2_h10s 1:3122058b3a2e 32 };
d2_h10s 1:3122058b3a2e 33