|
|
@@ -237,11 +237,6 @@ cc.Class({
|
|
|
bCalculation: false,
|
|
|
calTimeout: null,
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//波动判断打击部分
|
|
|
//记录打击的x 轴数据
|
|
|
xArray: [],
|
|
|
@@ -340,6 +335,9 @@ cc.Class({
|
|
|
rotate: { default: null, type: cc.Node },
|
|
|
|
|
|
//记录当前数据
|
|
|
+ currentGameDataArray: [],
|
|
|
+ currentInterval: null,
|
|
|
+
|
|
|
currentDataArray: [],
|
|
|
//是否先手原始数据
|
|
|
bShowOri: true,
|
|
|
@@ -361,25 +359,44 @@ cc.Class({
|
|
|
},
|
|
|
isY: true,
|
|
|
|
|
|
+ LastMS: 0,
|
|
|
+ LastTime: 0,
|
|
|
+
|
|
|
/**
|
|
|
- * 融合算法参数
|
|
|
- */
|
|
|
+ * 融合算法部分使用的参数
|
|
|
+ */
|
|
|
//记录时间
|
|
|
timestamp: 0,
|
|
|
//ms转s
|
|
|
MS2S: 0.001,
|
|
|
- //经过处理的总方向
|
|
|
+ //开始初始化bool
|
|
|
+ initState: true,
|
|
|
+ // angular speeds from gyro
|
|
|
+ gyro: new Array(3),
|
|
|
+ // rotation matrix from gyro data
|
|
|
gyroMatrix: new Array(9),
|
|
|
// orientation angles from gyro matrix
|
|
|
gyroOrientation: new Array(3),
|
|
|
-
|
|
|
- initState: true,
|
|
|
- //加速计和磁力计融合值
|
|
|
+ // magnetic field vector
|
|
|
+ magnet: new Array(3),
|
|
|
+ // accelerometer vector
|
|
|
+ accel: new Array(3),
|
|
|
+ // orientation angles from accel and magnet
|
|
|
accMagOrientation: new Array(3),
|
|
|
+ // final orientation angles from sensor fusion
|
|
|
+ fusedOrientation: new Array(3),
|
|
|
+ // accelerometer and magnetometer based rotation matrix
|
|
|
rotationMatrix: new Array(9),
|
|
|
|
|
|
- accel: new Array(3),
|
|
|
- fusedOrientation: new Array(3),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 波形
|
|
|
+ */
|
|
|
+ drawX: {
|
|
|
+ default: null,
|
|
|
+ type: cc.Node,
|
|
|
+ tooltip: "绘制X节点",
|
|
|
+ },
|
|
|
},
|
|
|
onChangeAxis(event) {
|
|
|
// console.log(event);
|
|
|
@@ -428,6 +445,8 @@ cc.Class({
|
|
|
|
|
|
this.lineLinearY = this.drawNodeLinearY.getComponent("line");
|
|
|
|
|
|
+ this.drawXScript = this.drawX.getComponent("heartBeat");
|
|
|
+
|
|
|
|
|
|
this.lineSqrt = this.drawNodeSqrt.getComponent("line");
|
|
|
|
|
|
@@ -455,20 +474,17 @@ cc.Class({
|
|
|
/**
|
|
|
* 算法初始参数
|
|
|
*/
|
|
|
+ this.gyroOrientation[0] = 0.0;
|
|
|
+ this.gyroOrientation[1] = 0.0;
|
|
|
+ this.gyroOrientation[2] = 0.0;
|
|
|
// initialise gyroMatrix with identity matrix
|
|
|
this.gyroMatrix[0] = 1.0; this.gyroMatrix[1] = 0.0; this.gyroMatrix[2] = 0.0;
|
|
|
this.gyroMatrix[3] = 0.0; this.gyroMatrix[4] = 1.0; this.gyroMatrix[5] = 0.0;
|
|
|
this.gyroMatrix[6] = 0.0; this.gyroMatrix[7] = 0.0; this.gyroMatrix[8] = 1.0;
|
|
|
|
|
|
-
|
|
|
- this.gyroOrientation[0] = 0.0;
|
|
|
- this.gyroOrientation[1] = 0.0;
|
|
|
- this.gyroOrientation[2] = 0.0;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ this.schedule(() => {
|
|
|
+ this.calculateFusedOrientationTask();
|
|
|
+ }, 0.03, 0, 1)
|
|
|
},
|
|
|
|
|
|
start() {
|
|
|
@@ -539,20 +555,39 @@ cc.Class({
|
|
|
// }
|
|
|
|
|
|
} else if (e.type == 'stateDataOfJump') {
|
|
|
+ console.log('stateDataOfJump:', JSON.stringify(e));
|
|
|
+ // this.event.trigger('resultant', {
|
|
|
+ // type: "stateDataOfJump",
|
|
|
+ // currentMaxValue: _frameMaxValue,
|
|
|
+ // currentMinValue: _frameMinValue,
|
|
|
+ // peakOfWaveMaxValue: this.peakOfWaveMaxValue,
|
|
|
+ // valleyOfWaveMinValue: this.valleyOfWaveMinValue,
|
|
|
+ // oGyroValue: _frameGyroValue,
|
|
|
+ // resultant: resultant,
|
|
|
+ // tempIndex: i, //触发了多少次
|
|
|
+ // name: "highestCountEnd"
|
|
|
+ // });
|
|
|
+ console.log(Math.abs(e.currentMaxValue) > Math.abs(e.currentMinValue) ? "左方向" : "右方向");
|
|
|
+ console.log(Math.abs(e.oGyroValue) > Math.abs(e.oGyroMinValue) ? "右旋转" : "左旋转");
|
|
|
+ if (e.oGyroValue > 1000) {
|
|
|
+ this.rotate.angle = 0;
|
|
|
+ } else if (e.oGyroMinValue < -1000) {
|
|
|
+ this.rotate.angle = 180;
|
|
|
+ }
|
|
|
//发送给game,在game里面处理判断
|
|
|
- if (this.gameScript)
|
|
|
- this.gameScript.listenStateDataOfJump(e, this.isY);
|
|
|
+ // if (this.gameScript)
|
|
|
+ // this.gameScript.listenStateDataOfJump(e, this.isY);
|
|
|
|
|
|
} else if (e.type == 'bUpdateDraw') {
|
|
|
if (this.bAccDraw) {
|
|
|
let { lAccX, lAccY, lAccZ } = e.data.linearAcc;
|
|
|
let { oAccX, oAccY, oAccZ } = e.data.oriAcc;
|
|
|
- if (lAccX > 0)
|
|
|
- this.lineX.onUpdateDraw(lAccX);
|
|
|
- else
|
|
|
- this.lineX.onUpdateDrawFromColor(lAccX, cc.Color.WHITE, 2);
|
|
|
+ // if (lAccX > 0)
|
|
|
+ // this.lineX.onUpdateDraw(lAccX);
|
|
|
+ // else
|
|
|
+ // this.lineX.onUpdateDrawFromColor(lAccX, cc.Color.WHITE, 2);
|
|
|
|
|
|
- this.lineLinearX.onUpdateDrawFromColor(oAccX, "#00F0FF", 2);
|
|
|
+ // this.lineLinearX.onUpdateDrawFromColor(oAccX, "#00F0FF", 2);
|
|
|
// this.z_k = mVector([e.linearZ]);
|
|
|
// this.KO.z_k = this.z_k;
|
|
|
// this.KM.update(this.KO);
|
|
|
@@ -563,20 +598,39 @@ cc.Class({
|
|
|
// else
|
|
|
// this.lineZ.onUpdateDrawFromColor(this.KM.x_k.elements[0], cc.Color.WHITE, 2);
|
|
|
|
|
|
- if (lAccZ > 0)
|
|
|
- this.lineZ.onUpdateDraw(lAccZ);
|
|
|
- else
|
|
|
- this.lineZ.onUpdateDrawFromColor(lAccZ, cc.Color.WHITE, 2);
|
|
|
+ // if (lAccZ > 0)
|
|
|
+ // this.lineZ.onUpdateDraw(lAccZ);
|
|
|
+ // else
|
|
|
+ // this.lineZ.onUpdateDrawFromColor(lAccZ, cc.Color.WHITE, 2);
|
|
|
+ this.lineZ.onUpdateDraw(oAccZ);
|
|
|
|
|
|
- this.lineLinearZ.onUpdateDrawFromColor(oAccZ, "#00F0FF", 2);
|
|
|
+ this.lineLinearZ.onUpdateDrawFromColor(lAccZ, "#00F0FF", 2);
|
|
|
|
|
|
}
|
|
|
} else if (e.type == 'stop') {
|
|
|
+ console.log('stop');
|
|
|
+ this.onSaveData(this.currentGameDataArray);
|
|
|
+ this.lineX.clear();
|
|
|
+ this.lineY.clear();
|
|
|
+ this.lineLinearY.clear();
|
|
|
+ //
|
|
|
+ let tempArray = e.tempDataArray[0];
|
|
|
+ for (let i = 0; i < tempArray.length; i++) {
|
|
|
+ //绘制读取的数据
|
|
|
+ this.lineY.onUpdateIndex();
|
|
|
+ this.lineY.onUpdateDraw(tempArray[i].oriAcc.oAccZ);
|
|
|
+
|
|
|
+ this.lineLinearY.onUpdateIndex();
|
|
|
+ this.lineLinearY.onUpdateDraw(tempArray[i].linearAcc.lAccZ);
|
|
|
+
|
|
|
+ if (i < 30) {
|
|
|
+ this.lineX.onUpdateIndex();
|
|
|
+ this.lineX.onUpdateDraw(tempArray[i].oriAcc.oAccZ);
|
|
|
+ }
|
|
|
|
|
|
- this.onClear();
|
|
|
- // console.log('stop');
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
})
|
|
|
|
|
|
@@ -594,65 +648,44 @@ cc.Class({
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
- for (let i = 0; i < 3; i++) {
|
|
|
- let box = {};
|
|
|
- box["acc"] = {
|
|
|
- ax: -i * Math.random() + 0.1,
|
|
|
- ay: -i * Math.random() + 0.1,
|
|
|
- az: i * Math.random() + 0.1
|
|
|
- };
|
|
|
- box["gyro"] = {
|
|
|
- gx: -i * Math.random() + 0.1,
|
|
|
- gy: -i * Math.random() + 0.1,
|
|
|
- gz: i * Math.random() + 0.1
|
|
|
- };
|
|
|
- box["min"] = 0;
|
|
|
- box["s"] = 0;
|
|
|
- box["ms"] = 10 * i + 10;
|
|
|
-
|
|
|
- this.onBLEBoxUpdate(box);
|
|
|
- }
|
|
|
- },
|
|
|
- onLeft() {
|
|
|
- let temp = {
|
|
|
- gameData: {
|
|
|
- xAxis: -10.5,
|
|
|
- yAxis: 5,
|
|
|
- zAxis: 0
|
|
|
- }
|
|
|
- }
|
|
|
- this.onUpdateAcc(temp);
|
|
|
- },
|
|
|
- onRight() {
|
|
|
- let temp = {
|
|
|
- gameData: {
|
|
|
- xAxis: 10.5,
|
|
|
- yAxis: 5,
|
|
|
- zAxis: 0
|
|
|
- }
|
|
|
- }
|
|
|
- this.onUpdateAcc(temp);
|
|
|
- },
|
|
|
- onMid() {
|
|
|
- let temp = {
|
|
|
- gameData: {
|
|
|
- xAxis: 0,
|
|
|
- yAxis: 5,
|
|
|
- zAxis: 100.5
|
|
|
- }
|
|
|
- }
|
|
|
- this.onUpdateAcc(temp);
|
|
|
- },
|
|
|
-
|
|
|
- onStatic() {
|
|
|
- let temp = {
|
|
|
- gameData: {
|
|
|
- xAxis: 0,
|
|
|
- yAxis: 9.8,
|
|
|
- zAxis: 0
|
|
|
- }
|
|
|
- }
|
|
|
- this.onUpdateAcc(temp);
|
|
|
+ // for (let i = 0; i < 300; i++) {
|
|
|
+ // let box = {};
|
|
|
+ // box["acc"] = {
|
|
|
+ // ax: -9 * Math.random() + 0.1,
|
|
|
+ // ay: -9 * Math.random() + 0.1,
|
|
|
+ // az: 9 * Math.random() + 0.1
|
|
|
+ // };
|
|
|
+ // box["gyro"] = {
|
|
|
+ // gx: -9 * Math.random() + 0.1,
|
|
|
+ // gy: -9 * Math.random() + 0.1,
|
|
|
+ // gz: 9 * Math.random() + 0.1
|
|
|
+ // };
|
|
|
+ // box["min"] = 0;
|
|
|
+ // box["s"] = 0;
|
|
|
+ // box["ms"] = 10 * i + 10;
|
|
|
+
|
|
|
+ // this.onBLEBoxUpdate(box);
|
|
|
+ // }
|
|
|
+ // let index = 0;
|
|
|
+ // this.schedule(() => {
|
|
|
+ // let box = {};
|
|
|
+ // box["acc"] = {
|
|
|
+ // ax: -9 * Math.random() + 0.1,
|
|
|
+ // ay: -9 * Math.random() + 0.1,
|
|
|
+ // az: 9 * Math.random() + 0.1
|
|
|
+ // };
|
|
|
+ // box["gyro"] = {
|
|
|
+ // gx: -9 * Math.random() + 0.1,
|
|
|
+ // gy: -9 * Math.random() + 0.1,
|
|
|
+ // gz: 9 * Math.random() + 0.1
|
|
|
+ // };
|
|
|
+ // box["min"] = 0;
|
|
|
+ // box["s"] = 0;
|
|
|
+ // box["ms"] = 10 * index + 10;
|
|
|
+ // index ++ ;
|
|
|
+
|
|
|
+ // this.onBLEBoxUpdate(box);
|
|
|
+ // }, 0.03)
|
|
|
},
|
|
|
|
|
|
//重置一下,记录的数据
|
|
|
@@ -690,7 +723,7 @@ cc.Class({
|
|
|
|
|
|
// console.log(gameData.data);
|
|
|
if (gameData.dataType == "Box") {
|
|
|
- webView.onBLEBoxUpdate(gameData.data);
|
|
|
+ webView.onBLEBoxUpdate(gameData.data, true);
|
|
|
}
|
|
|
|
|
|
} else if (name == "onDeviceUpdateJson") {
|
|
|
@@ -698,50 +731,40 @@ cc.Class({
|
|
|
if (gameData.dataType == "Json") {
|
|
|
webView.onBLEJsonUpdate(gameData.data);
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- // console.log(cc.sys.os);
|
|
|
- // if (cc.sys.OS_WINDOWS === cc.sys.os || 'Android' === cc.sys.os) {
|
|
|
-
|
|
|
- // for (let i = 0; i < 100; i++) {
|
|
|
- // // setInterval(()=>{
|
|
|
- // let data = {
|
|
|
- // funName: 'onDeviceUpdateData',
|
|
|
- // gameData: {
|
|
|
- // dataType: 'Box',
|
|
|
- // data: {
|
|
|
- // acc: { ax: Math.random(), ay: Math.random(), az: Math.random() },
|
|
|
- // gyro: { gz: 1, gy: 1, gz: 1 },
|
|
|
- // min: 1,
|
|
|
- // s: 1,
|
|
|
- // ms: 1
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // notifyCenter.emit('webViewMessage', data);
|
|
|
- // // },20)
|
|
|
- // }
|
|
|
-
|
|
|
- // return;
|
|
|
- // // do something
|
|
|
- // }
|
|
|
- // uni.postMessage({
|
|
|
- // data: {
|
|
|
- // funName: "openAccelerometer",
|
|
|
- // gameData: {}
|
|
|
+ } else if (name == 'saveData') {
|
|
|
+ let gameData = data.gameData;
|
|
|
+ // console.log("saveData:", gameData.length);
|
|
|
+ //停止硬件更新
|
|
|
+ webView.onSendWriteBLEDataValue(null, 4);
|
|
|
+ let saveArrayData = gameData;
|
|
|
+ // for (let i = 0; i < saveArrayData.length; i++) {
|
|
|
+ // console.log(saveArrayData[i]);
|
|
|
+ // //绘制读取的数据
|
|
|
+ // }
|
|
|
+ if (this.currentInterval) {
|
|
|
+ this.currentInterval = null;
|
|
|
+ clearInterval(this.currentInterval);
|
|
|
+ }
|
|
|
+ let _index = 60;
|
|
|
+ let _length = saveArrayData.length - 370;
|
|
|
+ // this.currentInterval = setInterval(() => {
|
|
|
+ // webView.onBLEBoxUpdate(saveArrayData[_index]);
|
|
|
+ // _index++;
|
|
|
+ // if (_index >= _length) {
|
|
|
+ // clearInterval(this.currentInterval);
|
|
|
+ // }
|
|
|
+ // }, 0, 0.006)
|
|
|
+
|
|
|
+ for (let i = _index; i < _length; i++) {
|
|
|
+ //绘制读取的数据
|
|
|
+ webView.onBLEBoxUpdate(saveArrayData[i]);
|
|
|
+ }
|
|
|
|
|
|
- // }
|
|
|
- // })
|
|
|
+ this.actionJump.setEndUpdate();
|
|
|
+ }
|
|
|
|
|
|
- // uni.postMessage({
|
|
|
- // data: {
|
|
|
- // funName: "openOrientation",
|
|
|
- // gameData: {}
|
|
|
+ });
|
|
|
|
|
|
- // }
|
|
|
- // })
|
|
|
// 监听蓝牙设备刷新
|
|
|
uni.postMessage({
|
|
|
data: {
|
|
|
@@ -791,165 +814,115 @@ cc.Class({
|
|
|
* @param {*} gameData
|
|
|
* @returns
|
|
|
*/
|
|
|
- onBLEBoxUpdate(gameData) {
|
|
|
- // console.log(gameData);
|
|
|
- //********陀螺仪角速度********
|
|
|
- let { gx, gy, gz } = gameData.gyro;
|
|
|
- let { min, s, ms } = gameData;
|
|
|
-
|
|
|
- //定义一个测试数据,加速计和磁力计的融合数据
|
|
|
- // let accMagOrientation = new Array(0, 1, 0);
|
|
|
- this.accel = [gx.gy, gz];
|
|
|
- this.calculateAccMagOrientation(this.accel);
|
|
|
- // initialisation of the gyroscope based rotation matrix
|
|
|
- if (this.initState) {
|
|
|
- let initMatrix = new Array(9);
|
|
|
- initMatrix = this.getRotationMatrixFromOrientation(this.accMagOrientation);
|
|
|
- let test = new Array(3);
|
|
|
- this.getOrientation(initMatrix, test);
|
|
|
- this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, initMatrix);
|
|
|
- this.initState = false;
|
|
|
+ onBLEBoxUpdate(gameData, bAdd) {
|
|
|
+ //记录最近的500帧原始设备数据
|
|
|
+ if (bAdd) {
|
|
|
+ if (this.currentGameDataArray.length <= 500) {
|
|
|
+ this.currentGameDataArray.push(gameData);
|
|
|
+ } else {
|
|
|
+ this.currentGameDataArray.shift();
|
|
|
+ this.currentGameDataArray.push(gameData);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // copy the new gyro values into the gyro array
|
|
|
- // convert the raw gyro data into a rotation vector
|
|
|
- let deltaVector = new Array(4);
|
|
|
- // if (this.timestamp != 0) {
|
|
|
-
|
|
|
- // }
|
|
|
- let dT = (ms - this.timestamp) * this.MS2S;
|
|
|
- this.getRotationVectorFromGyro([gx, gy, gz], deltaVector, dT / 2);
|
|
|
|
|
|
- // measurement done, save current time for next interval
|
|
|
- this.timestamp = ms;
|
|
|
- // convert rotation vector into rotation matrix
|
|
|
- let deltaMatrix = new Array(9);
|
|
|
- // console.log("deltaVector1:" + deltaVector);
|
|
|
- // console.log("deltaMatrix1:" + deltaMatrix);
|
|
|
- this.getRotationMatrixFromVector(deltaMatrix, deltaVector);
|
|
|
- // console.log("deltaVector2:" + deltaVector);
|
|
|
- // console.log("deltaMatrix2:" + deltaMatrix);
|
|
|
- // apply the new rotation interval on the gyroscope based rotation matrix
|
|
|
- this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, deltaMatrix);
|
|
|
- // console.log(this.gyroMatrix);
|
|
|
- // console.log(this.gyroMatrix.length);
|
|
|
- // get the gyroscope based orientation from the rotation matrix
|
|
|
- this.getOrientation(this.gyroMatrix, this.gyroOrientation);
|
|
|
-
|
|
|
- let FILTER_COEFFICIENT = 0.98;
|
|
|
-
|
|
|
- let oneMinusCoeff = 1.0 - FILTER_COEFFICIENT;
|
|
|
- this.fusedOrientation[0] =
|
|
|
- FILTER_COEFFICIENT * this.gyroOrientation[0]
|
|
|
- + oneMinusCoeff * this.accMagOrientation[0];
|
|
|
-
|
|
|
- this.fusedOrientation[1] =
|
|
|
- FILTER_COEFFICIENT * this.gyroOrientation[1]
|
|
|
- + oneMinusCoeff * this.accMagOrientation[1];
|
|
|
-
|
|
|
- this.fusedOrientation[2] =
|
|
|
- FILTER_COEFFICIENT * this.gyroOrientation[2]
|
|
|
- + oneMinusCoeff * this.accMagOrientation[2];
|
|
|
-
|
|
|
- // overwrite gyro matrix and orientation with fused orientation
|
|
|
- // to comensate gyro drift
|
|
|
- this.gyroMatrix = this.getRotationMatrixFromOrientation(this.fusedOrientation);
|
|
|
- // System.arraycopy(fusedOrientation, 0, gyroOrientation, 0, 3);
|
|
|
-
|
|
|
- this.gyroOrientation[0] = this.fusedOrientation[0];
|
|
|
- this.gyroOrientation[1] = this.fusedOrientation[1];
|
|
|
- this.gyroOrientation[2] = this.fusedOrientation[2];
|
|
|
+ // console.log(gameData);
|
|
|
+ //********传感器数值********
|
|
|
+ let { ax, ay, az } = gameData.acc;
|
|
|
+ let { gx, gy, gz } = gameData.gyro;
|
|
|
+ let { min, s, ms } = gameData;
|
|
|
|
|
|
- // this.oldOriBeta = gx;
|
|
|
- // this.oldOriAlpha = gy;
|
|
|
- // this.oldOriGamma = gz;
|
|
|
|
|
|
- // let oriNew = Math.sqrt(this.oldOriBeta * this.oldOriBeta
|
|
|
- // + this.oldOriAlpha * this.oldOriAlpha + this.oldOriGamma * this.oldOriGamma);
|
|
|
|
|
|
- // this.playerControScript.updateTime({ min: min, s: s, ms: ms });
|
|
|
- // this.playerControScript.updateOri({ beta: gx, alpha: gy, gamma: gz });
|
|
|
+ // //更新
|
|
|
+ // //更新Accl
|
|
|
+ // this.accel = [ax, ay, az];
|
|
|
+ // this.calculateAccMagOrientation();
|
|
|
+ // //更新计算gyro
|
|
|
+ // this.gyroFunction([gx, gy, gz], ms);
|
|
|
|
|
|
//更新index
|
|
|
if (this.bAccDraw) {
|
|
|
- this.lineX.onUpdateIndex();
|
|
|
+ // this.lineX.onUpdateIndex();
|
|
|
this.lineZ.onUpdateIndex();
|
|
|
// this.lineY.onUpdateIndex();
|
|
|
-
|
|
|
this.lineLinearX.onUpdateIndex();
|
|
|
// this.lineLinearY.onUpdateIndex();
|
|
|
this.lineLinearZ.onUpdateIndex();
|
|
|
-
|
|
|
this.lineSqrt.onUpdateIndex();
|
|
|
this.lineOriSqrt.onUpdateIndex();
|
|
|
-
|
|
|
// if (this.bGyroDraw) {
|
|
|
// this.lineX.onUpdateDrawOriBeta(gx);
|
|
|
// this.lineX.onUpdateDrawOriGamma(gy);
|
|
|
// this.lineX.onUpdateDrawOriAlpha(gz);
|
|
|
// this.lineOriSqrt.onUpdateDraw(oriNew);
|
|
|
-
|
|
|
// }
|
|
|
// this.playerControScript.updateOriSqrt(oriNew);
|
|
|
- // if (this.bGyroLog) {
|
|
|
- // console.log("gyro:" + JSON.stringify({ gx: gx, gy: gy, gz: gz }));
|
|
|
- // }
|
|
|
- //********手柄左右 */
|
|
|
- // this.playerControScript.onHandleState(gameData.handle);
|
|
|
- }
|
|
|
|
|
|
- let _ax = gameData.acc.ax * 10;
|
|
|
- let _ay = -gameData.acc.ay * 10;
|
|
|
- let _az = -gameData.acc.az * 10;
|
|
|
- //低通滤波分离重力
|
|
|
- let alpha = 0.8;
|
|
|
- this.xA = alpha * this.xA + (1 - alpha) * _ax;
|
|
|
- this.yA = alpha * this.yA + (1 - alpha) * _ay;
|
|
|
- this.zA = alpha * this.zA + (1 - alpha) * _az;
|
|
|
+ }
|
|
|
+ // var msGap = ms - this.LastMS;
|
|
|
+ // if (msGap < 0) {
|
|
|
+ // msGap += 1000;
|
|
|
+ // }
|
|
|
+ // this.LastMS = ms;
|
|
|
+ // let _ax = gameData.acc.ax * 10;
|
|
|
+ // let _ay = gameData.acc.ay * 10;
|
|
|
+ // let _az = gameData.acc.az * 10;
|
|
|
+ // //低通滤波分离重力
|
|
|
+ // let curTime = new Date().getTime();
|
|
|
+ // let alpha = 1000 / (1000 + msGap); // 0.8;
|
|
|
+ // this.LastTime = curTime;
|
|
|
+ // this.xA = alpha * this.xA + (1 - alpha) * _ax;
|
|
|
+ // this.yA = alpha * this.yA + (1 - alpha) * _ay;
|
|
|
+ // this.zA = alpha * this.zA + (1 - alpha) * _az;
|
|
|
|
|
|
//高通滤波获取线性速度
|
|
|
- let linear_acceleration_x = _ax - this.xA;
|
|
|
- let linear_acceleration_y = _az - this.zA;
|
|
|
- let linear_acceleration_z = _ay - this.yA;
|
|
|
-
|
|
|
- let _temp = {
|
|
|
- linearAcc: {
|
|
|
- lAccX: linear_acceleration_x,
|
|
|
- lAccY: linear_acceleration_y,
|
|
|
- lAccZ: linear_acceleration_z
|
|
|
- }, //gameData.acc,
|
|
|
- oriAcc: {
|
|
|
- oAccX: _ax,
|
|
|
- oAccY: _ay,
|
|
|
- oAccZ: _az
|
|
|
- },
|
|
|
- gravityAcc: {
|
|
|
- gravityX: this.xA,
|
|
|
- gravityY: this.yA,
|
|
|
- gravityZ: this.zA
|
|
|
- },
|
|
|
- bLimitRebound: false,
|
|
|
- resultant: Math.sqrt(_ax * _ax
|
|
|
- + _ay * _ay + _az * _az),
|
|
|
- runIndex: this.BLEAccIndex,
|
|
|
- //陀螺仪
|
|
|
- oriGyro: {
|
|
|
- oGyroX: gx,
|
|
|
- oGyroY: gy,
|
|
|
- oGyroZ: gz
|
|
|
- },
|
|
|
- //输入当前轴
|
|
|
- bYAxis: this.isY,
|
|
|
- };
|
|
|
- this.actionJump.updateJump(_temp);
|
|
|
- this.currentDataArray.push(_temp);
|
|
|
+ // let linear_acceleration_x = _ax - this.xA;
|
|
|
+ // let linear_acceleration_y = _ay - this.yA;
|
|
|
+ // let linear_acceleration_z = _az - this.zA;
|
|
|
+
|
|
|
+ // let _temp = {
|
|
|
+ // oriAcc: {
|
|
|
+ // oAccX: _ax,
|
|
|
+ // oAccY: _ay,
|
|
|
+ // oAccZ: _az
|
|
|
+ // },
|
|
|
+ // linearAcc: {
|
|
|
+ // lAccX: linear_acceleration_x,
|
|
|
+ // lAccY: linear_acceleration_y,
|
|
|
+ // lAccZ: linear_acceleration_z
|
|
|
+ // },
|
|
|
+ // gravityAcc: {
|
|
|
+ // gravityX: this.xA,
|
|
|
+ // gravityY: this.yA,
|
|
|
+ // gravityZ: this.zA
|
|
|
+ // },
|
|
|
+ // bLimitRebound: false,
|
|
|
+ // resultant: Math.sqrt(_ax * _ax
|
|
|
+ // + _ay * _ay + _az * _az),
|
|
|
+ // runIndex: this.BLEAccIndex,
|
|
|
+ // //陀螺仪
|
|
|
+ // oriGyro: {
|
|
|
+ // oGyroX: gx,
|
|
|
+ // oGyroY: gy,
|
|
|
+ // oGyroZ: gz
|
|
|
+ // },
|
|
|
+ // //输入当前轴
|
|
|
+ // bYAxis: this.isY,
|
|
|
+ // };
|
|
|
+ gameData.BLEAccIndex = this.BLEAccIndex;
|
|
|
+ gameData.bYAxis = this.isY;
|
|
|
+ this.actionJump.updateJump(gameData);
|
|
|
+ // this.currentDataArray.push(_temp);
|
|
|
+
|
|
|
+ // this.drawXScript.addPoint(_temp.oriAcc.oAccX);
|
|
|
|
|
|
if (this.bAccDraw) {
|
|
|
//显示
|
|
|
// this.playerControScript.updateAcc({ xAxis: _ax, yAxis: _ay, zAxis: _az });
|
|
|
// this.playerControScript.updateAcc({ xAxis: deltaVector[0], yAxis: deltaVector[1], zAxis: deltaVector[2] });
|
|
|
// this.playerControScript.updateStr(deltaVector[3]);
|
|
|
- this.playerControScript.updateAcc({ xAxis: this.gyroOrientation[0], yAxis: this.gyroOrientation[1], zAxis: this.gyroOrientation[2] });
|
|
|
+ // this.playerControScript.updateAcc({ xAxis: this.gyroOrientation[0], yAxis: this.gyroOrientation[1], zAxis: this.gyroOrientation[2] });
|
|
|
// this.playerControScript.updateSqrt(_temp.resultant);
|
|
|
|
|
|
this.lineOriSqrt.onUpdateDraw(gy);
|
|
|
@@ -966,40 +939,8 @@ cc.Class({
|
|
|
|
|
|
|
|
|
if (this.BLEAccIndex > 150) {
|
|
|
-
|
|
|
this.onClear();
|
|
|
-
|
|
|
this.bJump = false;
|
|
|
-
|
|
|
- return;
|
|
|
- if (!this.bJump) {
|
|
|
- uni.postMessage({
|
|
|
- data: {
|
|
|
- funName: "writeBLEConnectionValue",
|
|
|
- gameData: {
|
|
|
- value: '4'
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- uni.postMessage({
|
|
|
- data: {
|
|
|
- funName: "writeBLEConnectionValue",
|
|
|
- gameData: {
|
|
|
- value: '6'
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- this.onClear();
|
|
|
-
|
|
|
- this.bJump = false;
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
this.BLEAccIndex++;
|
|
|
|
|
|
@@ -1007,12 +948,12 @@ cc.Class({
|
|
|
},
|
|
|
|
|
|
onClear() {
|
|
|
- this.lineX.clear();
|
|
|
+ // this.lineX.clear();
|
|
|
this.lineZ.clear();
|
|
|
// this.lineY.clear();
|
|
|
|
|
|
this.lineLinearX.clear();
|
|
|
- this.lineLinearY.clear();
|
|
|
+ // this.lineLinearY.clear();
|
|
|
this.lineLinearZ.clear();
|
|
|
|
|
|
this.lineSqrt.clear();
|
|
|
@@ -1057,6 +998,27 @@ cc.Class({
|
|
|
console.log(this.gyroMatrix.length);
|
|
|
},
|
|
|
|
|
|
+ onSaveData(data) {
|
|
|
+ uni.postMessage({
|
|
|
+ data: {
|
|
|
+ funName: "saveData",
|
|
|
+ gameData: {
|
|
|
+ value: data
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onGetData() {
|
|
|
+ uni.postMessage({
|
|
|
+ data: {
|
|
|
+ funName: "getData",
|
|
|
+ gameData: {}
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
onOnlySendWriteBLEDataValue(event, data) {
|
|
|
console.log(data);
|
|
|
uni.postMessage({
|
|
|
@@ -1368,11 +1330,12 @@ cc.Class({
|
|
|
},
|
|
|
|
|
|
|
|
|
- calculateAccMagOrientation(accel) {
|
|
|
+ calculateAccMagOrientation() {
|
|
|
// magnet
|
|
|
- if (this.getRotationMatrix(this.rotationMatrix, null, accel, [1, 1, 1])) {
|
|
|
+ if (this.getRotationMatrix(this.rotationMatrix, null, this.accel, [1, 1, 1])) {
|
|
|
this.getOrientation(this.rotationMatrix, this.accMagOrientation);
|
|
|
}
|
|
|
+ // this.getOrientation(this.rotationMatrix, this.accel);
|
|
|
},
|
|
|
|
|
|
getRotationMatrix(R, I, gravity, geomagnetic) {
|
|
|
@@ -1445,5 +1408,78 @@ cc.Class({
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
+ },
|
|
|
+
|
|
|
+ gyroFunction(gyroValues, timeMs) {
|
|
|
+ // don't start until first accelerometer/magnetometer orientation has been acquired
|
|
|
+ if (this.accMagOrientation == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ // initialisation of the gyroscope based rotation matrix
|
|
|
+ if (this.initState) {
|
|
|
+ let initMatrix = new Array(9);
|
|
|
+ initMatrix = this.getRotationMatrixFromOrientation(this.accMagOrientation);
|
|
|
+ let test = new Array(3);
|
|
|
+ this.getOrientation(initMatrix, test);
|
|
|
+ this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, initMatrix);
|
|
|
+ this.initState = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // copy the new gyro values into the gyro array
|
|
|
+ // convert the raw gyro data into a rotation vector
|
|
|
+ let deltaVector = new Array(4);
|
|
|
+ // if (this.timestamp != 0) {
|
|
|
+
|
|
|
+ // }
|
|
|
+ let dT = (timeMs - this.timestamp) * this.MS2S;
|
|
|
+ this.gyro = [];
|
|
|
+ gyroValues.forEach((item) => this.gyro.push(item));
|
|
|
+
|
|
|
+ this.getRotationVectorFromGyro(this.gyro, deltaVector, dT / 2.0);
|
|
|
+
|
|
|
+ // measurement done, save current time for next interval
|
|
|
+ this.timestamp = timeMs;
|
|
|
+ // convert rotation vector into rotation matrix
|
|
|
+ let deltaMatrix = new Array(9);
|
|
|
+ // console.log("deltaVector1:" + deltaVector);
|
|
|
+ // console.log("deltaMatrix1:" + deltaMatrix);
|
|
|
+ this.getRotationMatrixFromVector(deltaMatrix, deltaVector);
|
|
|
+ // console.log("deltaVector2:" + deltaVector);
|
|
|
+ // console.log("deltaMatrix2:" + deltaMatrix);
|
|
|
+ // apply the new rotation interval on the gyroscope based rotation matrix
|
|
|
+ this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, deltaMatrix);
|
|
|
+ // console.log(this.gyroMatrix);
|
|
|
+ // console.log(this.gyroMatrix.length);
|
|
|
+ // get the gyroscope based orientation from the rotation matrix
|
|
|
+ this.getOrientation(this.gyroMatrix, this.gyroOrientation);
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主要计算
|
|
|
+ */
|
|
|
+ calculateFusedOrientationTask() {
|
|
|
+
|
|
|
+ let FILTER_COEFFICIENT = 0.98;
|
|
|
+
|
|
|
+ let oneMinusCoeff = 1.0 - FILTER_COEFFICIENT;
|
|
|
+ this.fusedOrientation[0] =
|
|
|
+ FILTER_COEFFICIENT * this.gyroOrientation[0]
|
|
|
+ + oneMinusCoeff * this.accMagOrientation[0];
|
|
|
+
|
|
|
+ this.fusedOrientation[1] =
|
|
|
+ FILTER_COEFFICIENT * this.gyroOrientation[1]
|
|
|
+ + oneMinusCoeff * this.accMagOrientation[1];
|
|
|
+
|
|
|
+ this.fusedOrientation[2] =
|
|
|
+ FILTER_COEFFICIENT * this.gyroOrientation[2]
|
|
|
+ + oneMinusCoeff * this.accMagOrientation[2];
|
|
|
+
|
|
|
+ // overwrite gyro matrix and orientation with fused orientation
|
|
|
+ // to comensate gyro drift
|
|
|
+ this.gyroMatrix = this.getRotationMatrixFromOrientation(this.fusedOrientation);
|
|
|
+ // System.arraycopy(fusedOrientation, 0, gyroOrientation, 0, 3);
|
|
|
+ this.gyroOrientation = [];
|
|
|
+ this.fusedOrientation.forEach((item) => this.gyroOrientation.push(item));
|
|
|
+
|
|
|
}
|
|
|
});
|