28 #include <sys/fcntl.h>
40 #ifndef AVOIDANCES_DISTANCES_HOR_COUNT
41 #define AVOIDANCES_DISTANCES_HOR_COUNT 36
44 #ifndef AVOIDANCE_AMOUNT_OF_BOARDS
45 #define AVOIDANCE_AMOUNT_OF_BOARDS 6
48 #ifndef AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES
49 #define AVOIDANCE_HEIGHT_IN_MEASUREMENT_VALUES 6
52 #ifndef AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES
53 #define AVOIDANCE_WIDTH_IN_MEASUREMENT_VALUES 6
168 for (
int i1 = 0; i1 < size_matrix_local[0]; i1++) {
169 for (
int i3 = 0; i3 < size_matrix_local[2]; i3++) {
170 anglesMeasurements[i1 * size_matrix_local[0] + i3] = centersensorRad[i1] - 0.5 * fieldOfViewRad[0] + fieldOfViewRad[0] /
171 size_matrix_local[2] / 2 + (fieldOfViewRad[0] / size_matrix_local[2]) * i3;
178 if (stereocam_data.fresh) {
179 printf(
"Stereo fresh: %i \n", stereocam_data.len);
181 float distancesMeters[stereocam_data.len];
182 float anglesMeasurements[stereocam_data.matrix_width];
196 stereocam_disparity_to_meters(stereocam_data.data, distancesMeters, stereocam_data.len);
226 stereocam_data.fresh = 0;
227 if (stereocam_data.len > 50) {
242 for (
int i_m = 0; i_m < size_matrix_local[0]; i_m++) {
243 for (
int i_m3 = 0; i_m3 < size_matrix_local[2]; i_m3++) {
244 distances_hor_local[i_m * size_matrix_local[2] + i_m3] = 10000;
245 distances_hor_local_new[i_m * size_matrix_local[2] + i_m3] = 10000;
246 for (
int i_m2 = 0; i_m2 < 4; i_m2++) {
247 if (distancesMeters[i_m * size_matrix_local[1] + i_m2 * size_matrix_local[0]*size_matrix_local[2] + i_m3] <
248 distances_hor_local[i_m * size_matrix_local[2] + i_m3]) {
249 distances_hor_local_old[i_m * size_matrix_local[2] + i_m3] = distances_hor_local_new[i_m * size_matrix_local[2] + i_m3];
250 distances_hor_local_new[i_m * size_matrix_local[2] + i_m3] = distancesMeters[i_m * size_matrix_local[1] + i_m2 *
251 size_matrix_local[0] * size_matrix_local[2] + i_m3];
253 distances_hor_local[i_m * size_matrix_local[2] + i_m3] = (distances_hor_local_old[i_m * size_matrix_local[2] + i_m3] +
254 distances_hor_local_new[i_m * size_matrix_local[2] + i_m3]) / 2;
279 Xpred_new[i_k] =
A_kal * Xest_old[i_k];
288 Xest_new[i_k] = Xpred_new[i_k] + K_gain[i_k] * (float)(stereocam_data.data[i_k] -
H_kal * Xpred_new[i_k]);
298 float A_butter = -0.7265;
299 float B_butter[2] = {0.1367, 0.1367};
310 butter[i_k] = B_butter[0] * (float)stereocam_data.data[i_k] + B_butter[1] * (
float)
READimageBuffer_old[i_k] - A_butter *
326 float s_psi = sin(psi);
327 float c_psi = cos(psi);
357 void pingpong_euler(
float *distances_hor_local,
float *horizontalAnglesMeasurements,
int horizontalAmountOfMeasurements,
358 float attitude_reference_pitch,
float attitude_reference_roll,
float dist_treshold_local)
362 float sumPitch = 0.0;
365 float oa_pitch_angle[horizontalAmountOfMeasurements];
366 float oa_roll_angle[horizontalAmountOfMeasurements];
368 for (
int horizontal_index = 0; horizontal_index < horizontalAmountOfMeasurements; horizontal_index++) {
371 if (distances_hor_local[horizontal_index] < dist_treshold_local) {
373 oa_pitch_angle[horizontal_index] = cos(horizontalAnglesMeasurements[horizontal_index]) * attitude_reference_pitch;
374 oa_roll_angle[horizontal_index] = -sin(horizontalAnglesMeasurements[horizontal_index]) * attitude_reference_roll;
375 sumPitch += oa_pitch_angle[horizontal_index];
376 sumRoll += oa_roll_angle[horizontal_index];
381 if (sumPitch > attitude_reference_pitch) {
383 }
else if (sumPitch < -attitude_reference_pitch) {
390 if (sumRoll > attitude_reference_roll) {
392 }
else if (sumRoll < -attitude_reference_roll) {
393 ref_roll = -attitude_reference_roll;
410 float potential_obst = 0;
411 float potential_obst_temp = 0;
412 float potential_obst_integrated = 0;
417 float obst_count = 0.0;
453 potential_obst_temp = 0.0;
456 for (
int i2 = 0; i2 < 4; i2++) {
463 angle_hor_abs = -1 * angle_hor;
465 angle_hor_abs = angle_hor;
467 potential_obst_temp = potential_obst_temp -
K_obst * (angle_hor) * exp(-
c3_oa * angle_hor_abs) * exp(
468 -
c4_oa * Distance_est);
469 potential_obst_integrated = potential_obst_integrated +
K_obst *
c3_oa * (fabs(angle_hor) + 1) / (
c3_oa *
c3_oa) * exp(
470 -
c3_oa * fabs(angle_hor)) * exp(-
c4_oa * Distance_est);
483 if (obst_count != 0) {
484 potential_obst = potential_obst + potential_obst_temp / ((float)obst_count);
508 float OF_Result_Vy = 0;
509 float OF_Result_Vx = 0;
516 float potential_obst = 0;
517 float potential_obst_integrated = 0;
522 float current_heading;
535 total_vel = pow((OF_Result_Vy * OF_Result_Vy + OF_Result_Vx * OF_Result_Vx), 0.5);
537 if (total_vel >
vmin) {
538 fp_angle = atan2(OF_Result_Vx, OF_Result_Vy);
562 diff_angle = fp_angle - angle_hor;
564 potential_obst = potential_obst +
K_obst * (diff_angle) * exp(-
c3_oa * fabs(diff_angle)) * exp(
565 -
c4_oa * Distance_est);
566 potential_obst_integrated = potential_obst_integrated +
K_obst *
c3_oa * (fabs(diff_angle) + 1) / (
c3_oa *
c3_oa) * exp(
567 -
c3_oa * fabs(diff_angle)) * exp(-
c4_oa * Distance_est);
595 float A_butter = -0.8541;
596 float B_butter[2] = {0.0730 , 0.0730 };
600 float escape_angle = 0;
662 for (
int i2 = 0; i2 < 4; i2++) {
677 2) * cos(angle_hor) * cos(angle_ver);
679 2) * sin(angle_hor) * cos(angle_ver);
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,
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;
769 printf(
"ref_pitch: %f ref_roll: %f disp_count: %d",
ref_pitch,
ref_roll, disp_count);
783 float A_butter = -0.8541;
784 float B_butter[2] = {0.0730 , 0.0730 };
806 int8_t number_of_buffer = 20;
807 float bias = 2 * M_PI;
812 float new_heading_diff = 1000;
836 for (
int i2 = 0; i2 < 4; i2++) {
852 2) * cos(angle_hor) * cos(angle_ver);
854 2) * sin(angle_hor) * cos(angle_ver);
902 V_total = sqrt(pow(Total_Kan.
x, 2) + pow(Total_Kan.
y, 2));
912 printf(
"V_total: %f", V_total);
926 available_heading[i] = angle_hor;
937 for (
int i2 = 0; i2 < 4; i2++) {
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;
954 diff_available_heading[i_buffer] = 100;
965 if (diff_available_heading[i100] <= 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
966 diff_available_heading[i100] = diff_available_heading[i100] - bias;
971 if (diff_available_heading[i100] > 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
972 diff_available_heading[i100] = diff_available_heading[i100] + bias;
978 if (fabs(diff_available_heading[i100]) < fabs(new_heading_diff)) {
979 new_heading_diff = diff_available_heading[i100];
984 if (
obstacle_flag == 0 && fabs(new_heading_diff) > (2 * M_PI / 36.0)) {
986 if (new_heading_diff > 0) {
989 }
else if (new_heading_diff <= 0) {
995 if (fabs(new_heading_diff) <= (2 * M_PI / 36.0)) {
1004 if (fabs(new_heading_diff) >= 0.5 * M_PI) {
1018 printf(
"%i diff_available_heading: %f available_heading: %f \n", i100, diff_available_heading[i100],
1019 available_heading[i100]);
1037 int8_t number_of_buffer = 20;
1038 float bias = 2 * M_PI;
1042 float angle_hor = 0;
1045 float new_heading_diff = 1000;
1050 float distance_heading = 0;
1059 available_heading[i] = angle_hor;
1071 for (
int i2 = 0; i2 < 4; i2++) {
1076 if (distance_est < distance_heading) {
1077 distance_heading = distance_est;
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;
1093 diff_available_heading[i_buffer] = 100;
1105 if (diff_available_heading[i100] <= 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
1106 diff_available_heading[i100] = diff_available_heading[i100] - bias;
1111 if (diff_available_heading[i100] > 0 && (fabs(diff_available_heading[i100]) < M_PI - 5.0 / 360.0 * 2.0 * M_PI)) {
1112 diff_available_heading[i100] = diff_available_heading[i100] + bias;
1119 if (fabs(diff_available_heading[i100]) < fabs(new_heading_diff)) {
1120 new_heading_diff = diff_available_heading[i100];
1127 }
else if (
obstacle_flag == 0 && fabs(new_heading_diff) > (2 * M_PI / 36.0)) {
1129 if (new_heading_diff > 0) {
1132 }
else if (new_heading_diff <= 0) {
1139 if (fabs(new_heading_diff) >= 0.5 * M_PI) {
1143 if (fabs(new_heading_diff) <= (2 * M_PI / 36.0)) {
1164 printf(
"%i diff_available_heading: %f available_heading: %f \n", i100, diff_available_heading[i100],
1165 available_heading[i100]);