|
| 1 | +/* |
| 2 | + This program is free software: you can redistribute it and/or modify |
| 3 | + it under the terms of the GNU General Public License as published by |
| 4 | + the Free Software Foundation, either version 3 of the License, or |
| 5 | + (at your option) any later version. |
| 6 | +
|
| 7 | + This program is distributed in the hope that it will be useful, |
| 8 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + GNU General Public License for more details. |
| 11 | +
|
| 12 | + You should have received a copy of the GNU General Public License |
| 13 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | + */ |
| 15 | +/* |
| 16 | + simple camera simulator class |
| 17 | +*/ |
| 18 | + |
| 19 | +#include "SIM_Camera.h" |
| 20 | + |
| 21 | +#include <GCS_MAVLink/GCS.h> |
| 22 | +#include <SITL/SITL.h> |
| 23 | + |
| 24 | +using namespace SITL; |
| 25 | + |
| 26 | +// table of user settable parameters |
| 27 | +const AP_Param::GroupInfo Camera::var_info[] = { |
| 28 | + |
| 29 | + // @Param: ENABLE |
| 30 | + // @DisplayName: Camera Sim enable/disable |
| 31 | + // @Description: Allows you to enable (1) or disable (0) the Camera simulation |
| 32 | + // @Values: 0:Disabled,1:Enabled |
| 33 | + // @User: Advanced |
| 34 | + AP_GROUPINFO("ENABLE", 0, Camera, _enable, 0), |
| 35 | + |
| 36 | + // @Param: TRIG_SRV |
| 37 | + // @DisplayName: Camera trigger servo pin |
| 38 | + // @Description: The pin number that the Camera trigger servo is connected to. (start at 1) |
| 39 | + // @Range: 0 32 |
| 40 | + // @User: Advanced |
| 41 | + AP_GROUPINFO("TRIG_SRV", 1, Camera, _trigger_servo_pin, -1), |
| 42 | + |
| 43 | + // @Param: TRIG_GPIO |
| 44 | + // @DisplayName: Camera trigger GPIO pin |
| 45 | + // @Description: The GPIO pin number used to trigger Camera capture. |
| 46 | + // @Range: -1 15 |
| 47 | + // @User: Advanced |
| 48 | + AP_GROUPINFO("GPIO_PIN", 2, Camera, _trigger_gpio_pin, -1), |
| 49 | + |
| 50 | + // @Param: TRIG_PWM |
| 51 | + // @DisplayName: Camera trigger PWM threshold |
| 52 | + // @Description: PWM threshold for considering the camera trigger servo active. |
| 53 | + // @Range: 1000 2000 |
| 54 | + // @Units: PWM |
| 55 | + // @User: Advanced |
| 56 | + AP_GROUPINFO("TRIG_PWM", 3, Camera, _trigger_pwm, 1300), |
| 57 | + |
| 58 | + AP_GROUPEND |
| 59 | +}; |
| 60 | + |
| 61 | +/* |
| 62 | + update camera state |
| 63 | + */ |
| 64 | +void Camera::update(const struct sitl_input &input) |
| 65 | +{ |
| 66 | + bool servo_triggered = false; |
| 67 | + if (_trigger_servo_pin >= 1 && _trigger_servo_pin <= 32) { |
| 68 | + const int16_t servo_pwm = input.servos[_trigger_servo_pin - 1]; |
| 69 | + servo_triggered = servo_pwm >= _trigger_pwm; |
| 70 | + } |
| 71 | + |
| 72 | + bool gpio_triggered = false; |
| 73 | + const auto *sitl = AP::sitl(); |
| 74 | + if (sitl != nullptr && _trigger_gpio_pin >= 0 && _trigger_gpio_pin <= 15) { |
| 75 | + gpio_triggered = (sitl->pin_mask.get() & (1U << _trigger_gpio_pin)) != 0; |
| 76 | + } |
| 77 | + |
| 78 | + const bool trigger_active = servo_triggered || gpio_triggered; |
| 79 | + if (trigger_active && !_last_trigger_state) { |
| 80 | + _image_count++; |
| 81 | + GCS_SEND_TEXT(MAV_SEVERITY_INFO, "SITL: Camera image %u", (unsigned)_image_count); |
| 82 | + } |
| 83 | + |
| 84 | + _last_trigger_state = trigger_active; |
| 85 | +} |
0 commit comments