Sub: Constrain camera tilt goal to servo output limits

This commit is contained in:
Jacob Walser 2016-11-23 19:27:24 -05:00 committed by Andrew Tridgell
parent 0faf2a1f8e
commit 9ef9afd26d
1 changed files with 30 additions and 6 deletions

View File

@ -8,8 +8,8 @@
// Anonymous namespace to hold variables used only in this file // Anonymous namespace to hold variables used only in this file
namespace { namespace {
int16_t mode = 1100; int16_t mode = 1100;
int16_t cam_tilt = 1500; float cam_tilt = 1500.0;
int16_t cam_tilt_goal = 1500; float cam_tilt_goal = 1500.0;
float cam_tilt_alpha = 0.97; float cam_tilt_alpha = 0.97;
int16_t lights1 = 1100; int16_t lights1 = 1100;
int16_t lights2 = 1100; int16_t lights2 = 1100;
@ -131,11 +131,35 @@ void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held) {
case JSButton::button_function_t::k_mount_center: case JSButton::button_function_t::k_mount_center:
cam_tilt_goal = 1500; cam_tilt_goal = 1500;
break; break;
case JSButton::button_function_t::k_mount_tilt_up: case JSButton::button_function_t::k_mount_tilt_up: {
cam_tilt_goal = constrain_float(cam_tilt_goal-g.cam_tilt_step,800,2200); uint8_t i;
// Find the first aux channel configured as mount tilt, if any
if(RC_Channel_aux::find_channel(RC_Channel_aux::k_mount_tilt, i)) {
// Get the channel output limits
RC_Channel *ch = RC_Channel::rc_channel(i);
uint16_t min = ch->get_limit_pwm(RC_Channel::RC_CHANNEL_LIMIT_MIN);
uint16_t max = ch->get_limit_pwm(RC_Channel::RC_CHANNEL_LIMIT_MAX);
cam_tilt_goal = constrain_int16(cam_tilt_goal-g.cam_tilt_step,min,max);
}
}
break; break;
case JSButton::button_function_t::k_mount_tilt_down: case JSButton::button_function_t::k_mount_tilt_down: {
cam_tilt_goal = constrain_float(cam_tilt_goal+g.cam_tilt_step,800,2200); uint8_t i;
// Find the first aux channel configured as mount tilt, if any
if(RC_Channel_aux::find_channel(RC_Channel_aux::k_mount_tilt, i)) {
// Get the channel output limits
RC_Channel *ch = RC_Channel::rc_channel(i);
uint16_t min = ch->get_limit_pwm(RC_Channel::RC_CHANNEL_LIMIT_MIN);
uint16_t max = ch->get_limit_pwm(RC_Channel::RC_CHANNEL_LIMIT_MAX);
cam_tilt_goal = constrain_int16(cam_tilt_goal+g.cam_tilt_step,min,max);
}
}
break; break;
case JSButton::button_function_t::k_camera_trigger: case JSButton::button_function_t::k_camera_trigger:
break; break;