
Originally Posted by
Ben
Ok so for scale variable, my motor does not have a range (it is the motor used in electronic scooters/wheel chairs). So how do I use that?
However let's try another variant of VBScript program:
Code:
' Set the turret control variables
turret_h = 0
turret_v = 0
turret_f = 0
nvObjectsTotal = GetVariable("NV_OBJECTS_TOTAL")
if nvObjectsTotal>0 then ' If any object was found
' Get image size
img_w = GetVariable("IMAGE_WIDTH")
img_h = GetVariable("IMAGE_HEIGHT")
' Get array variables of recognized objects
nvArrObjRectX = GetArrayVariable("NV_ARR_OBJ_RECT_X")
nvArrObjRectY = GetArrayVariable("NV_ARR_OBJ_RECT_Y")
nvArrObjRectW = GetArrayVariable("NV_ARR_OBJ_RECT_W")
nvArrObjRectH = GetArrayVariable("NV_ARR_OBJ_RECT_H")
' Get center coordinates of first object from array
obj_x = nvArrObjRectX(0) + nvArrObjRectW(0)/2
obj_y = nvArrObjRectY(0) - nvArrObjRectH(0)/2
' Get difference between object and screen centers
dX = img_w/2 - obj_x
dY = img_h/2 - obj_y
threshold = 40
if dX > threshold then
' The object is at left side
turret_h = - 1
end if
if dX < -threshold then
' The object is at right side
turret_h = 1
end if
if dY > threshold then
' The object is at the bottom
turret_v = - 1
end if
if dY < -threshold then
' The object is at the top
turret_v = 1
end if
' Is the target locked?
if dX < threshold and dX > -threshold and
dY < threshold and dY > -threshold then
turret_f = 1
end if
end if
' Set turret control variables
SetVariable "TURRET_V_CONTROL", turret_v
SetVariable "TURRET_H_CONTROL", turret_h
SetVariable "TURRET_FIRE", turret_f
=================================
TURRET_H_CONTROL - horizontal turret control (0 - motor off, 1 - right turn, -1 - left turn)
TURRET_V_CONTROL - vertical turret control (0 - motor off, 1 - turn it upward, -1 - turn it downward)
TURRET_FIRE - fire signal
See attached program.
Bookmarks