@@ -379,61 +379,37 @@ void Head::scan_custom(control::Command scan_type)
379
379
process ();
380
380
}
381
381
382
- double Head::calculate_distance_from_pan_tilt (double pan, double tilt)
383
- {
384
- double distance = 0.0 ;
385
-
386
- for (int i = 6 ; i >= 0 ; --i) {
387
- for (int j = 0 ; j <= i; ++j) {
388
- double x1 = pow ((pan + pan_center + pan_offset), (i - j));
389
- double x2 = pow ((tilt + tilt_center + tilt_offset), j);
390
- distance += (pan_tilt_to_distance_[i - j][j]) * x1 * x2;
391
- } // action_->playUntilStop(motion_manager_->WALKREADY);
392
- }
393
-
394
- return (distance > 0.0 ) ? distance : 0.0 ;
395
- }
396
-
397
- double Head::calculate_distance_from_pan_tilt_using_regression (double pan, double tilt)
382
+ double Head::calculate_distance_from_pan_tilt ()
398
383
{
399
384
double distance = 0.0 ;
385
+ double pan = get_pan_angle ();
386
+ double tilt = get_tilt_angle ();
400
387
int coef_index = 0 ;
401
- for (int i = 0 ; i < pan_tilt_to_dist_coefficients_ .size (); i++)
388
+ for (int i = 0 ; i < pan_tilt_to_dist_coefficients .size (); i++)
402
389
{
403
- double x1 = pow ((pan + pan_offset), pan_tilt_to_dist_degress_[i][0 ]);
404
- double x2 = pow ((tilt + tilt_offset), pan_tilt_to_dist_degress_[i][1 ]);
405
-
406
- distance += pan_tilt_to_dist_coefficients_[coef_index++] * x1 * x2;
407
- }
390
+ double x1 = pow ((pan + pan_offset), distance_regression_degrees[i][0 ]);
391
+ double x2 = pow ((tilt + tilt_offset), distance_regression_degrees[i][1 ]);
408
392
409
- return (distance > 0.0 ) ? distance : 0.0 ;
410
- }
411
-
412
- double Head::calculate_distance_from_tilt (double tilt)
413
- {
414
- double distance = 0.0 ;
415
-
416
- for (int i = 0 ; i <= 4 ; ++i) {
417
- double x2 = pow ((tilt + tilt_center + tilt_offset), i);
418
- distance += (tilt_to_distance_[i]) * x2;
393
+ distance += pan_tilt_to_dist_coefficients[coef_index++] * x1 * x2;
419
394
}
420
395
421
396
return (distance > 0.0 ) ? distance : 0.0 ;
422
397
}
423
398
424
- double Head::calculate_tilt_from_pan_distance (double pan, double distance)
399
+ double Head::calculate_tilt_from_pan_distance (double distance)
425
400
{
426
401
double tilt = 0.0 ;
402
+ double pan = get_pan_angle ();
403
+ int coef_index = 0 ;
404
+ for (int i = 0 ; i < pan_distance_to_tilt_coefficients.size (); i++)
405
+ {
406
+ double x1 = pow ((pan + pan_offset), distance_regression_degrees[i][0 ]);
407
+ double x2 = pow ((tilt + tilt_offset), distance_regression_degrees[i][1 ]);
427
408
428
- for (int i = 4 ; i >= 0 ; --i) {
429
- for (int j = 0 ; j <= i; ++j) {
430
- double x1 = pow ((pan + pan_center + pan_offset), (i - j));
431
- double x2 = pow (distance, j);
432
- tilt += (pan_distance_to_tilt_[i - j][j]) * x1 * x2;
433
- }
409
+ tilt += pan_distance_to_tilt_coefficients[coef_index++] * x1 * x2;
434
410
}
435
411
436
- return (( tilt < 15.0 ) ? tilt : 15.0 ) - tilt_center - tilt_offset ;
412
+ return tilt;
437
413
}
438
414
439
415
void Head::look_to_position (double goal_position_x, double goal_position_y)
@@ -444,7 +420,7 @@ void Head::look_to_position(double goal_position_x, double goal_position_y)
444
420
float dy = goal_position_y - robot_position_y;
445
421
446
422
float pan = yaw - keisan::signed_arctan (dy, dx).normalize ().degree ();
447
- float tilt = calculate_tilt_from_pan_distance (keisan::signed_arctan (dy, dx). degree ( ));
423
+ float tilt = calculate_tilt_from_pan_distance (std::hypot (dx, dy ));
448
424
449
425
move_by_angle (pan - pan_center, tilt);
450
426
}
@@ -510,10 +486,11 @@ void Head::load_config(const std::string & file_name)
510
486
std::cerr << " parse error at byte " << ex.byte << std::endl;
511
487
throw ex;
512
488
}
513
- } else if (key == " PanTiltToDistanceRegression " ) {
489
+ } else if (key == " DistanceRegression " ) {
514
490
try {
515
- val.at (" distance_polynomial_coefficients" ).get_to (pan_tilt_to_dist_coefficients_);
516
- val.at (" distance_polynomial_degrees" ).get_to (pan_tilt_to_dist_degress_);
491
+ val.at (" distance_polynomial_coefficients" ).get_to (pan_tilt_to_dist_coefficients);
492
+ val.at (" tilt_polynomial_coefficients" ).get_to (pan_distance_to_tilt_coefficients);
493
+ val.at (" distance_polynomial_degrees" ).get_to (distance_regression_degrees);
517
494
} catch (nlohmann::json::parse_error & ex) {
518
495
std::cerr << " parse error at byte " << ex.byte << std::endl;
519
496
throw ex;
@@ -526,43 +503,6 @@ void Head::load_config(const std::string & file_name)
526
503
std::cerr << " parse error at byte " << ex.byte << std::endl;
527
504
throw ex;
528
505
}
529
- } else if (key == " PanTiltToDistance" ) {
530
- try {
531
- for (int i = 6 ; i >= 0 ; --i) {
532
- for (int j = 0 ; j <= i; ++j) {
533
- char buffer[32 ];
534
- snprintf (buffer, sizeof (buffer), " pan_%d_tilt_%d" , (i - j), j);
535
- val.at (buffer).get_to (pan_tilt_to_distance_[i - j][j]);
536
- }
537
- }
538
- } catch (nlohmann::json::parse_error & ex) {
539
- std::cerr << " parse error at byte " << ex.byte << std::endl;
540
- throw ex;
541
- }
542
- } else if (key == " TiltToDistance" ) {
543
- try {
544
- for (int i = 0 ; i <= 4 ; ++i) {
545
- char buffer[32 ];
546
- snprintf (buffer, sizeof (buffer), " pan_%d_tilt_%d" , 0 , i);
547
- val.at (buffer).get_to (tilt_to_distance_[i]);
548
- }
549
- } catch (nlohmann::json::parse_error & ex) {
550
- std::cerr << " parse error at byte " << ex.byte << std::endl;
551
- throw ex;
552
- }
553
- } else if (key == " PanDistanceToTilt" ) {
554
- try {
555
- for (int i = 4 ; i >= 0 ; --i) {
556
- for (int j = 0 ; j <= i; ++j) {
557
- char buffer[32 ];
558
- snprintf (buffer, sizeof (buffer), " pan_%d_distance_%d" , (i - j), j);
559
- val.at (buffer).get_to (pan_distance_to_tilt_[i - j][j]);
560
- }
561
- }
562
- } catch (nlohmann::json::parse_error & ex) {
563
- std::cerr << " parse error at byte " << ex.byte << std::endl;
564
- throw ex;
565
- }
566
506
}
567
507
}
568
508
} catch (nlohmann::json::parse_error & ex) {
@@ -673,9 +613,9 @@ keisan::Point2 Head::calculate_object_position_from_pixel(double pixel_x, double
673
613
// calculate object distance from pixels and center distance
674
614
double horizontal_degree = horizontal_fov * pixel_x;
675
615
double vertical_degree = vertical_fov * pixel_y;
676
- double center_real_distance = is_ball ? Head::calculate_distance_from_pan_tilt_using_regression () : Head::calculate_distance_from_pan_tilt_using_regression () + 7 ;
616
+ double center_real_distance = is_ball ? Head::calculate_distance_from_pan_tilt () : Head::calculate_distance_from_pan_tilt () + 7 ;
677
617
678
- if (Head::calculate_distance_from_pan_tilt_using_regression () > -1 ) {
618
+ if (Head::calculate_distance_from_pan_tilt () > -1 ) {
679
619
double camera_height = center_real_distance / keisan::make_radian ((90 + Head::get_tilt_angle ())).tan ();
680
620
double x_relative_from_camera = camera_height * keisan::make_radian ((90 + Head::get_tilt_angle () - vertical_degree)).tan ();
681
621
double y_relative_from_camera = x_relative_from_camera * keisan::make_radian (horizontal_degree).tan ();
0 commit comments