svoe
Dependencies: mbed mbed-STM32F103C8T6 MPU6050_1
realtime.h@8:891e4f54e9e2, 2017-08-18 (annotated)
- Committer:
- dima285
- Date:
- Fri Aug 18 08:53:15 2017 +0000
- Revision:
- 8:891e4f54e9e2
- Parent:
- 6:6e89cdc3db92
- Child:
- 9:8f98b1c277a4
jstrjm66MRRRRRRRRRRth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stas285 | 0:e9488589a8ee | 1 | Ticker rt_ticker; |
Stas285 | 4:904b737ef08a | 2 | float rt_delta; |
Stas285 | 4:904b737ef08a | 3 | bool realtime_flag; |
Stas285 | 0:e9488589a8ee | 4 | |
Stas285 | 4:904b737ef08a | 5 | void realtime(){ //35uS - (3.5mS @ 115200) - (500uS @ 921600) (w/o sin,cos) |
Stas285 | 6:6e89cdc3db92 | 6 | myled = !myled; |
Stas285 | 4:904b737ef08a | 7 | // test = 1; |
Stas285 | 6:6e89cdc3db92 | 8 | |
Stas285 | 6:6e89cdc3db92 | 9 | //geometric navigation |
Stas285 | 6:6e89cdc3db92 | 10 | rt_delta = (motor_speed[1]+motor_speed[0])/2.0*0.05; |
Stas285 | 6:6e89cdc3db92 | 11 | current_angle += (motor_speed[0]-motor_speed[1])*0.05/16.0*57.3;//deg |
Stas285 | 4:904b737ef08a | 12 | current_path += rt_delta; |
Stas285 | 4:904b737ef08a | 13 | current_x += rt_delta*sin(current_angle/57.3); |
Stas285 | 4:904b737ef08a | 14 | current_y += rt_delta*cos(current_angle/57.3); |
Stas285 | 6:6e89cdc3db92 | 15 | //pc.printf("%3.1f - %3.1f ; %3.1f - %3.1f ; %d\n",target_path,current_path,target_angle,current_angle,motor_busy); //be careful in interrupt |
Stas285 | 0:e9488589a8ee | 16 | |
Stas285 | 0:e9488589a8ee | 17 | if(motor_busy == 1) { |
Stas285 | 6:6e89cdc3db92 | 18 | if(stop_flag == 1) {skorost(0,0);skorost(1,0);if(abs(motor_speed[0])<1) motor_busy = 0;} //Stop with accel |
Stas285 | 1:e2a6e523bf1f | 19 | else { //motion |
Stas285 | 1:e2a6e523bf1f | 20 | if(infinite_flag == 1){skorost(1,speed*(1-half_width/radius));skorost(0,speed*(1+half_width/radius));} |
Stas285 | 1:e2a6e523bf1f | 21 | else{ |
Stas285 | 1:e2a6e523bf1f | 22 | if(angle_task == 1) {//radial motion |
Stas285 | 1:e2a6e523bf1f | 23 | if((angle_dir == 1) && (target_angle <= current_angle)) motor_busy = 0; |
Stas285 | 1:e2a6e523bf1f | 24 | if((angle_dir == 0) && (target_angle >= current_angle)) motor_busy = 0; |
Stas285 | 1:e2a6e523bf1f | 25 | if(motor_busy == 1) { |
Stas285 | 1:e2a6e523bf1f | 26 | if(radius > 1) { |
Stas285 | 1:e2a6e523bf1f | 27 | if((angle_dir == 1) && (speed>0) || (angle_dir == 0) && (speed<0)){ |
Stas285 | 1:e2a6e523bf1f | 28 | skorost(1,speed*(1-half_width/radius));skorost(0,speed*(1+half_width/radius));} |
Stas285 | 1:e2a6e523bf1f | 29 | else {skorost(1,speed*(1+half_width/radius));skorost(0,speed*(1-half_width/radius));}} |
Stas285 | 4:904b737ef08a | 30 | else {if(angle_dir == 1){skorost(1,-speed); skorost(0,speed);} else {skorost(1,speed); skorost(0,-speed);} //turn on the spot |
Stas285 | 1:e2a6e523bf1f | 31 | } |
Stas285 | 0:e9488589a8ee | 32 | } |
Stas285 | 1:e2a6e523bf1f | 33 | } |
Stas285 | 1:e2a6e523bf1f | 34 | if(angle_task == 0) {//linear motion |
Stas285 | 1:e2a6e523bf1f | 35 | if((path_dir == 1) && (target_path <= current_path)) motor_busy = 0; |
Stas285 | 1:e2a6e523bf1f | 36 | if((path_dir == 0) && (target_path >= current_path)) motor_busy = 0; |
Stas285 | 1:e2a6e523bf1f | 37 | if(motor_busy == 1) {if(path_dir == 1) {skorost(1,speed);skorost(0,speed);} else{skorost(1,-speed);skorost(0,-speed);} } |
Stas285 | 0:e9488589a8ee | 38 | } |
Stas285 | 0:e9488589a8ee | 39 | } |
Stas285 | 0:e9488589a8ee | 40 | } |
Stas285 | 0:e9488589a8ee | 41 | } |
Stas285 | 4:904b737ef08a | 42 | echo_step(1); |
Stas285 | 4:904b737ef08a | 43 | realtime_flag = 1; |
Stas285 | 0:e9488589a8ee | 44 | |
Stas285 | 4:904b737ef08a | 45 | // test = 0; |
Stas285 | 1:e2a6e523bf1f | 46 | //pc.printf("%d \n", proc_counter); proc_counter = 0; |
Stas285 | 0:e9488589a8ee | 47 | } |
Stas285 | 0:e9488589a8ee | 48 | |
Stas285 | 0:e9488589a8ee | 49 | void realtime_init(){ |
dima285 | 8:891e4f54e9e2 | 50 | rt_ticker.attach_us(&realtime, 10000); |
Stas285 | 0:e9488589a8ee | 51 | } |