11 changed files with 302 additions and 3 deletions
@ -0,0 +1,176 @@ |
|||||||
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
||||||
|
|
||||||
|
#include <AP_Camera.h> |
||||||
|
#include <AP_Relay.h> |
||||||
|
#include <../RC_Channel/RC_Channel_aux.h> |
||||||
|
|
||||||
|
extern RC_Channel_aux* g_rc_function[RC_Channel_aux::k_nr_aux_servo_functions]; // the aux. servo ch. assigned to each function
|
||||||
|
extern long wp_distance; |
||||||
|
extern AP_Relay relay; |
||||||
|
|
||||||
|
// ------------------------------
|
||||||
|
#define CAM_DEBUG DISABLED |
||||||
|
|
||||||
|
const AP_Param::GroupInfo AP_Camera::var_info[] PROGMEM = { |
||||||
|
AP_GROUPINFO("TRIGG_TYPE", 0, AP_Camera, trigger_type), |
||||||
|
AP_GROUPEND |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::servo_pic() // Servo operated camera
|
||||||
|
{ |
||||||
|
if (g_rc_function[RC_Channel_aux::k_cam_trigger]) |
||||||
|
{ |
||||||
|
g_rc_function[RC_Channel_aux::k_cam_trigger]->radio_out = g_rc_function[RC_Channel_aux::k_cam_trigger]->radio_max; |
||||||
|
keep_cam_trigg_active_cycles = 2; // leave a message that it should be active for two event loop cycles
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::relay_pic() // basic relay activation
|
||||||
|
{ |
||||||
|
relay.on(); |
||||||
|
keep_cam_trigg_active_cycles = 2; // leave a message that it should be active for two event loop cycles
|
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::throttle_pic() // pictures blurry? use this trigger. Turns off the throttle until for # of cycles of medium loop then takes the picture and re-enables the throttle.
|
||||||
|
{ |
||||||
|
// TODO find a way to do this without using the global parameter g
|
||||||
|
// g.channel_throttle.radio_out = g.throttle_min;
|
||||||
|
if (thr_pic == 10){ |
||||||
|
servo_pic(); // triggering method
|
||||||
|
thr_pic = 0; |
||||||
|
// g.channel_throttle.radio_out = g.throttle_cruise;
|
||||||
|
} |
||||||
|
thr_pic++; |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::distance_pic() // pictures blurry? use this trigger. Turns off the throttle until closer to waypoint then takes the picture and re-enables the throttle.
|
||||||
|
{ |
||||||
|
// TODO find a way to do this without using the global parameter g
|
||||||
|
// g.channel_throttle.radio_out = g.throttle_min;
|
||||||
|
if (wp_distance < 3){ |
||||||
|
servo_pic(); // triggering method
|
||||||
|
// g.channel_throttle.radio_out = g.throttle_cruise;
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::NPN_pic() // hacked the circuit to run a transistor? use this trigger to send output.
|
||||||
|
{ |
||||||
|
// TODO: Assign pin spare pin for output
|
||||||
|
digitalWrite(camtrig, HIGH); |
||||||
|
keep_cam_trigg_active_cycles = 1; // leave a message that it should be active for two event loop cycles
|
||||||
|
} |
||||||
|
|
||||||
|
// single entry point to take pictures
|
||||||
|
void |
||||||
|
AP_Camera::trigger_pic() |
||||||
|
{ |
||||||
|
switch (trigger_type) |
||||||
|
{ |
||||||
|
case 0: |
||||||
|
servo_pic(); // Servo operated camera
|
||||||
|
break; |
||||||
|
case 1: |
||||||
|
relay_pic(); // basic relay activation
|
||||||
|
break; |
||||||
|
case 2: |
||||||
|
throttle_pic(); // pictures blurry? use this trigger. Turns off the throttle until for # of cycles of medium loop then takes the picture and re-enables the throttle.
|
||||||
|
break; |
||||||
|
case 3: |
||||||
|
distance_pic(); // pictures blurry? use this trigger. Turns off the throttle until closer to waypoint then takes the picture and re-enables the throttle.
|
||||||
|
break; |
||||||
|
case 4: |
||||||
|
NPN_pic(); // hacked the circuit to run a transistor? use this trigger to send output.
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// de-activate the trigger after some delay, but without using a delay() function
|
||||||
|
void |
||||||
|
AP_Camera::trigger_pic_cleanup() |
||||||
|
{ |
||||||
|
if (keep_cam_trigg_active_cycles) |
||||||
|
{ |
||||||
|
keep_cam_trigg_active_cycles --; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
switch (trigger_type) |
||||||
|
{ |
||||||
|
case 0: |
||||||
|
case 2: |
||||||
|
case 3: |
||||||
|
G_RC_AUX(k_cam_trigger)->radio_out = g_rc_function[RC_Channel_aux::k_cam_trigger]->radio_min; |
||||||
|
break; |
||||||
|
case 1: |
||||||
|
relay.off(); |
||||||
|
break; |
||||||
|
case 4: |
||||||
|
digitalWrite(camtrig, LOW); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
void |
||||||
|
AP_Camera::configure_msg(mavlink_message_t* msg) |
||||||
|
{ |
||||||
|
__mavlink_digicam_configure_t packet; |
||||||
|
mavlink_msg_digicam_configure_decode(msg, &packet); |
||||||
|
if (mavlink_check_target(packet.target_system, packet.target_component)) { |
||||||
|
// not for us
|
||||||
|
return; |
||||||
|
} |
||||||
|
// TODO do something with these values
|
||||||
|
/*
|
||||||
|
packet.aperture |
||||||
|
packet.command_id |
||||||
|
packet.engine_cut_off |
||||||
|
packet.exposure_type |
||||||
|
packet.extra_param |
||||||
|
packet.extra_value |
||||||
|
packet.iso |
||||||
|
packet.mode |
||||||
|
packet.shutter_speed |
||||||
|
*/ |
||||||
|
// echo the message to the ArduCam OSD camera control board
|
||||||
|
// for more info see: http://code.google.com/p/arducam-osd/
|
||||||
|
// TODO is it connected to MAVLINK_COMM_3 ?
|
||||||
|
mavlink_msg_digicam_configure_send(MAVLINK_COMM_3, packet.target_system, packet.target_component, packet.mode, packet.shutter_speed, packet.aperture, packet.iso, packet.exposure_type, packet.command_id, packet.engine_cut_off, packet.extra_param, packet.extra_value); |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
AP_Camera::control_msg(mavlink_message_t* msg) |
||||||
|
{ |
||||||
|
__mavlink_digicam_control_t packet; |
||||||
|
mavlink_msg_digicam_control_decode(msg, &packet); |
||||||
|
if (mavlink_check_target(packet.target_system, packet.target_component)) { |
||||||
|
// not for us
|
||||||
|
return; |
||||||
|
} |
||||||
|
// TODO do something with these values
|
||||||
|
/*
|
||||||
|
packet.command_id |
||||||
|
packet.extra_param |
||||||
|
packet.extra_value |
||||||
|
packet.focus_lock |
||||||
|
packet.session |
||||||
|
packet.shot |
||||||
|
packet.zoom_pos |
||||||
|
packet.zoom_step |
||||||
|
*/ |
||||||
|
if (packet.shot) |
||||||
|
{ |
||||||
|
trigger_pic(); |
||||||
|
} |
||||||
|
// echo the message to the ArduCam OSD camera control board
|
||||||
|
// for more info see: http://code.google.com/p/arducam-osd/
|
||||||
|
// TODO is it connected to MAVLINK_COMM_3 ?
|
||||||
|
mavlink_msg_digicam_control_send(MAVLINK_COMM_3, packet.target_system, packet.target_component, packet.session, packet.zoom_pos, packet.zoom_step, packet.focus_lock, packet.shot, packet.command_id, packet.extra_param, packet.extra_value); |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,58 @@ |
|||||||
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
||||||
|
|
||||||
|
/// @file AP_Camera.h
|
||||||
|
/// @brief Photo or video camera manager, with EEPROM-backed storage of constants.
|
||||||
|
|
||||||
|
#ifndef AP_CAMERA_H |
||||||
|
#define AP_CAMERA_H |
||||||
|
|
||||||
|
#include <AP_Common.h> |
||||||
|
#include <GCS_MAVLink.h> |
||||||
|
|
||||||
|
/// @class Camera
|
||||||
|
/// @brief Object managing a Photo or video camera
|
||||||
|
class AP_Camera{ |
||||||
|
|
||||||
|
public: |
||||||
|
/// Constructor
|
||||||
|
///
|
||||||
|
AP_Camera() : |
||||||
|
trigger_type (0), |
||||||
|
picture_time (0), // waypoint trigger variable
|
||||||
|
thr_pic (0), // timer variable for throttle_pic
|
||||||
|
camtrig (83), // PK6 chosen as it not near anything so safer for soldering
|
||||||
|
keep_cam_trigg_active_cycles (0), |
||||||
|
wp_distance_min (10) |
||||||
|
{} |
||||||
|
|
||||||
|
// single entry point to take pictures
|
||||||
|
void trigger_pic(); |
||||||
|
|
||||||
|
// de-activate the trigger after some delay, but without using a delay() function
|
||||||
|
void trigger_pic_cleanup(); |
||||||
|
|
||||||
|
// MAVLink methods
|
||||||
|
void configure_msg(mavlink_message_t* msg); |
||||||
|
void control_msg(mavlink_message_t* msg); |
||||||
|
|
||||||
|
int picture_time; // waypoint trigger variable
|
||||||
|
long wp_distance_min; // take picture if distance to WP is smaller than this
|
||||||
|
|
||||||
|
static const struct AP_Param::GroupInfo var_info[]; |
||||||
|
|
||||||
|
private: |
||||||
|
uint8_t keep_cam_trigg_active_cycles; // event loop cycles to keep trigger active
|
||||||
|
int thr_pic; // timer variable for throttle_pic
|
||||||
|
int camtrig; // PK6 chosen as it not near anything so safer for soldering
|
||||||
|
|
||||||
|
AP_Int8 trigger_type; // 0=Servo, 1=relay, 2=throttle_off time, 3=throttle_off waypoint 4=transistor
|
||||||
|
|
||||||
|
void servo_pic(); // Servo operated camera
|
||||||
|
void relay_pic(); // basic relay activation
|
||||||
|
void throttle_pic(); // pictures blurry? use this trigger. Turns off the throttle until for # of cycles of medium loop then takes the picture and re-enables the throttle.
|
||||||
|
void distance_pic(); // pictures blurry? use this trigger. Turns off the throttle until closer to waypoint then takes the picture and re-enables the throttle.
|
||||||
|
void NPN_pic(); // hacked the circuit to run a transistor? use this trigger to send output.
|
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
#endif /* AP_CAMERA_H */ |
Loading…
Reference in new issue