Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Camera_servo: allow focus and zoom control #29247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions libraries/AP_Camera/AP_Camera_Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

extern const AP_HAL::HAL& hal;


void AP_Camera_Servo::init() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too let's put a comment and put the bracket on the next line

SRV_Channels::set_output_scaled(SRV_Channel::k_cam_zoom, 500);
SRV_Channels::set_output_scaled(SRV_Channel::k_cam_focus, 500);
}

// update - should be called at 50hz
void AP_Camera_Servo::update()
{
Expand Down Expand Up @@ -43,6 +49,28 @@ bool AP_Camera_Servo::trigger_pic()
return true;
}


bool AP_Camera_Servo::set_zoom(ZoomType zoom_type, float zoom_value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, thanks for this. Small nitpick is in the cpp files we put the bracket on the next line

if (zoom_type == ZoomType::RATE) {
float current_zoom = SRV_Channels::get_output_scaled(SRV_Channel::k_cam_zoom);
float new_zoom = constrain_float(current_zoom + zoom_value * 10, 0, 1000);
SRV_Channels::set_output_scaled(SRV_Channel::k_cam_zoom, new_zoom);
return true;
}
return false;
}

// set focus specified as rate
SetFocusResult AP_Camera_Servo::set_focus(FocusType focus_type, float focus_value) {
if (focus_type == FocusType::RATE) {
const float current_focus = SRV_Channels::get_output_scaled(SRV_Channel::k_cam_focus);
const float new_focus = constrain_float(current_focus + focus_value * 10, 0, 1000);
SRV_Channels::set_output_scaled(SRV_Channel::k_cam_focus, new_focus);
return SetFocusResult::ACCEPTED;
}
return SetFocusResult::UNSUPPORTED;
}

// configure camera
void AP_Camera_Servo::configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time)
{
Expand Down
8 changes: 8 additions & 0 deletions libraries/AP_Camera/AP_Camera_Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ class AP_Camera_Servo : public AP_Camera_Backend
// Constructor
using AP_Camera_Backend::AP_Camera_Backend;

void init() override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put the init lower like it is in other drivers. Also if possible can we put a comment above it? I know it's pretty obvious what "init" is for but all our other methods have comments so I'd like to keep it consistent

/* Do not allow copies */
CLASS_NO_COPY(AP_Camera_Servo);

// update - should be called at 50hz
void update() override;

// set zoom specified as a rate or percentage
bool set_zoom(ZoomType zoom_type, float zoom_value) override;

// set focus specified as rate, percentage or auto
// focus in = -1, focus hold = 0, focus out = 1
SetFocusResult set_focus(FocusType focus_type, float focus_value) override;

// entry point to actually take a picture. returns true on success
bool trigger_pic() override;

Expand Down
1 change: 1 addition & 0 deletions libraries/SRV_Channel/SRV_Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class SRV_Channel {
k_motor30 = 177,
k_motor31 = 178,
k_motor32 = 179,
k_cam_zoom = 180,
k_nr_aux_servo_functions ///< This must be the last enum value (only add new values _before_ this one)
} Function;

Expand Down
4 changes: 4 additions & 0 deletions libraries/SRV_Channel/SRV_Channel_aux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ void SRV_Channel::aux_servo_function_setup(void)
// fixed wing throttle
set_range(100);
break;
case k_cam_zoom:
case k_cam_focus:
set_range(1000);
break;
default:
break;
}
Expand Down
Loading