pir sensor和ir sensor的区别
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pir sensor和ir sensor的区别相关的知识,希望对你有一定的参考价值。
Sensor 是传感器的统称,把现实中物理存在的信号转换成电信号。 Switch 是开关的意思,它是被包含在Sensor中的,比如光电开关,它其实就是一种传感器。 参考技术A PIR主要强调在P(passive)被动上,因为仅被动接收红外线,不主动发射任何辐射,所以成本低、功耗小、尺寸小巧。PIR内部一般是2个探测元反向串联(高级的也有4个的,更多的不常见)。物体静止或没有物体时,两个探测元的输入一致,极性相反,电压抵消;物体通过时,两个探测元感受到的红外信号不平衡,产生电压差,就认为检测到有物体经过。但是也正因如此,他的检测方式受限制,仅能探测物体(与环境背景温度有偏差的物体,一般PIRs要求物体温度高于环境至少4~8℃)运动,但是如果物体静止就检测不到了。如果你以前看过一些关于蛇的纪录片,应该知道蛇眼中的世界,很类似PIR。比如一个青蛙,如果运动时,蛇可以看到;静止时,则好像突然消失了。IR sensor就是正常的红外传感器,军事上常用的热成像仪,即使物体(同样需要与环境背景温度有差别)不移动,由于有温度差还是能检测到。对比PIR好处时实时能检测,配合算法可以自动判断出物体类型,运动状态等;坏处是尺寸大、价格高、功耗惊人(对比PIRs来说)、同时很多需要注意制冷散热(近几年很多厂家倒是出了不少无需制冷散热的sensor)。
flink笔记10 [实验]体验ProcessingTime和指定EventTime下的区别
体验ProcessingTime和指定EventTime下的区别
实验数据
sensor_1,1619492107,36.2
sensor_1,1619492108,36.0
sensor_1,1619492109,36.5
sensor_1,1619492110,34.3
sensor_1,1619492111,34.3
sensor_1,1619492112,34.3
sensor_1,1619492113,34.3
sensor_1,1619492114,34.3
sensor_1,1619492115,34.3
sensor_1,1619492116,34.3
sensor_1,1619492117,34.3
sensor_1,1619492118,34.3
sensor_1,1619492119,34.3
sensor_1,1619492120,36.2
sensor_1,1619492121,36.1
sensor_1,1619492122,36.5
sensor_1,1619492123,35.2
sensor_1,1619492124,36.2
sensor_1,1619492125,36.1
sensor_1,1619492126,36.5
sensor_1,1619492127,36.2
sensor_1,1619492128,36.1
sensor_1,1619492129,36.3
sensor_1,1619492130,36.2
sensor_1,1619492131,36.2
sensor_1,1619492132,36.2
sensor_1,1619492170,36.2
sensor_1,1619492171,36.5
sensor_1,1619492172,37.3
sensor_1,1619492173,36.2
sensor_1,1619492174,36.3
sensor_1,1619492175,36.1
sensor_1,1619492176,36.6
sensor_1,1619492177,36.5
sensor_1,1619492178,36.1
sensor_1,1619492179,36.8
sensor_1,1619492180,36.1
sensor_1,1619492209,36.5
实验代码
(一) EventTime
import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.functions.timestamps.BoundedOutOfOrdernessTimestampExtractor
import org.apache.flink.streaming.api.scala.{StreamExecutionEnvironment, createTypeInformation}
import org.apache.flink.streaming.api.windowing.time.Time
import org.tysy.window_api.sensorReading
import java.util.Date
object window_eventtime {
def main(args: Array[String]): Unit = {
val env = StreamExecutionEnvironment.getExecutionEnvironment
env.setParallelism(1)
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
val inputStream = env.socketTextStream("localhost",7777)
val resultStream = inputStream
.map(data =>{
val arr = data.split(",")
sensorReading(arr(0),arr(1).toLong,arr(2).toDouble)
})
.assignAscendingTimestamps(_.timestamp * 1000)
.assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor[sensorReading](Time.seconds(3)) {
override def extractTimestamp(element: sensorReading): Long = element.timestamp * 1000L
} )
.keyBy(_.id)
.timeWindow(Time.seconds(15))
.reduce((data1,data2)=>sensorReading(data1.id,data2.timestamp,data1.temperature.min(data2.temperature)))
.map(data =>(data,new Date().getTime))
resultStream.print()
env.execute("window_eventtime test")
}
}
(二) ProcessingTime
import org.apache.flink.streaming.api.scala.{StreamExecutionEnvironment, createTypeInformation}
import org.apache.flink.streaming.api.windowing.time.Time
import org.tysy.window_api.sensorReading
import java.util.Date
object window_processingtime {
def main(args: Array[String]): Unit = {
val env = StreamExecutionEnvironment.getExecutionEnvironment
env.setParallelism(1)
val inputStream = env.socketTextStream("localhost",7777)
val resultStream = inputStream
.map(data =>{
val arr = data.split(",")
sensorReading(arr(0),arr(1).toLong,arr(2).toDouble)
})
.keyBy(_.id)
.timeWindow(Time.seconds(15))
.reduce((data1,data2)=>sensorReading(data1.id,data2.timestamp,data1.temperature.min(data2.temperature)))
.map(data =>(data,new Date().getTime))
resultStream.print()
env.execute("window_processingtime test")
}
}
实验结果
实验分析
①数据的最后一列是系统的时间戳。
②当使用的是ProcessingTime时,在同一个window里有多少条数据,和测试代码时在该window的时间内输入的代码条数有关,最后一列的时间戳可看出窗口大小15秒。
③当使用的是EventTime时,和输入数据的速度没有关系,只和实验中指定的时间戳大小有关。
以上是关于pir sensor和ir sensor的区别的主要内容,如果未能解决你的问题,请参考以下文章
flink笔记10 [实验]体验ProcessingTime和指定EventTime下的区别
flink笔记10 [实验]体验ProcessingTime和指定EventTime下的区别
flink笔记10 [实验]体验ProcessingTime和指定EventTime下的区别