-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,12 @@ | |
|
||
extern const AP_HAL::HAL& hal; | ||
|
||
|
||
void AP_Camera_Servo::init() { | ||
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() | ||
{ | ||
|
@@ -43,6 +49,28 @@ bool AP_Camera_Servo::trigger_pic() | |
return true; | ||
} | ||
|
||
|
||
bool AP_Camera_Servo::set_zoom(ZoomType zoom_type, float zoom_value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,20 @@ class AP_Camera_Servo : public AP_Camera_Backend | |
// Constructor | ||
using AP_Camera_Backend::AP_Camera_Backend; | ||
|
||
void init() override; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
There was a problem hiding this comment.
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