在我目前的项目中,我试图通过压力和温度测量来计算高度。我已经设法将从传感器收集的三种类型的数据(温度,压力,安全带[0或1]的状态)发送到功能节点,在那里它们可以一起处理。压力和温度由两个元素组成:环境[t0,t1],压力[pr0,pr1]。数据每2秒到达一次功能节点。
我想根据以下逻辑计算实际高度:
1)当第一个环境和压力数组到达时,我检索t0,pr0,计算初始海拔 hInit ~t0 / PR0;
2)之后,将从t1,pr1,t2,pr2 ...... tN,prN计算出的进一步高度 hChecked 将与初始高度进行比较,初始高度将给出实际高度h。 h = hChecked - hInitial ;
3)如果h < 0我们需要选择另一个初始高度,即检索并存储新的t0,pr0;
4)如果h> 3我们需要检查皮带的状态。如果1 - 状态是安全的;如果0 - 锁定腰带;
我有以下代码:
if(ambient !== null && pressure !== null && lockerState != null) {
var hInit;
var hChecked;
var h;
//p0 is the hardcoded pressure on the level of the sea
//for the current area
var p0 = 1019;
//assing new variables for initital pressure and temp
var tInit = ambient[0];
var pInit = pressure[0];
//variables for the checked pressure and temp
var tChecked = ambient[1];
var pChecked = pressure[1];
//altitude hInit (hInit) is measure when the testbest is turned on
hInit = (((Math.pow((p0/pInit), (1/5.257)))-1)*(tInit + 273.15))/0.0065;
//hChecked is the measured altitude afterwards
hChecked = (((Math.pow((p0/pChecked), (1/5.257)))-1)*(tChecked + 273.15))/0.0065;
//h is the actual altitude the worker is working on
h = hChecked - hInit;
//in the case if a worker turned the testbed on
//when he was operating on the altitude he then
//might go down so altitude can reduce.
//therefore if the altitude h is < 0 we need to
//calculate a new reference
if (h < 0) {
var tInit = ambient[0];
var pInit = pressure[0];
var tChecked = ambient[1];
var pChecked = pressure[1];
hInit = (((Math.pow((p0/pInit), (1/5.257)))-1)*(tInit + 273.15))/0.0065;
hChecked = (((Math.pow((p0/pChecked), (1/5.257)))-1)*(tChecked + 273.15))/0.0065;
h = hChecked - hInit;
}
//check current altitude
while (h>=0) {
if (h>2) {
if (lockerState == 1) {
msg.payload = "safe";
return msg;
} else if (lockerState === 0) {
msg.payload = "lock your belt!";
//basically i want to send a 1 signal
//to the buzzer which is a pin on the RPI3
//so probably msg.payload = 1;
return msg;
}
}
}
} else return msg;
我的问题是系统无法存储初始数据t0,pr0从第一个环境和压力数组在不改变它的情况下打开。每次程序开始执行代码时,它都会改变t0和pr0。我想要实现的是当h小于0时改变初始数据。
如果有人可以分享如何解决这个问题的线索,将不胜感激