Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //incoming serial data from tracking (error from center)
- error_from_center_x
- error_from_center_y
- const int32_t frame_width(1280);
- const int32_t frame_height(720);
- double MAX_VELOCITY_VALUE_X = (frame_width * 0.75);
- double MAX_VELOCITY_VALUE_Y = (frame_height * 0.75);
- double delta_x = ((double)(error_from_center_x + joystick_x) - ((double)frame_width / 2)) / ((double)frame_width / 2);
- double delta_y = ((double)(error_from_center_y + joystick_y) - ((double)frame_height / 2)) / ((double)frame_height / 2);
- if (delta_x > 0)
- delta_x = (delta_x * delta_x);
- else
- delta_x = -(delta_x * delta_x);
- if (delta_y > 0)
- delta_y = (delta_y * delta_y);
- else
- delta_y = -(delta_y * delta_y);
- double speed_coeff = (double)zoom_position / (1638.0 * 2.5);
- if (speed_coeff == 0)
- speed_coeff = 1.0;
- else
- speed_coeff = 1 / speed_coeff;
- delta_x = MAX_VELOCITY_VALUE_X * (delta_x * speed_coeff);
- delta_y = MAX_VELOCITY_VALUE_Y * (delta_y * speed_coeff);
- const double check_offset(420);
- if (delta_x > check_offset) { delta_x = check_offset; }
- if (delta_x < -check_offset) { delta_x = -check_offset; }
- if (delta_y > check_offset) { delta_y = check_offset; }
- if (delta_y < -check_offset) { delta_y = -check_offset; }
- int16_t tmp_pan_value = ((int16_t)delta_x);
- int16_t tmp_tilt_value = ((int16_t)delta_y);
- uint8_t gimbal_move_command[20];
- gimbal_move_command[0] = 0x3E;
- gimbal_move_command[1] = 0x43;
- gimbal_move_command[2] = 0x0F;
- gimbal_move_command[3] = 0x52;
- gimbal_move_command[4] = 0x00;
- gimbal_move_command[5] = 0x01;
- gimbal_move_command[6] = 0x01;
- gimbal_move_command[7] = 0x00;
- gimbal_move_command[8] = 0x00;
- gimbal_move_command[9] = 0x00;
- gimbal_move_command[10] = 0x00;
- memcpy(&gimbal_move_command[11], &tmp_tilt_value, 2);
- gimbal_move_command[13] = 0x00;
- gimbal_move_command[14] = 0x00;
- memcpy(&gimbal_move_command[15], &tmp_pan_value, 2);
- gimbal_move_command[17] = 0x00;
- gimbal_move_command[18] = 0x00;
- gimbal_move_command[19] = gimbal_move_command[5] +
- gimbal_move_command[6] +
- gimbal_move_command[11] +
- gimbal_move_command[12] +
- gimbal_move_command[15] +
- gimbal_move_command[16];
- basecam_serial.write(gimbal_move_command, sizeof(gimbal_move_command));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement