def getY(self): self.lock.acquire() # Y1 = Y[0] #angle Y1_angle = comedi.comedi_data_read(self.device ,0 ,0 ,0 ,0) angle = comedi.comedi_to_phys(Y1_angle[1], self.range_info_input_1, self.maxdata_input_1) Y2_position = comedi.comedi_data_read(self.device ,0 ,1 ,0 ,0) position = comedi.comedi_to_phys(Y2_position[1], self.range_info_input_2, self.maxdata_input_2) Y = [position, 0.0, angle] self.lock.release() return Y
def read(self, context): device, subdevice, channel = _phys_channel(context) chk, value = c.comedi_data_read(device, subdevice, channel, 0, 0) # range, aref if chk < 0: raise ComediError("Failed to read on %s" % context.node) return value
def imagecapture_part(xb, yb, xe, ye, nx, ny, n): dev = comedi.comedi_open("/dev/comedi0") outsubdevice = 1 insubdevice = 0 xchannel = 0 ychannel = 1 inchannel = 0 analogref = comedi.AREF_GROUND arange = 0 image = numpy.zeros((nx,ny), float) for y in range(ny, 0, -1): y = y-1 write_data = int( (float(y)/(ny-1) *(ye-yb) + yb ) * 65535) msg = comedi.comedi_data_write(dev, outsubdevice, ychannel, arange, analogref, write_data) for x in range(0, nx): # print "( " + str(x) + ", " + str(y) + ")" write_data = int( (float(x)/(nx-1) * (xe-xb) + xb ) * 65535) msg = comedi.comedi_data_write(dev, outsubdevice, xchannel, arange, analogref, write_data) pixel = 0.0 for i in range(0, n): result = comedi.comedi_data_read(dev,insubdevice,inchannel,arange,analogref) pixel = pixel + float(result[1]) pixel = pixel/n # print pixel, msg=result[0] image[x][y] = pixel print comedi.comedi_close(dev) return image
def get(self): data = c.comedi_data_read(self.device0,self.subdevice,self.channel,self.range_num, c.AREF_GROUND) self.position=(c.comedi_to_phys(data[1],self.range_ds,self.maxdata)*self.gain+self.offset) t=time.time() #t_=datetime.datetime.now() #t=(((((((t_.year*12)+t_.month)*30+t_.day)*24+t_.hour)*60+t_.minute)*60+t_.second)*1000000)+t_.microsecond return ((t-t0), self.position)
def getimage(nx, ny, n): dev = comedi.comedi_open("/dev/comedi0") outsubdevice = 1 insubdevice = 0 xchannel = 0 ychannel = 1 inchannel = 0 analogref = comedi.AREF_GROUND arange = 0 image = numpy.zeros((nx,ny), float) for y in range(0, ny): write_data = int( (float(y)/(ny-1) ) * 65535) msg = comedi.comedi_data_write(dev, outsubdevice, ychannel, arange, analogref, write_data) for x in range(0, nx): write_data = int( (float(x)/(nx-1) ) * 65535) msg = comedi.comedi_data_write(dev, outsubdevice, xchannel, arange, analogref, write_data) pixel = 0.0 for i in range(0, n): result = comedi.comedi_data_read(dev,insubdevice,inchannel,arange,analogref) pixel = pixel + float(result[1]) pixel = pixel/n # print pixel, msg=result[0] image[x][y] = pixel # print comedi.comedi_close(dev) return pixel
def get(self): """Read the signal""" data = c.comedi_data_read(self.device0, self.subdevice, self.channel, self.range_num, c.AREF_GROUND) self.position = ( c.comedi_to_phys(data[1], self.range_ds, self.maxdata) * self.gain + self.offset) t = time.time() return (t, self.position)
def capture_all(): captured = [[None for _ in range(n_ranges)] for _ in CHANNELS] for chan_i, ch in enumerate(CHANNELS): for range_i, ran in enumerate(range(n_ranges)): ret, data = c.comedi_data_read(dev, SUBDEVICE, ch, ran, REFERENCE) phydata = c.comedi_to_phys(data, ranges[ran], maxdata) captured[chan_i][range_i] = (data, phydata) return captured
def get(self): data = c.comedi_data_read(self.device0, self.subdevice, self.channel, self.range_num, c.AREF_GROUND) self.position = ( c.comedi_to_phys(data[1], self.range_ds, self.maxdata) * self.gain + self.offset) t = time.time() #t_=datetime.datetime.now() #t=(((((((t_.year*12)+t_.month)*30+t_.day)*24+t_.hour)*60+t_.minute)*60+t_.second)*1000000)+t_.microsecond return ((t - t0), self.position)
def getData(self,channel_number="all"): """Read the signal for desired channel""" if channel_number=="all": result=[] for channel in range(self.nchans): data = c.comedi_data_read(self.device,self.subdevice, self.channels[channel], self.range_num[channel], c.AREF_GROUND) self.position=(c.comedi_to_phys(data[1],self.range_ds[channel], self.maxdata[channel])*self.gain[channel]+self.offset[channel]) result.append(self.position) t=time.time() return (t, result) else: data = c.comedi_data_read(self.device,self.subdevice, self.channels[channel_number], self.range_num[channel_number], c.AREF_GROUND) self.position=(c.comedi_to_phys(data[1],self.range_ds[channel_number], self.maxdata[channel_number])*self.gain[channel_number]+self.offset[channel_number]) t=time.time() return (t, self.position)
def read_raw(self): """ Read directly from 6 channels of the sensor and convert from uint-16 to voltage with no additional processing """ data_array = np.empty(self.num_channels) for chan in range(self.num_channels): #Read in data rc, data_array[chan] = comedi.comedi_data_read( self.dev, self.sub_device, chan, self.range, self.aref) #Convert unsigned 16-bit ints to voltages data_array[chan] = self.comedi_to_phys(data_array[chan]) #Multiply voltages by calibration matrix to get force/torque data = -np.matmul(self.cal_matrix, data_array) return data
def get_data(self, channel="all"): """To read the value on input_channels. If channel is specified, it will only read and return these channels. 'all' (default) will read all opened channels""" if channel == 'all': to_read = self.channels else: if not isinstance(channel, list): channel = [channel] to_read = [self.channels[self.channels_dict[i]] for i in channel] data = [time()] for chan in to_read: data_read = c.comedi_data_read(self.device, self.subdevice, chan['num'], chan['range_num'], c.AREF_GROUND) val = c.comedi_to_phys(data_read[1], chan['range_ds'], chan['maxdata']) data.append(val * chan['gain'] + chan['offset']) return data
time.sleep(PRE_MOTION_TIME) dev.set_vel_setpt(0) dev.set_mode('velocity') dev.start() start_time = time.time() t = 0 while t <= start_time + TOTAL_TIME_EXP: gin = stdscr.getch() if gin ==10: stdscr.addstr("experiment ended") stdscr.refresh() time.sleep(1) break else: rawAnalogIn = comedi.comedi_data_read(daq,subdev,chans[0],0,comedi.AREF_GROUND) voltsInLMR = comedi.comedi_to_phys(rawAnalogIn[1], cr[0], maxdata[0]) rawAnalogIn = comedi.comedi_data_read(daq,subdev,chans[1],0,comedi.AREF_GROUND) voltsInFreq = comedi.comedi_to_phys(rawAnalogIn[1], cr[1], maxdata[1]) vel = int(round(voltsInLMR*gain)) dev.set_dir_setpt(direction[(numpy.sign(vel)+1)/2], io_update=False) dev.set_vel_setpt(abs(vel)) t = time.time() pos = dev.get_pos() fd.write('%f %d %d %f %f\n'%(t,vel,pos,voltsInLMR,voltsInFreq))
def read(self, comediObject): ret, self.value = c.comedi_data_read(comediObject.device, comediObject.subdevice, self.channel, 0, 0) self.voltage = c.comedi_to_phys(self.value, comediObject.channelRange, comediObject.maxdata)
rdata = 0 # read data wdata = outputMaxdata/2 theRange = 0 aref = 0 # start the motor at zero speed: c.comedi_data_write(comediDevice, outputSubdev, channel, theRange, aref, wdata) while True: startTime = time.time() ret, rdata = c.comedi_data_read(comediDevice, inputSubdev, channel, theRange, aref) voltage = c.comedi_to_phys(rdata, inputRange, inputMaxdata); #print "Voltage: %f" % voltage x1 = voltage x2 = x1*voltage x3 = x2*voltage x4 = x3*voltage x5 = x4*voltage dist = -14.153*x5+110.18*x4-339.89*x3+538.13*x2-479.23*x1+243.35 #print "Distance: %f" % dist if dist > 50: wdata = outputMaxdata/2 + 1000
def get(self): """Read the signal""" data = c.comedi_data_read(self.device0,self.subdevice,self.channel,self.range_num, c.AREF_GROUND) self.position=(c.comedi_to_phys(data[1],self.range_ds,self.maxdata)*self.gain+self.offset) t=time.time() return (t, self.position)
nRanges = c.comedi_get_n_ranges(dev, subdev, channel) print "Ranges: %d" % nRanges crange = c.comedi_get_range(dev, subdev, channel, 0) print "comedi_get_range: %s" % str(crange) data = maxdata/2 rdata = 0 nChannels = 2 for i in range(100): for chan in range(nChannels): ret, rdata = c.comedi_data_read(dev, subdev, chan, 0, 0) #print "Read value: %d" % rdata voltage = c.comedi_to_phys(rdata, crange, maxdata); #print voltage x1 = voltage x2 = x1*voltage x3 = x2*voltage x4 = x3*voltage x5 = x4*voltage dist = -14.153*x5+110.18*x4-339.89*x3+538.13*x2-479.23*x1+243.35 print "Chan %d Distance: %f" % (chan, dist) print