2012-06-13 16:00:20 -03:00
|
|
|
/// @file AP_Camera.h
|
|
|
|
/// @brief Photo or video camera manager, with EEPROM-backed storage of constants.
|
2016-02-17 21:25:17 -04:00
|
|
|
#pragma once
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Relay/AP_Relay.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2012-12-06 04:46:09 -04:00
|
|
|
#define AP_CAMERA_TRIGGER_TYPE_SERVO 0
|
|
|
|
#define AP_CAMERA_TRIGGER_TYPE_RELAY 1
|
|
|
|
|
|
|
|
#define AP_CAMERA_TRIGGER_DEFAULT_TRIGGER_TYPE AP_CAMERA_TRIGGER_TYPE_SERVO // default is to use servo to trigger camera
|
|
|
|
|
|
|
|
#define AP_CAMERA_TRIGGER_DEFAULT_DURATION 10 // default duration servo or relay is held open in 10ths of a second (i.e. 10 = 1 second)
|
|
|
|
|
|
|
|
#define AP_CAMERA_SERVO_ON_PWM 1300 // default PWM value to move servo to when shutter is activated
|
|
|
|
#define AP_CAMERA_SERVO_OFF_PWM 1100 // default PWM value to move servo to when shutter is deactivated
|
|
|
|
|
2015-06-07 14:11:30 -03:00
|
|
|
#define AP_CAMERA_FEEDBACK_DEFAULT_FEEDBACK_PIN -1 // default is to not use camera feedback pin
|
|
|
|
|
2012-06-13 16:00:20 -03:00
|
|
|
/// @class Camera
|
|
|
|
/// @brief Object managing a Photo or video camera
|
2012-08-17 03:09:29 -03:00
|
|
|
class AP_Camera {
|
2012-06-13 16:00:20 -03:00
|
|
|
|
|
|
|
public:
|
2017-12-12 21:06:11 -04:00
|
|
|
AP_Camera(AP_Relay *obj_relay, uint32_t _log_camera_bit, const struct Location &_loc, const AP_AHRS &_ahrs)
|
2018-06-19 05:19:53 -03:00
|
|
|
: log_camera_bit(_log_camera_bit)
|
2017-12-12 21:06:11 -04:00
|
|
|
, current_loc(_loc)
|
|
|
|
, ahrs(_ahrs)
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
|
|
|
_apm_relay = obj_relay;
|
2018-08-03 07:50:34 -03:00
|
|
|
_singleton = this;
|
2012-08-17 03:09:29 -03:00
|
|
|
}
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2017-08-29 15:48:37 -03:00
|
|
|
/* Do not allow copies */
|
|
|
|
AP_Camera(const AP_Camera &other) = delete;
|
|
|
|
AP_Camera &operator=(const AP_Camera&) = delete;
|
|
|
|
|
2018-04-14 01:03:29 -03:00
|
|
|
// get singleton instance
|
2018-10-03 21:26:34 -03:00
|
|
|
static AP_Camera *get_singleton()
|
|
|
|
{
|
2018-04-14 01:03:29 -03:00
|
|
|
return _singleton;
|
|
|
|
}
|
2017-08-29 15:48:37 -03:00
|
|
|
|
2012-08-17 03:09:29 -03:00
|
|
|
// MAVLink methods
|
2017-07-26 02:47:08 -03:00
|
|
|
void control_msg(const mavlink_message_t* msg);
|
2017-07-25 23:45:20 -03:00
|
|
|
void send_feedback(mavlink_channel_t chan);
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2015-09-06 17:41:47 -03:00
|
|
|
// Command processing
|
|
|
|
void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time);
|
2017-07-25 23:45:20 -03:00
|
|
|
// handle camera control
|
|
|
|
void control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id);
|
2015-04-18 10:30:03 -03:00
|
|
|
|
2013-10-11 07:29:01 -03:00
|
|
|
// set camera trigger distance in a mission
|
2018-10-03 21:26:34 -03:00
|
|
|
void set_trigger_distance(uint32_t distance_m)
|
|
|
|
{
|
|
|
|
_trigg_dist.set(distance_m);
|
|
|
|
}
|
2013-10-11 07:29:01 -03:00
|
|
|
|
2017-07-25 23:45:20 -03:00
|
|
|
void take_picture();
|
2013-06-24 09:39:50 -03:00
|
|
|
|
2017-07-25 23:45:20 -03:00
|
|
|
// Update - to be called periodically @at least 10Hz
|
|
|
|
void update();
|
|
|
|
|
|
|
|
// update camera trigger - 50Hz
|
|
|
|
void update_trigger();
|
2016-01-19 01:25:53 -04:00
|
|
|
|
2012-08-17 03:09:29 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2017-10-24 07:42:17 -03:00
|
|
|
// set if vehicle is in AUTO mode
|
2018-10-03 21:26:34 -03:00
|
|
|
void set_is_auto_mode(bool enable)
|
|
|
|
{
|
|
|
|
_is_in_auto_mode = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum camera_types {
|
|
|
|
CAMERA_TYPE_STD,
|
|
|
|
CAMERA_TYPE_BMMCC
|
|
|
|
};
|
2017-10-24 07:42:17 -03:00
|
|
|
|
2012-06-13 16:00:20 -03:00
|
|
|
private:
|
2018-04-14 01:03:29 -03:00
|
|
|
|
|
|
|
static AP_Camera *_singleton;
|
|
|
|
|
2013-12-05 21:27:58 -04:00
|
|
|
AP_Int8 _trigger_type; // 0:Servo,1:Relay
|
2012-12-06 04:46:09 -04:00
|
|
|
AP_Int8 _trigger_duration; // duration in 10ths of a second that the camera shutter is held open
|
2015-09-05 00:44:07 -03:00
|
|
|
AP_Int8 _relay_on; // relay value to trigger camera
|
2012-12-06 04:46:09 -04:00
|
|
|
AP_Int16 _servo_on_pwm; // PWM value to move servo to when shutter is activated
|
|
|
|
AP_Int16 _servo_off_pwm; // PWM value to move servo to when shutter is deactivated
|
|
|
|
uint8_t _trigger_counter; // count of number of cycles shutter has been held open
|
2018-10-03 21:26:34 -03:00
|
|
|
uint8_t _trigger_counter_cam_function; // count of number of cycles alternative camera function has been held open
|
2015-11-03 09:46:29 -04:00
|
|
|
AP_Relay *_apm_relay; // pointer to relay object from the base class Relay.
|
2017-10-24 07:42:17 -03:00
|
|
|
AP_Int8 _auto_mode_only; // if 1: trigger by distance only if in AUTO mode.
|
2018-10-03 21:26:34 -03:00
|
|
|
AP_Int8 _type; // Set the type of camera in use, will open additional parameters if set
|
2017-10-24 07:42:17 -03:00
|
|
|
bool _is_in_auto_mode; // true if in AUTO mode
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2012-08-17 03:09:29 -03:00
|
|
|
void servo_pic(); // Servo operated camera
|
|
|
|
void relay_pic(); // basic relay activation
|
2016-01-19 01:25:53 -04:00
|
|
|
void feedback_pin_timer();
|
2018-05-14 22:03:49 -03:00
|
|
|
void feedback_pin_isr(uint8_t, bool, uint32_t);
|
2016-04-14 20:24:41 -03:00
|
|
|
void setup_feedback_callback(void);
|
2018-10-03 21:26:34 -03:00
|
|
|
|
2014-08-26 18:08:54 -03:00
|
|
|
AP_Float _trigg_dist; // distance between trigger points (meters)
|
2015-12-18 03:16:11 -04:00
|
|
|
AP_Int16 _min_interval; // Minimum time between shots required by camera
|
|
|
|
AP_Int16 _max_roll; // Maximum acceptable roll angle when trigging camera
|
|
|
|
uint32_t _last_photo_time; // last time a photo was taken
|
2013-06-24 09:39:50 -03:00
|
|
|
struct Location _last_location;
|
2014-08-26 18:08:54 -03:00
|
|
|
uint16_t _image_index; // number of pictures taken since boot
|
2012-06-13 16:00:20 -03:00
|
|
|
|
2016-01-20 17:33:17 -04:00
|
|
|
// pin number for accurate camera feedback messages
|
|
|
|
AP_Int8 _feedback_pin;
|
|
|
|
AP_Int8 _feedback_polarity;
|
|
|
|
|
2018-05-14 22:03:49 -03:00
|
|
|
uint32_t _camera_trigger_count;
|
|
|
|
uint32_t _camera_trigger_logged;
|
|
|
|
uint32_t _feedback_timestamp_us;
|
|
|
|
bool _timer_installed;
|
|
|
|
bool _isr_installed;
|
2016-01-20 17:33:17 -04:00
|
|
|
uint8_t _last_pin_state;
|
2017-07-25 23:45:20 -03:00
|
|
|
|
|
|
|
void log_picture();
|
|
|
|
|
|
|
|
uint32_t log_camera_bit;
|
|
|
|
const struct Location ¤t_loc;
|
|
|
|
const AP_AHRS &ahrs;
|
|
|
|
|
2017-07-26 01:32:40 -03:00
|
|
|
// entry point to trip local shutter (e.g. by relay or servo)
|
|
|
|
void trigger_pic();
|
2017-07-25 23:45:20 -03:00
|
|
|
|
|
|
|
// de-activate the trigger after some delay, but without using a delay() function
|
|
|
|
// should be called at 50hz from main program
|
|
|
|
void trigger_pic_cleanup();
|
|
|
|
|
|
|
|
// return true if we are using a feedback pin
|
2018-10-03 21:26:34 -03:00
|
|
|
bool using_feedback_pin(void) const
|
|
|
|
{
|
|
|
|
return _feedback_pin > 0;
|
|
|
|
}
|
2017-07-25 23:45:20 -03:00
|
|
|
|
2012-06-13 16:00:20 -03:00
|
|
|
};
|
2018-04-14 01:03:29 -03:00
|
|
|
|
|
|
|
namespace AP {
|
2018-10-03 21:26:34 -03:00
|
|
|
AP_Camera *camera();
|
2018-04-14 01:03:29 -03:00
|
|
|
};
|