Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
obstacle_avoidance.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Roland + Clint
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
27#include <stdio.h>
28#include <sys/fcntl.h>
29#include <math.h>
30#include <unistd.h>
31#include <inttypes.h>
32#include "state.h"
39
40#ifndef AVOIDANCES_DISTANCES_HOR_COUNT
41#define AVOIDANCES_DISTANCES_HOR_COUNT 36
42#endif
43
44#ifndef AVOIDANCE_AMOUNT_OF_BOARDS
45#define AVOIDANCE_AMOUNT_OF_BOARDS 6
46#endif
47
48#ifndef AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES
49#define AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES 6
50#endif
51
52#ifndef AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES
53#define AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES 6
54#endif
56//sensor info
58float stereo_fow[2] = {1.0018, 0.7767};//based on FOW of 57.4, by 44.5
59float angle_hor_board[] = {0, 1.0472, 2.0944, 3.1416, -2.0944, -1.0472};
60int16_t focal = 118 * 6;
61float baseline = 60;
62float ref_yaw = 0.0;
63//tuning info
64float reference_pitch = 0.1;
65float reference_roll = 0.1;
66float dist_treshold = 1.25;
68
70//for messages
71//general
72uint8_t *READimageBuffer_old; //USED for butterworth filter
76//target
79struct FloatVect2 init_target = {0, 0};
80float dx_ref = 0;
81float dy_ref = 0;
82//Variables Kalman filter
83float A_kal = 1;
84float B_kal = 0;
85float H_kal = 1;
86float Q_kal = 0.05;//TODO: clean variables
87float R_kal = 2;
88float K_gain_send = 0;
93//variables butterworth filter
94struct FloatVect3 filter_repforce_old = {0.0, 0.0, 0.0};
95struct FloatVect3 Repulsionforce_Kan_old = {0.0, 0.0, 0.0};
98//Vector Method
99float F1 = 0.1;
100float F2 = 0.9;
101float Cfreq = 1;
102float Ko = 60;//1000;//10000
103float Kg = 100;//100;//100
104float Dist_offset = 0;//-0.125;
109//Potential Method
110float b_damp = 0;
111float K_goal = 1;
112float K_obst = 40;
113float c1_oa = 0.4;
114float c2_oa = 0.4;
115float c3_oa = 5.0;
116float c4_oa = 0.5;
117float c5_oa = 0.9;
118float kv = 0.05;
119float epsilon = 0.0;
120float vmin = 0.2;
122//variables escape method
126float waypoint_rot = 0;
129float v_min = 0.3;
130float v_max = 0.6;
131//variables hysteris
132float V_hys_low = 5;
133float V_hys_high = 10;
135//variables for logger
138
139//static void send_OA_DATA(void)
140//{
141// //DOWNLINK_SEND_OA_DATA(DefaultChannel, DefaultDevice, &target.x, &target.y, &pos_diff.x, &pos_diff.y, &ref_pitch,
144//}
145
146void serial_init(void)
147{
148
149 for (int i_fill = 0;
151 i_fill++) {
152 Pest_new[i_fill] = 1;
153 Xest_new[i_fill] = 1;
154 butter_old[i_fill] = 0;
155 }
156// register_periodic_telemetry(DefaultPeriodic, "OA_DATA", send_OA_DATA);
157}
158
159void serial_start(void)
160{
161 //printf("serial start\n");
162}
163
166{
167
168 for (int i1 = 0; i1 < size_matrix_local[0]; i1++) {
169 for (int i3 = 0; i3 < size_matrix_local[2]; i3++) {
172 }
173 }
174}
175
177{
178 if (stereocam_data.fresh) {
179 printf("Stereo fresh: %i \n", stereocam_data.len);
180
182 float anglesMeasurements[stereocam_data.matrix_width];
183
184 //stereocam_disparity_to_meters(stereocam_data.data,distancesMeters,stereocam_data.len);
188 }
189 printf("\n");
190 }
191
193 if (OA_method_flag == PINGPONG) {
194 //Calculate angles + distances
197
201 }
202
206 }
207
208 if (OA_method_flag == POT_VEL) {
211 }
212
213 if (OA_method_flag == VECTOR) {
216 }
217 if (OA_method_flag == SAFETYZONE) {
220 }
221 if (OA_method_flag == LOGICBASED) {
224 }
225
226 stereocam_data.fresh = 0;
227 if (stereocam_data.len > 50) {
229
230 } else {
232
233 }
234 }
235
236}
262
264{
265 //TODO implement kalman filter
266 //Parameters for Kalman filter
272
273 //Kallman filter on disparity matrix
274 for (int i_k = 0; i_k < (size_matrix[0]*size_matrix[1]*size_matrix[2]); i_k++) {
277
278 //one step ahead prediction
280
281 //Covariance matrix of state prediction error
283
284 //Kalman gain calculation
285 K_gain[i_k] = Ppred_new[i_k] * H_kal * 1.0 / (H_kal * Ppred_new[i_k] * H_kal + R_kal);
286
287 //Measurement update
289
290 //Covariance matrix of state estimation error
291 Pest_new[i_k] = (1 - K_gain[i_k] * H_kal) * Ppred_new[i_k];
292 }
293}
294
296{
298 float A_butter = -0.7265;
299 float B_butter[2] = {0.1367, 0.1367};
300
301
302 for (int i_k = 0; i_k < (size_matrix[0] * size_matrix[1] * size_matrix[2]); i_k++) {
303
304 if ((READimageBuffer_old[i_k] - stereocam_data.data[i_k]) <= 1
305 && (READimageBuffer_old[i_k] - stereocam_data.data[i_k]) > 0) {
307
308 }
309
313 }
314
315 for (int ifill = 0; ifill < (size_matrix[0] * size_matrix[1] * size_matrix[2]); ifill++) {
317 }
318
319}
320
322{
324
325 float psi = stateGetNedToBodyEulers_f()->psi;
326 float s_psi = sin(psi);
327 float c_psi = cos(psi);
330 float dx_ref_NED;
331 float dy_ref_NED;
332
333 if (OA_method_flag == 2) {
336
337 } else {
340 }
341
344
345 //apply rotation of waypoint
346 if (OA_method_flag == 6) {
349 }
350
354
355}
356
359{
360
361 //init
362 float sumPitch = 0.0;
363 float sumRoll = 0.0;
364
367
369
370 // printf("index: %i,distance %f",horizontal_index, distances_hor[horizontal_index]);
372
377
378 }
379 }
380
383 } else if (sumPitch < -attitude_reference_pitch) {
385 } else {
387 }
388
389
392 } else if (sumRoll < -attitude_reference_roll) {
394 } else {
396 }
397
398
399 printf("DegOfRad data %f %f\n", ref_pitch, ref_roll);
400
401
402}
403
405{
406 //float OF_Result_Vy = 0;
407 //float OF_Result_Vx = 0
408
409 //Initialize
410 float potential_obst = 0; //define potential field variables
411 float potential_obst_temp = 0;
413 float Distance_est;
414 float angle_hor = - 0.5 * stereo_fow[0] - stereo_fow[0] / size_matrix[2] + stereo_fow[0] / size_matrix[2] /
415 2; //calculate position angle of stereo
416 float angle_hor_abs;
417 float obst_count = 0.0;
418 //float total_vel;
419 //float current_heading;
420 //float fp_angle;
421
422 //Tune
423 //float dt = 0.5; //define delta t for integration! check response under 0.1 and 1
425
426 //Current state of system;
427 float r_old = stateGetBodyRates_f()->r;
428 //current_heading = stateGetNedToBodyEulers_f()->psi; //check maybe cause of errors
429 //current_heading = 0;
430
431 //check if side slip is zero
432 //total_vel = pow((OF_Result_Vy*OF_Result_Vy + OF_Result_Vx*OF_Result_Vx),0.5);
433
434 //if (total_vel>vmin){
435 // fp_angle = atan2(OF_Result_Vx,OF_Result_Vy);
436 //}
437 //else{
438 // fp_angle = 0;
439 //}
440 //fp_angle = 0;
441
444
445
446 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
448 / 2; //Check if bodyframe is correct with current_heading correction
449 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
450
454 obst_count = 0;
455
456 for (int i2 = 0; i2 < 4; i2++) {
457
458 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
459 Distance_est = ((baseline * (float)focal / (float)stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0] *
460 size_matrix[2] + i3] - 18.0)) / 1000;
461
462 if (angle_hor < 0) {
464 } else {
466 }
468 -c4_oa * Distance_est);//(tan(obst_width[i]+c5)-tan(c5));
470 -c3_oa * fabs(angle_hor)) * exp(-c4_oa * Distance_est); // (tan(obst_width[i]+c5)-tan(c5));
471 //printf("angle_hor: %f, angle_hor_abs: %f, c3: %f, potential_obst: %f", angle_hor, angle_hor_abs,c3_oa,potential_obst);
472 obst_count++;
473
474 } else {
475 Distance_est = 2000;
476 }
477
478 //potential_obst = potential_obst + K_obst*(angle_hor);//*exp(-c3*abs(angle_hor))*exp(-c4*Distance_est);//(tan(obst_width[i]+c5)-tan(c5));
479 //potential_obst_write = potential_obst;
480 //potential_obst_integrated = potential_obst_integrated + K_obst*c3*(abs(angle_hor)+1)/(c3*c3)*exp(-c3*abs(angle_hor))*exp(-c4*Distance_est);// (tan(obst_width[i]+c5)-tan(c5));
481
482 }
483 if (obst_count != 0) {
485 }
486 }
487 }
488
489 //printf("current_heading, %f heading_goal_f: %f",current_heading, heading_goal_ref);
490 //calculate angular accelaration from potential field
491
494
495 // Calculate velocity from potential
497 if (speed_pot <= 0) {
498 speed_pot = 0;
499 }
500
501 //calculate new_heading(ref_pitch)
502 //ref_pitch = (current_state(3)+sideslip) + alpha_fil*r_dot_new;)
503
504}
505
507{
508 float OF_Result_Vy = 0;
509 float OF_Result_Vx = 0;
510
511 //Constants
512 float new_heading;
513 float alpha_fil = 0.2;
514
515 //Initialize
516 float potential_obst = 0; //define potential field variables
518 float Distance_est;
519 float fp_angle;
520 float diff_angle;
521 float total_vel;
522 float current_heading;
523 float angle_hor = - 0.5 * stereo_fow[0] - stereo_fow[0] / size_matrix[2] + stereo_fow[0] / size_matrix[2] /
524 2; //calculate position angle of stereo
525
526 //Tune
527 //float dt = 0.5; //define delta t for integration! check response under 0.1 and 1
529
530 //Current state of system;
531 float r_old = stateGetBodyRates_f()->r;
532 current_heading = stateGetNedToBodyEulers_f()->psi; //check maybe cause of errors
533 //current_heading = 0;
534
536
537 if (total_vel > vmin) {
539 } else {
540 fp_angle = 0;
541 }
542
545
546
547 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
549 / 2; //Check if bodyframe is correct with current_heading correction
550 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
553
554 for (int i2 = 0; i2 < size_matrix[1]; i2++) {
555
556 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
557 Distance_est = ((baseline * (float)focal / (float)stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0] *
558 size_matrix[2] + i3] - 18.0)) / 1000;
559 } else {
560 Distance_est = 2000;
561 }
565 -c4_oa * Distance_est); //(tan(obst_width[i]+c5)-tan(c5));
567 -c3_oa * fabs(diff_angle)) * exp(-c4_oa * Distance_est); // (tan(obst_width[i]+c5)-tan(c5));
568
569 }
570 }
571 }
572
573 //calculate angular accelaration from potential field
576
577 // Calculate velocity from potential
579 if (speed_pot <= 0) {
580 speed_pot = 0;
581 }
582
583 //calculate new_ref_speeds
586
588}
589
591{
592
593 //Constants
594 //Parameters for Butterworth filter
595 float A_butter = -0.8541;//-0.7265;
596 float B_butter[2] = {0.0730 , 0.0730 };//{0.1367, 0.1367};
597
598 //Initalize
599 int8_t disp_count = 0;
600 float escape_angle = 0;
601 float y_goal_frame;
602 //float total_vel;
603 float Distance_est;
604 float Ca;
605 float Cv;
606 float angle_ver = 0;
607 float angle_hor = 0;
608 //struct FloatVect3 Repulsionforce_Kan = {0,0,0};
612 //struct FloatVect3 Attractforce_goal = {0,0,0};
613 //Attractforce_goal.x = 0;
614 //Attractforce_goal.y = 0;
615 //Attractforce_goal.z = 0;
616 //struct FloatRMat T;
617 //struct FloatEulers current_attitude = {0,0,0};
618 struct FloatVect3 Total_Kan = {0, 0, 0};
619 //Tuning variables
620 //float force_max = 200;
622
623 //Flight plath angle calculation
624 // TODO make algorithm dependent on angle of obstacle.....
625 // total_vel = pow((OF_Result_Vy*OF_Result_Vy + OF_Result_Vx*OF_Result_Vx),0.5);
626
627 // if (total_vel>vmin){
628 // fp_angle = atan2(OF_Result_Vx,OF_Result_Vy);
629 // }
630 // else{
631 // fp_angle = 0;
632 // }
633
635 //FLOAT_ANGLE_NORMALIZE(heading_goal_ref);
636
637 //Calculate Attractforce_goal size = 1;
641
642
643 //printf("current_heading, %f heading_goal_f: %f, heading_goal_ref: %f",stateGetNedToBodyEulers_f()->psi, heading_goal_f, heading_goal_ref);
644 //Transform to body frame
645 //current_attitude.psi = stateGetNedToBodyEulers_f()->psi;Attractforce_already in body frame, check when using data form Roland
646 //float_rmat_of_eulers_312(&T, &current_attitude);
647 //MAT33_VECT3_MUL(Attractforce_goal, T, Attractforce_goal);
648
649 //Attractforce_goal_send.x = Attractforce_goal.x;
650 //Attractforce_goal_send.y = Attractforce_goal.y;
651 //Attractforce_goal_send.z = Attractforce_goal.z;
652
653
654 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
656 / 2; //Check if bodyframe is correct with current_heading correction
657
658 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
660 angle_ver = 0.5 * stereo_fow[1] + stereo_fow[1] / size_matrix[1] - stereo_fow[1] / size_matrix[1] / 2;
661
662 for (int i2 = 0; i2 < 4; i2++) {
664
666 if (Ca < 0) {
667 Ca = 0;
668 }
669
670 //TODO make dependent on speed: total_vel/vref_max
671 Cv = F1 + F2 * Ca;
672 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
673 Distance_est = (baseline * (float)focal / ((float)stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0] *
674 size_matrix[2] + i3]) - 18.0) / 1000;
675 disp_count++;
677 2) * cos(angle_hor) * cos(angle_ver);
679 2) * sin(angle_hor) * cos(angle_ver);
681
682 printf("rep.x %f index %d %d %d disp: %d cv: %f angle_hor: %f angle_ver: %f \n", Repulsionforce_Kan.x, i1, i2, i3,
684
685 }
686// else {
687// Distance_est = 2000;
688// }
689//
690// if(pow(Cv/(READimageBuffer_offset[i1*size_matrix[1]+i2*size_matrix[0]*size_matrix[2] + i3]-0.2),2)<force_max){
691// Repulsionforce_Kan.x = Repulsionforce_Kan.x - pow(Cv/(Distance_est+Dist_offset),2)*cos(angle_hor)*cos(angle_ver);
692// Repulsionforce_Kan.y = Repulsionforce_Kan.y - pow(Cv/(Distance_est+Dist_offset),2)*sin(angle_hor)*cos(angle_ver);
693// Repulsionforce_Kan.z = Repulsionforce_Kan.z - pow(Cv/(Distance_est+Dist_offset),2)*sin(angle_ver);
694// }
695// else{
696// Repulsionforce_Kan.x = Repulsionforce_Kan.x - force_max*sin(angle_hor)*cos(angle_ver);
697// Repulsionforce_Kan.y = Repulsionforce_Kan.y - force_max*cos(angle_hor)*cos(angle_ver);
698// Repulsionforce_Kan.z = Repulsionforce_Kan.z - force_max*sin(angle_ver);
699// }
700
701 }
702 }
703 }
704
705 //Normalize for ammount entries in Matrix
706 //Repulsionforce_Kan = Repulsionforce_Kan/(float)(size_matrix[1]*size_matrix[2]);
708 printf("After multiplication: %f", Repulsionforce_Kan.x);
709
711
718
721
722 }
723
724 else {
726 }
727
730
731 //Total force
734
735 //set variable for stabilization_opticflow
736 //printf("RepulsionforceX: %f AttractX: %f \n",Repulsionforce_Used.x,Attractforce_goal.x);
737 //printf("RepulsionforceY: %f AttractY: %f \n",Repulsionforce_Used.y,Attractforce_goal.y);
738
739
740 //hysteris
742 hysteris_flag = 1;
743
744 //x_goal_frame= cos() * Total_Kan.x + sin() * Total_Kan.y;
746
747 if (y_goal_frame >= 0) {
748 escape_angle = 0.5 * M_PI;
749 } else if (y_goal_frame < 0) {
750 escape_angle = -0.5 * M_PI;
751 }
752 }
753
754
756 hysteris_flag = 0;
757 }
758
759 if (hysteris_flag == 1) {
760
763
764 }
765
766
769 printf("ref_pitch: %f ref_roll: %f disp_count: %d", ref_pitch, ref_roll, disp_count);
770 //set write values for logger
771 //Attractforce_goal_send.x = Attractforce_goal.x;
772 //Attractforce_goal_send.y = Attractforce_goal.y;
773 //Repulsionforce_Kan_send.x = Repulsionforce_Used.x;
774 //Repulsionforce_Kan_send.y = Repulsionforce_Used.y;
775}
776
778{
779
781 //Constants
782 //Parameters for Butterworth filter
783 float A_butter = -0.8541;//-0.7265;
784 float B_butter[2] = {0.0730 , 0.0730 };//{0.1367, 0.1367};
785
786 int8_t disp_count = 0;
787 //Initalize
788 //float fp_angle;
789 //float total_vel;
790 float Ca;
791 float Cv;
792 float angle_ver = 0;
793 float angle_hor = 0;
797 //struct FloatRMat T;
798 //struct FloatEulers current_attitude = {0,0,0};
799 struct FloatVect3 Total_Kan = {0, 0, 0};
800 //Tuning variables
801 //float force_max = 200;
802
804 //Constants
807 float bias = 2 * M_PI;
808 vref_max = 0.1; //CHECK!
809 //init
812 float new_heading_diff = 1000;
813 float new_heading = 1000;
814 int8_t i = 0;
815 int8_t i_buffer = 0;
816 float Distance_est;
817 float V_total = 0;
819
821 //FLOAT_ANGLE_NORMALIZE(heading_goal_ref);
822
823 //Calculate Attractforce_goal
827
828 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
830 / 2; //Check if bodyframe is correct with current_heading correction
831
832 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
834 angle_ver = 0.5 * stereo_fow[1] + stereo_fow[1] / size_matrix[1] - stereo_fow[1] / size_matrix[1] / 2;
835
836 for (int i2 = 0; i2 < 4; i2++) {
838
840 if (Ca < 0) {
841 Ca = 0;
842 }
843
844 //TODO make dependent on speed: total_vel/vref_max
845 Cv = F1 + F2 * Ca;
846
847 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
848 Distance_est = (baseline * (float)focal / ((float)stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0] *
849 size_matrix[2] + i3]) - 18.0) / 1000;
850 disp_count++;
852 2) * cos(angle_hor) * cos(angle_ver);
854 2) * sin(angle_hor) * cos(angle_ver);
856
857
858 }
859
860 }
861 }
862 }
863
864 //Normalize for ammount entries in Matrix
866
868
875
878
879 }
880
881 else {
883 }
884
887
888 //Total force
891
892 //set variable for stabilization_opticflow
893 printf("RepulsionforceX: %f AttractX: %f \n", Repulsionforce_Used.x, Attractforce_goal.x);
894 printf("RepulsionforceY: %f AttractY: %f \n", Repulsionforce_Used.y, Attractforce_goal.y);
895
896 //set write values for logger
897 //Attractforce_goal_send.x = Attractforce_goal.x;
898 //Attractforce_goal_send.y = Attractforce_goal.y;
899 //Repulsionforce_Kan_send.x = Repulsionforce_Used.x;
900 //Repulsionforce_Kan_send.y = Repulsionforce_Used.y;
901
902 V_total = sqrt(pow(Total_Kan.x, 2) + pow(Total_Kan.y, 2));
903
904 if (V_total < v_min && sqrt(VECT2_NORM2(pos_diff)) > 1) {
905 escape_flag = 1;
906 }
907
908 else if (V_total > v_max && obstacle_flag == 0) {
909 escape_flag = 0;
910 }
911
912 printf("V_total: %f", V_total);
913 printf("escape_flag: %i, obstacle_flag: %i, set_bias: %i", escape_flag, obstacle_flag, set_bias);
914 printf("escape_flag: %i, obstacle_flag: %i, set_bias: %i", escape_flag, obstacle_flag, set_bias);
915
916 if (escape_flag == 0) {
919 } else if (escape_flag == 1) {
921
922 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
924 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
929 i++;
930
931 }
932 }
933
934 i = 0;
935 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
936 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
937 for (int i2 = 0; i2 < 4; i2++) {
938 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
939 //distance_est = (baseline*(float)focal/((float)READimageBuffer_offset[i1*size_matrix[1]+i2*size_matrix[0]*size_matrix[2] + i3])-18.0)/1000;
940
941 diff_available_heading[i] = 100;
942 for (int i_diff = -number_of_buffer; i_diff <= number_of_buffer + 1; i_diff++) {
943 i_buffer = i + i_diff;
944
945
946 if (i_buffer < 1) {
948 }
949
950 if (i_buffer > size_matrix[0]*size_matrix[2]) {
952 }
953
955 }
956 }
957 }
958 i++;
959 }
960 }
961
962 //set bias
963 if (set_bias == 1) {
964 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
965 if (diff_available_heading[i100] <= 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
967 }
968 }
969 } else if (set_bias == 2) {
970 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
971 if (diff_available_heading[i100] > 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
973 }
974 }
975 }
976
977 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
981 }
982 }
983
984 if (obstacle_flag == 0 && fabs(new_heading_diff) > (2 * M_PI / 36.0)) {
985 obstacle_flag = 1;
986 if (new_heading_diff > 0) {
987 set_bias = 1;
988 direction = -1;
989 } else if (new_heading_diff <= 0) {
990 set_bias = 2;
991 direction = 1;
992 }
993 }
994
995 if (fabs(new_heading_diff) <= (2 * M_PI / 36.0)) {
996 if (waypoint_rot == 0) {
997 obstacle_flag = 0;
998 set_bias = 0;
999 } else {
1001 }
1002 }
1003
1004 if (fabs(new_heading_diff) >= 0.5 * M_PI) {
1006 }
1007
1008 //vref_max should be low
1010 if (speed_pot <= 0) {
1011 speed_pot = 0;
1012 }
1013
1015
1016#if PRINT_STUFF
1017 for (int i100 = 0; i100 < (size_matrix[0] * size_matrix[2]); i100++) {
1018 printf("%i diff_available_heading: %f available_heading: %f \n", i100, diff_available_heading[i100],
1020 }
1021 printf("new_heading: %f current_heading: %f speed_pot: %f\n", new_heading, stateGetNedToBodyEulers_f()->psi,
1022 speed_pot);
1023 printf("set_bias: %i obstacle_flag: %i", set_bias, obstacle_flag);
1024#endif
1025
1028
1029 }
1030}
1031
1033{
1034
1035 //Constants
1036 int8_t min_disparity = 45;
1038 float bias = 2 * M_PI;
1039 vref_max = 0.1; //CHECK!
1040
1041 //init variables
1042 float angle_hor = 0;
1045 float new_heading_diff = 1000;
1046 float new_heading = 1000;
1047 int8_t i = 0;
1048 int8_t i_buffer = 0;
1049 float distance_est;
1050 float distance_heading = 0;
1051
1052 //generate available_headings
1054
1055 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
1057 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
1062 i++;
1063
1064 }
1065 }
1066
1067 //set unavailable headings to 100;
1068 i = 0;
1069 for (int i1 = 0; i1 < size_matrix[0]; i1++) {
1070 for (int i3 = 0; i3 < size_matrix[2]; i3++) {
1071 for (int i2 = 0; i2 < 4; i2++) {
1072 if (stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0]*size_matrix[2] + i3] > min_disparity) {
1073 distance_est = (baseline * (float)focal / ((float)stereocam_data.data[i1 * size_matrix[1] + i2 * size_matrix[0] *
1074 size_matrix[2] + i3]) - 18.0) / 1000;
1075
1078 }
1079
1080 diff_available_heading[i] = 100;
1081 for (int i_diff = -number_of_buffer; i_diff <= number_of_buffer + 1; i_diff++) {
1082 i_buffer = i + i_diff;
1083
1084
1085 if (i_buffer < 1) {
1087 }
1088
1089 if (i_buffer > size_matrix[0]*size_matrix[2]) {
1091 }
1092
1094 }
1095
1096 }
1097 }
1098 i++;
1099 }
1100 }
1101
1102 //set bias
1103 if (set_bias == 1) {
1104 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
1105 if (diff_available_heading[i100] <= 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
1107 }
1108 }
1109 } else if (set_bias == 2) {
1110 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
1111 if (diff_available_heading[i100] > 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
1113 }
1114 }
1115 }
1116
1117 // select minimum available heading
1118 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
1122 }
1123 }
1124
1125 if (obstacle_flag == 0 && distance_heading > 2.0) {
1127 } else if (obstacle_flag == 0 && fabs(new_heading_diff) > (2 * M_PI / 36.0)) {
1128 obstacle_flag = 1;
1129 if (new_heading_diff > 0) {
1130 set_bias = 1;
1131 direction = -1;
1132 } else if (new_heading_diff <= 0) {
1133 set_bias = 2;
1134 direction = 1;
1135 }
1136 }
1137
1138 // Rotate waypoint
1139 if (fabs(new_heading_diff) >= 0.5 * M_PI) {
1141 }
1142
1143 if (fabs(new_heading_diff) <= (2 * M_PI / 36.0)) {
1144 if (waypoint_rot == 0) {
1145 obstacle_flag = 0;
1146 set_bias = 0;
1147 } else {
1149 }
1150 }
1151
1152 //vref_max should be low
1154 if (speed_pot <= 0) {
1155 speed_pot = 0;
1156 }
1157
1161
1162#if PRINT_STUFF
1163 for (int i100 = 0; i100 < (size_matrix[0]*size_matrix[2]); i100++) {
1164 printf("%i diff_available_heading: %f available_heading: %f \n", i100, diff_available_heading[i100],
1166 }
1167 printf("new_heading: %f current_heading: %f speed_pot: %f\n", new_heading, stateGetNedToBodyEulers_f()->psi,
1168 speed_pot);
1169 printf("set_bias: %i obstacle_flag: %i", set_bias, obstacle_flag);
1170#endif
1171
1172}
1173
1174
float r
in rad/s
float psi
in radians
#define FLOAT_ANGLE_NORMALIZE(_a)
#define VECT3_SMUL(_vo, _vi, _s)
#define VECT3_COPY(_a, _b)
#define VECT3_ADD(_a, _b)
#define VECT2_NORM2(_v)
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
Definition state.h:839
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
Definition state.h:1367
float alpha_fil
float r_dot_new
float new_heading
float vref_max
Definition guidance_OA.c:99
float speed_pot
oa_method OA_method_flag
Definition guidance_OA.c:96
float ref_pitch
int8_t repulsionforce_filter_flag
Definition guidance_OA.c:94
float ref_roll
Guidance for the obstacle avoidance methods.
@ SAFETYZONE
Definition guidance_OA.h:52
@ LOGICBASED
Definition guidance_OA.h:52
@ PINGPONG
Definition guidance_OA.h:52
@ POT_VEL
Definition guidance_OA.h:52
@ POT_HEADING
Definition guidance_OA.h:52
uint16_t foo
Definition main_demo5.c:58
Definition point.c:84
float ref_yaw
float stereo_fow[2]
void CN_matrix_Kalman_filter(void)
uint8_t escape_flag
float b_damp
float c4_oa
float heading_goal_f
float B_kal
struct FloatVect2 pos_diff
float c3_oa
struct FloatVect2 target
float epsilon
void CN_potential_velocity(void)
float dx_ref
float K_gain_send
float dy_ref
float waypoint_rot
void CN_potential_heading(void)
float Q_kal
struct FloatVect3 Repulsionforce_Kan
float Kg
void serial_update(void)
void CN_vector_velocity(void)
void matrix_2_pingpong(float *distancesMeters, uint16_t *size_matrix_local, float *distances_hor_local)
uint8_t point_index
struct FloatVect3 Repulsionforce_Kan_old
#define AVOIDANCE_AMOUNT_OF_BOARDS
struct FloatVect2 init_target
void setAnglesMeasurements(float *anglesMeasurements, float *centersensorRad, float *fieldOfViewRad, uint16_t *size_matrix_local)
float reference_roll
float V_hys_high
float F2
#define AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES
int8_t dis_treshold
float H_kal
float Pest_new[AVOIDANCE_AMOUNT_OF_BOARDS *AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES *AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES]
float baseline
struct FloatVect3 Repulsionforce_Kan_send
uint8_t hysteris_flag
float Cfreq
#define AVOIDANCES_DISTANCES_HOR_COUNT
float V_hys_low
float K_obst
float v_min
struct NedCoor_f current_pos
float Ko
float kv
uint8_t set_bias
float c2_oa
float vmin
float c5_oa
uint8_t obstacle_flag
struct FloatVect3 Attractforce_goal
struct FloatVect3 Repulsionforce_Used
float heading_goal_ref
struct FloatVect3 filter_repforce_old
float c1_oa
uint8_t direction
int16_t focal
float K_goal
void CN_escape_velocity(void)
uint16_t size_matrix[]
void pingpong_euler(float *distances_hor_local, float *horizontalAnglesMeasurements, int horizontalAmountOfMeasurements, float attitude_reference_pitch, float attitude_reference_roll, float dist_treshold_local)
float v_max
void serial_init(void)
#define AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES
float F1
void CN_matrix_butterworth(void)
struct FloatVect3 Attractforce_goal_send
uint8_t * READimageBuffer_old
void serial_start(void)
float new_heading_old
float A_kal
float butter_old[AVOIDANCE_AMOUNT_OF_BOARDS *AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES *AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES]
float reference_pitch
float Dist_offset
float distances_hor[AVOIDANCES_DISTANCES_HOR_COUNT]
float dist_treshold
void CN_vector_escape_velocity(void)
float Xest_new[AVOIDANCE_AMOUNT_OF_BOARDS *AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES *AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES]
float angle_hor_board[]
void CN_calculate_target(void)
float R_kal
Obstacle avoidance methods.
Paparazzi floating point algebra.
float x
in meters
float y
in meters
vector in North East Down coordinates Units: meters
Paparazzi fixed point math for geodetic calculations.
API to get/set the generic vehicle states.
interface to the TU Delft serial stereocam
Periodic telemetry system header (includes downlink utility and generated code).
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.
int min_disparity
Block size used for the block matching (SBM) function.
Definition wedgebug.c:257