|
@@ -5,6 +5,7 @@
|
|
|
// var valuesPath = local.values;
|
|
|
|
|
|
var ZoomPos = script.addFloatParameter("Zoom Position", "", 0., 0., 1.);
|
|
|
+var ZoomPosLastUpdate = script.addFloatParameter("Zoom update", "", 0.);
|
|
|
|
|
|
// var state =
|
|
|
var inquiry = ['CAM_ZoomPosInq', 'CAM_FocusModeInq', 'CAM_FocusPosInq'];
|
|
@@ -12,7 +13,11 @@ var camID = 1;
|
|
|
var waitTaskComplete = 0 ;
|
|
|
var currentInquiry = '';
|
|
|
|
|
|
-/////////// HELPERS FUNCTIONS ////////////////
|
|
|
+var ZoomAuto = false ;
|
|
|
+var ZoomPos_target ;
|
|
|
+var ZoomTime_target ;
|
|
|
+
|
|
|
+//////////////////////// HELPERS FUNCTIONS ////////////////////////////
|
|
|
|
|
|
function printArray(name, array){
|
|
|
var printHeader = ' '+name+' : ';
|
|
@@ -20,7 +25,9 @@ function printArray(name, array){
|
|
|
script.log(printHeader);
|
|
|
}
|
|
|
|
|
|
-/////////// VISCA FUNCTIONS ////////////////
|
|
|
+
|
|
|
+
|
|
|
+//////////////////////// VISCA FUNCTIONS ////////////////////////////////
|
|
|
|
|
|
function setZoomPos(ID, position){
|
|
|
var header = [1, 4, 71];
|
|
@@ -37,15 +44,19 @@ function setZoomPos(ID, position){
|
|
|
|
|
|
sendHeaderCommand(camID, header, posCmd);
|
|
|
}
|
|
|
+
|
|
|
function setZoomSpeed(ID, speed){
|
|
|
var header = [1, 4, 7];
|
|
|
|
|
|
var speedCmd = speed < 0 ? 48 : 32;
|
|
|
+
|
|
|
+ speedCmd += Math.abs(speed)-1;
|
|
|
speedCmd = speed == 0 ? 0 : speedCmd ;
|
|
|
- speedCmd += Math.abs(speed);
|
|
|
sendHeaderCommand(camID, header, speedCmd);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
function sendInquiry(id, inquiryName){
|
|
|
var command ;
|
|
|
if (currentInquiry == ''){ //no inquiry running;
|
|
@@ -61,15 +72,15 @@ function sendInquiry(id, inquiryName){
|
|
|
function sendCommand(id, command){
|
|
|
var idHex = (parseInt("0x80") + id);
|
|
|
|
|
|
- printArray('command', command);
|
|
|
+ // printArray('command', command);
|
|
|
local.sendBytes(idHex, command, 255);
|
|
|
}
|
|
|
|
|
|
function sendHeaderCommand(id, header, command){
|
|
|
if (!waitTaskComplete){
|
|
|
var idHex = (parseInt("0x80") + id);
|
|
|
- printArray('header', header);
|
|
|
- printArray('command', command);
|
|
|
+ // printArray('header', header);
|
|
|
+ // printArray('command', command);
|
|
|
local.sendBytes(idHex, header, command, 255);
|
|
|
waitTaskComplete = 1;
|
|
|
}
|
|
@@ -77,22 +88,90 @@ function sendHeaderCommand(id, header, command){
|
|
|
|
|
|
}
|
|
|
|
|
|
-/////////// SCRIPT FUNCTIONS ////////////////
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//////////////////////// ZOOM AUTOMATION ////////////////////////////////
|
|
|
+
|
|
|
+
|
|
|
+function setZoomPositionInTime(ID, position, time){
|
|
|
+
|
|
|
+ //update zoom position and time targets
|
|
|
+ ZoomPos_target = position ;
|
|
|
+ ZoomTime_target = util.getTime()+time;
|
|
|
+
|
|
|
+ //activate callback
|
|
|
+ ZoomAuto = true ;
|
|
|
+
|
|
|
+ //deduce appropriate speed
|
|
|
+ // var speedCmd = speed < 0 ? 48 : 32;
|
|
|
+ // speedCmd = speed == 0 ? 0 : speedCmd ;
|
|
|
+ // speedCmd += Math.abs(speed);
|
|
|
+ // sendHeaderCommand(camID, header, speedCmd);
|
|
|
+}
|
|
|
+
|
|
|
+function updateZoomPosition() {
|
|
|
+
|
|
|
+ if (ZoomAuto){
|
|
|
+ //update position
|
|
|
+ sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+
|
|
|
+ //update speed if needed
|
|
|
+ var lastUpdated = util.getTime()-ZoomPosLastUpdate.get();
|
|
|
+ // script.log(lastUpdated);
|
|
|
+ if(lastUpdated<0.5){
|
|
|
+ //compute remaining time
|
|
|
+ var remainTime = ZoomTime_target - util.getTime();
|
|
|
+ if(remainTime > 0){
|
|
|
+ var remainLength = (ZoomPos_target - ZoomPos.get()) * 100;
|
|
|
+ var rawSpeed = remainLength / remainTime ;
|
|
|
+
|
|
|
+ var absSpeed = Math.abs(rawSpeed);
|
|
|
+ var realSpeed = -0.00221 * Math.pow(absSpeed,2) + 0.30898 * absSpeed ;
|
|
|
+ var direction = rawSpeed > 0 ? 1 : -1;
|
|
|
+ realSpeed *= direction ;
|
|
|
+ realSpeed = Math.floor(realSpeed);
|
|
|
+ script.log(remainLength + '% in ' + remainTime + ' s : ' + realSpeed + ' / ' +rawSpeed );
|
|
|
+ setZoomSpeed(1, realSpeed);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ZoomAuto = false;
|
|
|
+ script.log('automation timeout');
|
|
|
+ //go to position
|
|
|
+ setZoomPos(1, ZoomPos_target);
|
|
|
+ sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ function computeSpeed(){
|
|
|
+
|
|
|
+
|
|
|
+ // 0,151*PUISSANCE((A18+1);2) +3,0001717*(A18+1)+0,007557
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/////////////////////// SCRIPT FUNCTIONS ///////////////////////////////
|
|
|
+
|
|
|
+
|
|
|
|
|
|
function init() {
|
|
|
//loadFixtures();
|
|
|
script.log("VISCA module loaded");
|
|
|
- script.setUpdateRate(100);
|
|
|
+ script.setUpdateRate(2);
|
|
|
}
|
|
|
|
|
|
-function update(deltatTime){
|
|
|
- if(!waitTaskComplete && (currentInquiry!=''))
|
|
|
- {
|
|
|
- sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
- }
|
|
|
+function update(deltaTime){
|
|
|
+ updateZoomPosition();
|
|
|
+ computeSpeed();
|
|
|
+ // script.log('update');
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
var buffer=[];
|
|
|
var bufferIndex = 0 ;
|
|
|
function dataReceived(data)
|
|
@@ -142,9 +221,10 @@ function dataReceived(data)
|
|
|
else if (buffer[1]==80){//0x50
|
|
|
if(currentInquiry == 'CAM_ZoomPosInq'){
|
|
|
var position = buffer[2]*4096 + buffer[3]*256 + buffer[4]*16 + buffer[5];
|
|
|
- printArray("zoom position :", buffer);
|
|
|
- script.log(position);
|
|
|
+ // printArray("zoom position :", buffer);
|
|
|
+ // script.log(position);
|
|
|
ZoomPos.set(position/16384.);
|
|
|
+ ZoomPosLastUpdate.set(util.getTime());
|
|
|
}
|
|
|
//free inquiry slot
|
|
|
currentInquiry = '';
|