svoe
Dependencies: mbed mbed-STM32F103C8T6 MPU6050_1
motion.h@15:960b922433d1, 2018-12-01 (annotated)
- Committer:
- Stas285
- Date:
- Sat Dec 01 14:25:04 2018 +0000
- Revision:
- 15:960b922433d1
- Parent:
- 12:721a9ea55e91
- Child:
- 17:bd6b6ac89e0e
coord_ready
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stas285 | 6:6e89cdc3db92 | 1 | //3 main parameters of the movement: |
Stas285 | 6:6e89cdc3db92 | 2 | //float accel (defined in motor.h) |
dima285 | 9:8f98b1c277a4 | 3 | float speed = 1;//cm/s |
Stas285 | 15:960b922433d1 | 4 | float radius = 100; |
Stas285 | 6:6e89cdc3db92 | 5 | |
Stas285 | 1:e2a6e523bf1f | 6 | bool infinite_flag = 0; |
Stas285 | 0:e9488589a8ee | 7 | |
Stas285 | 15:960b922433d1 | 8 | void go(float distance_m, bool brake = 1){ |
Stas285 | 15:960b922433d1 | 9 | target.path = current.path + distance_m; |
Stas285 | 15:960b922433d1 | 10 | // wifi.printf("%.2f %.2f %.2f %.2f;",target_path,current_path,distance_m,current_speed); |
Stas285 | 15:960b922433d1 | 11 | // while(abs(target.path - current.path) > 0.01){ |
Stas285 | 15:960b922433d1 | 12 | // gyro_process(); |
Stas285 | 15:960b922433d1 | 13 | // wifi.printf("%.2f %.2f %.2f %.2f;",target_path,current_path,target_path,current_speed);} |
Stas285 | 0:e9488589a8ee | 14 | } |
Stas285 | 15:960b922433d1 | 15 | /* |
dima285 | 8:891e4f54e9e2 | 16 | void go_no_wait(int cm, bool brake = 1){ |
dima285 | 8:891e4f54e9e2 | 17 | if(cm != 0) { |
dima285 | 8:891e4f54e9e2 | 18 | stop_flag = 0; infinite_flag = 0; |
dima285 | 8:891e4f54e9e2 | 19 | motor_enable = 1; |
dima285 | 8:891e4f54e9e2 | 20 | target_path =old_path + cm; old_path = target_path; |
dima285 | 8:891e4f54e9e2 | 21 | if(cm > 0) path_dir = 1; else path_dir = 0; |
dima285 | 8:891e4f54e9e2 | 22 | angle_task = 0; |
dima285 | 8:891e4f54e9e2 | 23 | motor_busy = 1; |
dima285 | 8:891e4f54e9e2 | 24 | //while(motor_busy == 1){proc_counter++;} |
dima285 | 8:891e4f54e9e2 | 25 | } |
dima285 | 8:891e4f54e9e2 | 26 | } |
Stas285 | 0:e9488589a8ee | 27 | |
Stas285 | 0:e9488589a8ee | 28 | void turn(int deg, bool brake = 1){ |
Stas285 | 0:e9488589a8ee | 29 | if(deg != 0) { |
Stas285 | 1:e2a6e523bf1f | 30 | stop_flag = 0; infinite_flag = 0; |
Stas285 | 0:e9488589a8ee | 31 | motor_enable = 1; |
Stas285 | 0:e9488589a8ee | 32 | target_angle = old_angle + deg; old_angle = target_angle; |
Stas285 | 0:e9488589a8ee | 33 | if(deg > 0) angle_dir = 1; else angle_dir = 0; |
Stas285 | 0:e9488589a8ee | 34 | angle_task = 1; |
Stas285 | 0:e9488589a8ee | 35 | motor_busy = 1; |
Stas285 | 0:e9488589a8ee | 36 | while(motor_busy == 1){proc_counter++;} |
Stas285 | 0:e9488589a8ee | 37 | old_path = current_path; |
Stas285 | 0:e9488589a8ee | 38 | } |
Stas285 | 0:e9488589a8ee | 39 | } |
Stas285 | 0:e9488589a8ee | 40 | |
Stas285 | 0:e9488589a8ee | 41 | void stop(){ |
Stas285 | 0:e9488589a8ee | 42 | motor_enable = 1; |
Stas285 | 0:e9488589a8ee | 43 | stop_flag = 1; |
Stas285 | 0:e9488589a8ee | 44 | motor_busy = 1; |
Stas285 | 0:e9488589a8ee | 45 | while(motor_busy == 1){} |
Stas285 | 6:6e89cdc3db92 | 46 | target_path = current_path; |
Stas285 | 4:904b737ef08a | 47 | //motor_enable = 0; |
Stas285 | 0:e9488589a8ee | 48 | } |
Stas285 | 0:e9488589a8ee | 49 | |
Stas285 | 0:e9488589a8ee | 50 | void dance(float dance_speed,float dance_accel){ |
Stas285 | 0:e9488589a8ee | 51 | speed = dance_speed; |
Stas285 | 0:e9488589a8ee | 52 | accel=dance_accel; |
Stas285 | 0:e9488589a8ee | 53 | radius=20; |
Stas285 | 0:e9488589a8ee | 54 | |
Stas285 | 0:e9488589a8ee | 55 | go(25); |
Stas285 | 0:e9488589a8ee | 56 | go(-50); |
Stas285 | 0:e9488589a8ee | 57 | go(25); |
Stas285 | 0:e9488589a8ee | 58 | turn(90); |
Stas285 | 0:e9488589a8ee | 59 | speed = -dance_speed; |
Stas285 | 0:e9488589a8ee | 60 | turn(-180); |
Stas285 | 0:e9488589a8ee | 61 | speed = dance_speed; |
Stas285 | 0:e9488589a8ee | 62 | turn(90); |
Stas285 | 0:e9488589a8ee | 63 | turn(-360); |
Stas285 | 0:e9488589a8ee | 64 | turn(360); |
Stas285 | 0:e9488589a8ee | 65 | |
Stas285 | 0:e9488589a8ee | 66 | go(20); |
Stas285 | 0:e9488589a8ee | 67 | speed = -dance_speed; |
Stas285 | 0:e9488589a8ee | 68 | turn(-90); |
Stas285 | 0:e9488589a8ee | 69 | speed = dance_speed; |
Stas285 | 0:e9488589a8ee | 70 | turn(-90); |
Stas285 | 0:e9488589a8ee | 71 | speed = -dance_speed; |
Stas285 | 0:e9488589a8ee | 72 | turn(-90); |
Stas285 | 0:e9488589a8ee | 73 | speed = dance_speed; |
Stas285 | 0:e9488589a8ee | 74 | turn(-90); |
Stas285 | 0:e9488589a8ee | 75 | go(-20); |
Stas285 | 0:e9488589a8ee | 76 | |
Stas285 | 0:e9488589a8ee | 77 | radius =0; |
Stas285 | 0:e9488589a8ee | 78 | turn(720); |
Stas285 | 0:e9488589a8ee | 79 | turn(-720); |
dima285 | 10:5bdd3dfd5f59 | 80 | } |
dima285 | 12:721a9ea55e91 | 81 | */ |
dima285 | 10:5bdd3dfd5f59 | 82 |