Skip to content

Commit

Permalink
Handle continuous zoom (#488)
Browse files Browse the repository at this point in the history
This commits adds a iterator for zoom so that it can handle continuous zoom controls for MAV_CMD_SET_CAMERA_ZOOM message
  • Loading branch information
Jaeyoung-Lim authored May 11, 2020
1 parent dab2eba commit 0b348fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/gazebo_geotagged_images_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class GAZEBO_VISIBLE GeotaggedImagesPlugin : public SensorPlugin
int _captureCount;
double _captureInterval;
int _fd;
int _zoom_cmd;

enum {
CAPTURE_DISABLED,
Expand Down
18 changes: 16 additions & 2 deletions src/gazebo_geotagged_images_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ GeotaggedImagesPlugin::GeotaggedImagesPlugin()
, _hfov(1.57)
, _zoom(1.0)
, _maxZoom(8.0)
, _zoom_cmd(0)
{
}

Expand Down Expand Up @@ -428,6 +429,14 @@ void GeotaggedImagesPlugin::cameraThread() {
_last_heartbeat = current_time;
_send_heartbeat();
}

//Move camera zoom incase of continuous zoom
// _zoom_cmd is set by MAV_CMD_SET_CAMERA_ZOOM
if (_zoom_cmd!=0) {
_zoom = std::max(std::min(float(_zoom + 0.05 * _zoom_cmd), _maxZoom), 1.0f);
_camera->SetHFOV(_hfov / _zoom);
}

}
}

Expand Down Expand Up @@ -689,8 +698,13 @@ void GeotaggedImagesPlugin::_handle_camera_zoom(const mavlink_message_t *pMsg, s
_send_cmd_ack(pMsg->sysid, pMsg->compid,
MAV_CMD_SET_CAMERA_ZOOM, MAV_RESULT_ACCEPTED, srcaddr);

_zoom = std::max(std::min(float(_zoom + 0.1 * cmd.param2), _maxZoom), 1.0f);
_camera->SetHFOV(_hfov / _zoom);
if (cmd.param1 == ZOOM_TYPE_CONTINUOUS) {
_zoom = std::max(std::min(float(_zoom + 0.1 * cmd.param2), _maxZoom), 1.0f);
_zoom_cmd = cmd.param2;
} else {
_zoom = std::max(std::min(float(_zoom + 0.1 * cmd.param2), _maxZoom), 1.0f);
_camera->SetHFOV(_hfov / _zoom);
}
}

void GeotaggedImagesPlugin::_send_capture_status(struct sockaddr* srcaddr)
Expand Down

0 comments on commit 0b348fd

Please sign in to comment.