Advertisement
Guest User

Untitled

a guest
Apr 8th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. //incoming serial data from tracking (error from center)
  2. error_from_center_x
  3. error_from_center_y
  4.  
  5. const int32_t frame_width(1280);
  6. const int32_t frame_height(720);
  7.  
  8. double MAX_VELOCITY_VALUE_X = (frame_width * 0.75);
  9. double MAX_VELOCITY_VALUE_Y = (frame_height * 0.75);
  10.  
  11. double delta_x = ((double)(error_from_center_x + joystick_x) - ((double)frame_width / 2)) / ((double)frame_width / 2);
  12. double delta_y = ((double)(error_from_center_y + joystick_y) - ((double)frame_height / 2)) / ((double)frame_height / 2);
  13.  
  14. if (delta_x > 0)
  15.   delta_x = (delta_x * delta_x);
  16. else
  17.   delta_x = -(delta_x * delta_x);
  18.  
  19. if (delta_y > 0)
  20.   delta_y = (delta_y * delta_y);
  21. else
  22.   delta_y = -(delta_y * delta_y);
  23.  
  24. double speed_coeff = (double)zoom_position / (1638.0 * 2.5);
  25. if (speed_coeff == 0)
  26.   speed_coeff = 1.0;
  27. else
  28.   speed_coeff = 1 / speed_coeff;
  29.  
  30. delta_x = MAX_VELOCITY_VALUE_X * (delta_x * speed_coeff);
  31. delta_y = MAX_VELOCITY_VALUE_Y * (delta_y * speed_coeff);
  32.  
  33. const double check_offset(420);
  34.  
  35. if (delta_x > check_offset) { delta_x = check_offset; }
  36. if (delta_x < -check_offset) { delta_x = -check_offset; }
  37. if (delta_y > check_offset) { delta_y = check_offset; }
  38. if (delta_y < -check_offset) { delta_y = -check_offset; }
  39.  
  40. int16_t tmp_pan_value = ((int16_t)delta_x);
  41. int16_t tmp_tilt_value = ((int16_t)delta_y);
  42.  
  43. uint8_t gimbal_move_command[20];
  44. gimbal_move_command[0] = 0x3E;
  45. gimbal_move_command[1] = 0x43;
  46. gimbal_move_command[2] = 0x0F;
  47. gimbal_move_command[3] = 0x52;
  48. gimbal_move_command[4] = 0x00;
  49. gimbal_move_command[5] = 0x01;
  50. gimbal_move_command[6] = 0x01;
  51. gimbal_move_command[7] = 0x00;
  52. gimbal_move_command[8] = 0x00;
  53. gimbal_move_command[9] = 0x00;
  54. gimbal_move_command[10] = 0x00;
  55. memcpy(&gimbal_move_command[11], &tmp_tilt_value, 2);
  56. gimbal_move_command[13] = 0x00;
  57. gimbal_move_command[14] = 0x00;
  58. memcpy(&gimbal_move_command[15], &tmp_pan_value, 2);
  59. gimbal_move_command[17] = 0x00;
  60. gimbal_move_command[18] = 0x00;
  61. gimbal_move_command[19] = gimbal_move_command[5] +
  62.   gimbal_move_command[6] +
  63.   gimbal_move_command[11] +
  64.   gimbal_move_command[12] +
  65.   gimbal_move_command[15] +
  66.   gimbal_move_command[16];
  67.  
  68.  
  69. basecam_serial.write(gimbal_move_command, sizeof(gimbal_move_command));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement