AP_Scripting: add support for controlling onvif camera using lua script
This commit is contained in:
parent
a81da13c13
commit
027d8b4aea
@ -43,6 +43,10 @@
|
||||
static_assert(SCRIPTING_STACK_SIZE >= SCRIPTING_STACK_MIN_SIZE, "Scripting requires a larger minimum stack size");
|
||||
static_assert(SCRIPTING_STACK_SIZE <= SCRIPTING_STACK_MAX_SIZE, "Scripting requires a smaller stack size");
|
||||
|
||||
#ifndef SCRIPTING_ENABLE_DEFAULT
|
||||
#define SCRIPTING_ENABLE_DEFAULT 0
|
||||
#endif
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
const AP_Param::GroupInfo AP_Scripting::var_info[] = {
|
||||
@ -52,7 +56,7 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
|
||||
// @Values: 0:None,1:Lua Scripts
|
||||
// @RebootRequired: True
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO_FLAGS("ENABLE", 1, AP_Scripting, _enable, 0, AP_PARAM_FLAG_ENABLE),
|
||||
AP_GROUPINFO_FLAGS("ENABLE", 1, AP_Scripting, _enable, SCRIPTING_ENABLE_DEFAULT, AP_PARAM_FLAG_ENABLE),
|
||||
|
||||
// @Param: VM_I_COUNT
|
||||
// @DisplayName: Scripting Virtual Machine Instruction Count
|
||||
|
39
libraries/AP_Scripting/applets/ONVIF_Camera_Control.lua
Normal file
39
libraries/AP_Scripting/applets/ONVIF_Camera_Control.lua
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
local counter = 0
|
||||
local running = 0
|
||||
local last_pan_cmd = 0.0
|
||||
local last_tilt_cmd = 0.0
|
||||
|
||||
function update()
|
||||
if onvif and onvif.start and counter >= 100 and running == 0 then
|
||||
gcs:send_text(0, "onvif starting")
|
||||
if onvif:start("user","123456","http://10.211.55.3:10000") then
|
||||
gcs:send_text(0, "onvif started")
|
||||
running = 1
|
||||
end
|
||||
counter = 0
|
||||
end
|
||||
counter = counter + 1
|
||||
|
||||
if running == 1 then
|
||||
pan_norm, tilt_norm = vehicle:get_pan_tilt_norm()
|
||||
pan_tilt_limit_max = onvif:get_pan_tilt_limit_max()
|
||||
pan_tilt_limit_min = onvif:get_pan_tilt_limit_min()
|
||||
pan_norm = ((pan_norm + 1) * (pan_tilt_limit_max:x() - pan_tilt_limit_min:x())/2.0) + pan_tilt_limit_min:x()
|
||||
tilt_norm = ((tilt_norm + 1) * (pan_tilt_limit_max:y() - pan_tilt_limit_min:y())/2.0) + pan_tilt_limit_min:y()
|
||||
gcs:send_text(0, string.format("PAN: %f TILT: %f", pan_norm, tilt_norm))
|
||||
if math.floor(pan_norm*100.0) ~= math.floor(last_pan_cmd*100.0) or
|
||||
math.floor(tilt_norm*100.0) ~= math.floor(last_tilt_cmd*100.0) then
|
||||
-- actually send the command
|
||||
if not onvif:set_absolutemove(pan_norm, tilt_norm, 0.0) then
|
||||
gcs:send_text(0, "onvif failed to send absolutemove command")
|
||||
end
|
||||
last_pan_cmd = pan_norm;
|
||||
last_tilt_cmd = tilt_norm;
|
||||
end
|
||||
end
|
||||
return update, 20
|
||||
end
|
||||
gcs:send_text(0, "Starting ONVIF Control")
|
||||
|
||||
return update() -- run immediately before starting to reschedule
|
14
libraries/AP_Scripting/applets/ONVIF_Camera_Control.md
Normal file
14
libraries/AP_Scripting/applets/ONVIF_Camera_Control.md
Normal file
@ -0,0 +1,14 @@
|
||||
# ONVIF_Camera_Control Lua Script
|
||||
|
||||
This is a script that converts AntennaTracker into a Drone Tracking Camera using ONVIF capable Camera. The Camera needs to support PTZ AbsoluteMove method. The camera is sent absolute Pan Tilt commands based on requirement from Antenna Tracker lib.
|
||||
|
||||
User just needs to edit the script to set string username, password and IP address:port of the camera. Currently we only support running as part of SITL/Linux instance. Which can simply be done by adding `--enable-onvif` the rest including adding this script will be taken care of by build system. Also you will need to set `PITCH_MAX` `PITCH_MIN` and `YAW_RANGE` parameters per camera specifications.
|
||||
|
||||
Following steps are required before doing ONVIF build:
|
||||
```
|
||||
cd modules/gsoap
|
||||
autoreconf -f -i
|
||||
./configure
|
||||
make
|
||||
make install #add sudo if needed
|
||||
```
|
@ -180,9 +180,13 @@ singleton GCS method send_text void MAV_SEVERITY'enum MAV_SEVERITY_EMERGENCY MAV
|
||||
singleton GCS method set_message_interval MAV_RESULT'enum uint8_t 0 MAVLINK_COMM_NUM_BUFFERS uint32_t 0U UINT32_MAX int32_t -1 INT32_MAX
|
||||
singleton GCS method send_named_float void string float -FLT_MAX FLT_MAX
|
||||
|
||||
include AP_ONVIF/AP_ONVIF.h
|
||||
include AP_ONVIF/AP_ONVIF.h depends ENABLE_ONVIF == 1
|
||||
singleton AP_ONVIF depends ENABLE_ONVIF == 1
|
||||
singleton AP_ONVIF alias onvif
|
||||
singleton AP_ONVIF method start boolean string string string
|
||||
singleton AP_ONVIF method set_absolutemove boolean float -FLT_MAX FLT_MAX float -FLT_MAX FLT_MAX float -FLT_MAX FLT_MAX
|
||||
singleton AP_ONVIF method get_pan_tilt_limit_min Vector2f
|
||||
singleton AP_ONVIF method get_pan_tilt_limit_max Vector2f
|
||||
|
||||
include AP_Vehicle/AP_Vehicle.h
|
||||
singleton AP_Vehicle alias vehicle
|
||||
@ -203,6 +207,7 @@ singleton AP_Vehicle method set_steering_and_throttle boolean float -1 1 float -
|
||||
singleton AP_Vehicle method get_wp_distance_m boolean float'Null
|
||||
singleton AP_Vehicle method get_wp_bearing_deg boolean float'Null
|
||||
singleton AP_Vehicle method get_wp_crosstrack_error_m boolean float'Null
|
||||
singleton AP_Vehicle method get_pan_tilt_norm boolean float'Null float'Null
|
||||
|
||||
include AP_SerialLED/AP_SerialLED.h
|
||||
singleton AP_SerialLED alias serialLED
|
||||
|
Loading…
Reference in New Issue
Block a user