当前位置: 首页>>代码示例>>Python>>正文


Python Sensor.getSample方法代码示例

本文整理汇总了Python中sensor.Sensor.getSample方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.getSample方法的具体用法?Python Sensor.getSample怎么用?Python Sensor.getSample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor.Sensor的用法示例。


在下文中一共展示了Sensor.getSample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Echidna

# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import getSample [as 别名]
class Echidna(object):
    
    def __init__(self, sensor_server="172.17.5.180", 
                       sensor_port=5555,
                       sensor_sample_rate=100000,
                       sensor_tx_freq=1000,
                       gantry_server="172.17.5.100", 
                       gantry_port=5007,
                       store_filename="data.log"):
        
        self.robot = Gantry(host=gantry_server,port=gantry_port)
        self.sensor = Sensor(server=sensor_server,
                        port=sensor_port,
                        sample_rate=sensor_sample_rate,
                        tx_freq=sensor_tx_freq)
                        
        self.transmitter = siggen
        self.transmitter.setFrequency(sensor_tx_freq)
        self.transmitter.setVoltage(-2,2)
        self.transmitter.turnOn()
        self._tx_freq = sensor_tx_freq
        
        self.store = DataStorage(store_filename)
        self.pos = Pos(0,0)
    
    def setStore(self,fname):
        if self.store.db.isopen:
            self.store.close()
        self.store = DataStorage(fname)
        
    def setTxFreq(self,freq):
        self._tx_freq = freq
        self.transmitter.setFrequency(freq)
        self.sensor.tx_freq = freq
        
    def stepOverTank(self,fname="tank"):
        self.pos = self.discretizeTank()
        x_size = self.pos.shape[0]
        y_size = self.pos.shape[1]
        for x in range(x_size):            
            for y in range(y_size):
                p = self.pos[x,y]                
                logger.info("Moving to (%f, %f)" % (p[0],p[1]))
                self.robot.moveAndWait(p[0],p[1], 60)
                d = self.sensor.getSample(100)
                fig, samp = self.plotRadar(5)
                fig.savefig(fname + "-x%3.2f-y%3.2f(x%d,y%d).tiff" % (p[0],p[1],x,y))
                plt.close(fig)
                d.setPos(p, (x,y))
                self.store.save(d)                
                    
    def stepOverPos(self,pos,fname="target"):
        self.count = 0
        self.pos = pos
        x_size = self.pos.shape[0]
        y_size = self.pos.shape[1]
        for x in range(x_size):            
            for y in range(y_size):
                p = self.pos[x,y]                
                logger.info("Moving to (%f, %f)" % (p[0],p[1]))
                self.robot.move(p[0],p[1], 70)
                #d = self.sensor.getSample(25)
                fig, d = self.plotRadar()
                d.setPos(p)
                self.store.save(d)                            
                fig.savefig("%d-" % self.count + fname + "-x%3.2f-y%3.2f.tiff" % (p[0],p[1]))
                plt.close(fig)                
                while(self.robot.busy()):
                    time.sleep(0.5)                
                self.count = self.count + 1
                        
    def freqSweep(self,start,stop,step=1, nsamps=100):
        self.count = 0                
        range = np.arange(start,stop,step)   
        samples = []
        for freq in range:
            logger.info("%d | Sampling frequency: %f" % (self.count,freq))
            self.setTxFreq(freq)
            d = self.sensor.getSample(nsamps)            
            d.setPos(self.pos.astuple())
            self.store.save(d)                                                                    
            self.count = self.count + 1
            samples.append(d)
        
        return samples     
        
    def discretizeTank(self, width=23.5, length=23.5, steps=50.0):
        x_steps = np.round(np.arange(0,width,width/steps),2)
        y_steps = np.round(np.arange(0,length,length/steps),2)
        pos = np.zeros((x_steps.size,y_steps.size, 2))
        for i in range(x_steps.size):
            for j in range(y_steps.size):
                pos[i][j][0] = x_steps[i]
                pos[i][j][1] = y_steps[j]
        
        return pos
         

    def learn_baseline(self, samples=250):
        self.sample_baseline = self.sensor.getSample(samples)
#.........这里部分代码省略.........
开发者ID:henryeherman,项目名称:echidna,代码行数:103,代码来源:echidna.py


注:本文中的sensor.Sensor.getSample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。