From: David Schleef Date: Wed, 10 Oct 2001 22:07:53 +0000 (+0000) Subject: Cleanups, change log level for many operations, added info for some X-Git-Tag: r0_7_17~15 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b369fac84c2128b0dabb3145ee6e7a1b807e0072;p=comedilib.git Cleanups, change log level for many operations, added info for some ni boards --- diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 897e1c0..63d18d1 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -151,6 +151,7 @@ typedef struct { }linear_fit_t; int linear_fit_monotonic(linear_fit_t *l); double linear_fit_func_y(linear_fit_t *l,double x); +double linear_fit_func_x(linear_fit_t *l,double y); double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac); /* slowly varying measurements */ diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index c93e2d9..856e9ff 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -110,6 +110,8 @@ int main(int argc, char *argv[]) c = getopt_long(argc, argv, "f:vq", options, &index); if (c == -1)break; switch (c) { + case 0: + continue; case 'f': fn = optarg; break; @@ -126,7 +128,7 @@ int main(int argc, char *argv[]) devicename = optarg; break; default: - printf("bad option\n"); + printf("bad option %d\n",c); exit(1); } } @@ -162,7 +164,7 @@ ok: if(device_status\n"); - if(verbose<0)verbose=0; + if(verbose<1)verbose=1; if(device_status==STATUS_UNKNOWN){ do_reset=1; do_dump=1; @@ -219,7 +221,9 @@ void observe(void) preobserve(i); DPRINT(0,"%s\n",observables[i].name); measure_observable(i); - observable_dependence(i); + if(verbose>=1){ + observable_dependence(i); + } } } @@ -246,7 +250,7 @@ void measure_observable(int obs) n=new_sv_measure(&sv); sci_sprint_alt(s,sv.average,sv.error); - printf("offset %s, target %g\n",s,observables[obs].target); + DPRINT(0,"offset %s, target %g\n",s,observables[obs].target); } void observable_dependence(int obs) @@ -271,11 +275,12 @@ void postgain_cal(int obs1, int obs2, int dac) double gain; comedi_range *range1,*range2; - DPRINT(0,"postgain calibration\n"); + DPRINT(0,"postgain: %s; %s\n",observables[obs1].name, + observables[obs2].name); preobserve(obs1); check_gain_chan_x(&l,observables[obs1].observe_insn.chanspec,dac); offset1=linear_fit_func_y(&l,caldacs[dac].current); - DPRINT(1,"obs1: [%d] offset %g\n",obs1,offset1); + DPRINT(2,"obs1: [%d] offset %g\n",obs1,offset1); range1 = comedi_get_range(dev,observables[obs1].observe_insn.subdev, CR_CHAN(observables[obs1].observe_insn.chanspec), CR_RANGE(observables[obs1].observe_insn.chanspec)); @@ -284,18 +289,18 @@ void postgain_cal(int obs1, int obs2, int dac) preobserve(obs2); check_gain_chan_x(&l,observables[obs2].observe_insn.chanspec,dac); offset2=linear_fit_func_y(&l,caldacs[dac].current); - DPRINT(1,"obs2: [%d] offset %g\n",obs2,offset2); + DPRINT(2,"obs2: [%d] offset %g\n",obs2,offset2); range2 = comedi_get_range(dev,observables[obs2].observe_insn.subdev, CR_CHAN(observables[obs2].observe_insn.chanspec), CR_RANGE(observables[obs2].observe_insn.chanspec)); slope2=l.slope; gain = (range1->max-range1->min)/(range2->max-range2->min); - DPRINT(3,"range1 %g range2 %g\n", range1->max-range1->min, + DPRINT(4,"range1 %g range2 %g\n", range1->max-range1->min, range2->max-range2->min); - DPRINT(2,"gain: %g\n",gain); + DPRINT(3,"gain: %g\n",gain); - DPRINT(2,"difference: %g\n",offset2-offset1); + DPRINT(3,"difference: %g\n",offset2-offset1); a = (offset1-offset2)/(slope1-slope2); a=caldacs[dac].current-a; @@ -317,30 +322,24 @@ void postgain_cal(int obs1, int obs2, int dac) void cal1(int obs, int dac) { linear_fit_t l; - double offset; - double target; - double gain; double a; - DPRINT(0,"cal1\n"); + DPRINT(0,"linear: %s\n",observables[obs].name); preobserve(obs); check_gain_chan_x(&l,observables[obs].observe_insn.chanspec,dac); - offset=linear_fit_func_y(&l,caldacs[dac].current); - gain=l.slope; - - target = observables[obs].target; - a=caldacs[dac].current+(target-offset)/gain; + a=linear_fit_func_x(&l,observables[obs].target); caldacs[dac].current=rint(a); update_caldac(dac); usleep(100000); DPRINT(0,"caldac[%d] set to %g\n",dac,a); - if(verbose>=2){ + if(verbose>=3){ measure_observable(obs); } } +#if 0 void chan_cal(int adc,int cdac,int range,double target) { linear_fit_t l; @@ -359,11 +358,12 @@ void chan_cal(int adc,int cdac,int range,double target) update_caldac(cdac); read_chan2(s,adc,range); - DPRINT(0,"caldac[%d] set to %g, offset=%s\n",cdac,a,s); + DPRINT(1,"caldac[%d] set to %g, offset=%s\n",cdac,a,s); } +#endif - +#if 0 void channel_dependence(int adc,int range) { int i; @@ -373,7 +373,9 @@ void channel_dependence(int adc,int range) gain=check_gain_chan(adc,range,i); } } +#endif +#if 0 void caldac_dependence(int caldac) { int i; @@ -383,13 +385,16 @@ void caldac_dependence(int caldac) gain=check_gain_chan(i,0,caldac); } } +#endif +#if 0 void dump_curve(int adc,int caldac) { linear_fit_t l; check_gain_chan_x(&l,CR_PACK(adc,0,AREF_OTHER),caldac); } +#endif void setup_caldacs(void) @@ -427,13 +432,13 @@ void update_caldac(int i) { int ret; - DPRINT(3,"update %d %d %d\n",caldacs[i].subdev,caldacs[i].chan,caldacs[i].current); + DPRINT(4,"update %d %d %d\n",caldacs[i].subdev,caldacs[i].chan,caldacs[i].current); if(caldacs[i].current<0){ - DPRINT(0,"caldac set out of range (%d<0)\n",caldacs[i].current); + DPRINT(1,"caldac set out of range (%d<0)\n",caldacs[i].current); caldacs[i].current=0; } if(caldacs[i].current>caldacs[i].maxdata){ - DPRINT(0,"caldac set out of range (%d>%d)\n", + DPRINT(1,"caldac set out of range (%d>%d)\n", caldacs[i].current,caldacs[i].maxdata); caldacs[i].current=caldacs[i].maxdata; } @@ -443,7 +448,7 @@ void update_caldac(int i) if(ret<0)perror("update_caldac()"); } - +#if 0 void check_gain(int ad_chan,int range) { int i; @@ -452,13 +457,16 @@ void check_gain(int ad_chan,int range) check_gain_chan(ad_chan,range,i); } } +#endif +#if 0 double check_gain_chan(int ad_chan,int range,int cdac) { linear_fit_t l; return check_gain_chan_x(&l,CR_PACK(ad_chan,range,AREF_OTHER),cdac); } +#endif double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) { @@ -520,14 +528,14 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) linear_fit_monotonic(l); - if(verbose>=1 || (verbose>=0 && fabs(l->slope/l->err_slope)>4.0)){ + if(verbose>=2 || (verbose>=1 && fabs(l->slope/l->err_slope)>4.0)){ sci_sprint_alt(str,l->slope,l->err_slope); printf("caldac[%d] gain=%s V/bit S_min=%g dof=%g\n", cdac,str,l->S_min,l->dof); //printf("--> %g\n",fabs(l.slope/l.err_slope)); } - if(verbose>=2){ + if(verbose>=3){ static int dump_number=0; double x,y; @@ -652,6 +660,7 @@ int read_chan2(char *s,int adc,int range) return sci_sprint_alt(s,sv.average,sv.error); } +#if 0 void set_ao(comedi_t *dev,int subdev,int chan,int range,double value) { comedi_range *r = comedi_get_range(dev,subdev,chan,range); @@ -662,6 +671,7 @@ void set_ao(comedi_t *dev,int subdev,int chan,int range,double value) comedi_data_write(dev,subdev,chan,range,AREF_GROUND,data); } +#endif int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int aref) @@ -876,6 +886,11 @@ double linear_fit_func_y(linear_fit_t *l,double x) return l->ave_y+l->slope*(x-l->ave_x); } +double linear_fit_func_x(linear_fit_t *l,double y) +{ + return l->ave_x+(y-l->ave_y)/l->slope; +} + /* printing of scientific numbers (with errors) */ diff --git a/comedi_calibrate/ni.c b/comedi_calibrate/ni.c index f5ae51b..42d9607 100644 --- a/comedi_calibrate/ni.c +++ b/comedi_calibrate/ni.c @@ -45,24 +45,28 @@ struct board_struct{ void ni_setup_board(void); void ni_setup_observables(void); -void cal_ni_16e_1(void); +void cal_ni_at_mio_16e_2(void); void cal_ni_daqcard_ai_16xe_50(void); -void cal_ni_6035e(void); -void cal_ni_6071e(void); -void cal_ni_16e_10(void); -void cal_ni_16xe_50(void); +void cal_ni_at_mio_16e_1(void); +void cal_ni_pci_mio_16e_1(void); +void cal_ni_pci_6035e(void); +void cal_ni_pci_6071e(void); +void cal_ni_pxi_6071e(void); +void cal_ni_at_mio_16e_10(void); +void cal_ni_pci_mio_16xe_50(void); +void cal_ni_pci_6023e(void); struct board_struct boards[]={ - { "at-mio-16e-2", STATUS_DONE, cal_ni_16e_1 }, + { "at-mio-16e-2", STATUS_SOME, cal_ni_at_mio_16e_2 }, { "DAQCard-ai-16xe-50", STATUS_DONE, cal_ni_daqcard_ai_16xe_50 }, - { "at-mio-16e-1", STATUS_SOME, cal_ni_16e_1 }, - { "pci-mio-16e-1", STATUS_SOME, cal_ni_16e_1 }, - { "pci-6035e", STATUS_GUESS, cal_ni_6035e }, - { "pci-6071e", STATUS_GUESS, cal_ni_6071e }, - { "pxi-6071e", STATUS_GUESS, cal_ni_6071e }, - { "at-mio-16e-10", STATUS_GUESS, cal_ni_16e_10 }, - { "pci-mio-16xe-50", STATUS_GUESS, cal_ni_16xe_50 }, - { "pci-6023e", STATUS_GUESS, cal_ni_6035e }, + { "at-mio-16e-1", STATUS_SOME, cal_ni_at_mio_16e_1 }, + { "pci-mio-16e-1", STATUS_SOME, cal_ni_pci_mio_16e_1 }, + { "pci-6035e", STATUS_GUESS, cal_ni_pci_6035e }, + { "pci-6071e", STATUS_GUESS, cal_ni_pci_6071e }, + { "pxi-6071e", STATUS_GUESS, cal_ni_pxi_6071e }, + { "at-mio-16e-10", STATUS_GUESS, cal_ni_at_mio_16e_10 }, + { "pci-mio-16xe-50", STATUS_GUESS, cal_ni_pci_mio_16xe_50 }, + { "pci-6023e", STATUS_GUESS, cal_ni_pci_6023e }, #if 0 // { "at-mio-16de-10", cal_ni_unknown }, { "at-mio-64e-3", cal_ni_16e_1 }, @@ -169,6 +173,8 @@ void ni_setup_observables(void) o->observe_insn.chanspec = CR_PACK(5,bipolar_lowgain,AREF_OTHER); o->target = voltage_reference; + n_observables = ni_reference_low + 1; + if(unipolar_lowgain>=0){ /* unip/bip offset */ o = observables + ni_unip_offset_low; @@ -188,6 +194,7 @@ void ni_setup_observables(void) o->target = voltage_reference; i++; #endif + n_observables = ni_unip_offset_low + 1; } if(da_subdev>=0){ @@ -244,21 +251,12 @@ void ni_setup_observables(void) set_target(ni_ao1_reference,5.0); o->target -= voltage_reference; + n_observables = ni_ao1_reference + 1; } - n_observables = ni_ao1_reference + 1; } -void cal_ni_daqcard_ai_16xe_50(void) +void cal_ni_at_mio_16e_2(void) { - // daqcard - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - cal1(ni_zero_offset_high,8); - cal1(ni_reference_low,0); -} - -void cal_ni_16e_1(void) -{ - // 16e-2 postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); cal1(ni_zero_offset_high,0); cal1(ni_reference_low,3); @@ -271,36 +269,74 @@ void cal_ni_16e_1(void) } } -void cal_ni_16e_10(void) +/* + * Device name: DAQCard-ai-16xe-50 + * Comedi version: 0.7.60 + * ai, bipolar zero offset, low gain + * offset 5.87(63)e-3, target 0 + * caldac[0] gain=-2.243(21)e-6 V/bit S_min=208.079 dof=254 + * caldac[2] gain=1.56378(22)e-4 V/bit S_min=1782.91 dof=254 + * caldac[8] gain=2.499(14)e-7 V/bit S_min=234.915 dof=254 + * ai, bipolar zero offset, high gain + * offset 4.251(49)e-5, target 0 + * caldac[0] gain=-2.396(30)e-8 V/bit S_min=231.387 dof=254 + * caldac[2] gain=1.56428(28)e-6 V/bit S_min=829.096 dof=254 + * caldac[8] gain=2.61244(18)e-7 V/bit S_min=773.092 dof=254 + * ai, bipolar voltage reference, low gain + * offset 4.99650(81), target 5 + * caldac[0] gain=-3.78250(23)e-4 V/bit S_min=12207.6 dof=254 + * caldac[1] gain=-9.878(22)e-6 V/bit S_min=346.795 dof=254 + * caldac[2] gain=1.57172(23)e-4 V/bit S_min=969.526 dof=254 + * caldac[8] gain=2.795(14)e-7 V/bit S_min=245.703 dof=254 + * ai, unipolar zero offset, low gain + * offset 0.0133(14), target 0 + * caldac[0] gain=3.73923(29)e-4 V/bit S_min=2855.79 dof=151 + * caldac[1] gain=9.784(11)e-6 V/bit S_min=727.295 dof=254 + * caldac[2] gain=7.8670(11)e-5 V/bit S_min=903.291 dof=254 + * caldac[8] gain=2.7732(74)e-7 V/bit S_min=415.399 dof=254 + */ +void cal_ni_daqcard_ai_16xe_50(void) { - // 16e-10 (old) + postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); + cal1(ni_zero_offset_high,8); + cal1(ni_reference_low,0); +} + +void cal_ni_at_mio_16e_1(void) +{ + cal_ni_at_mio_16e_2(); +} + +void cal_ni_pci_mio_16e_1(void) +{ + cal_ni_at_mio_16e_2(); +} + +void cal_ni_pci_6035e(void) +{ + // 6035e (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,10); cal1(ni_zero_offset_high,0); cal1(ni_reference_low,3); - cal1(ni_unip_offset_low,2); if(do_output){ - cal1(ni_ao0_zero_offset,5); // guess - cal1(ni_ao0_reference,6); // guess - cal1(ni_ao0_zero_offset,8); // guess - cal1(ni_ao0_reference,9); // guess + // unknown } } -void cal_ni_16xe_50(void) +void cal_ni_pci_6071e(void) { - // 16xe-50 (old) (same as daqcard?) - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - cal1(ni_zero_offset_high,8); - cal1(ni_reference_low,0); + // 6071e (old) + postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); + cal1(ni_zero_offset_high,0); + cal1(ni_reference_low,3); if(do_output){ // unknown } } -void cal_ni_6035e(void) +void cal_ni_pxi_6071e(void) { - // 6035e (old) + // 6071e (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); cal1(ni_zero_offset_high,0); cal1(ni_reference_low,3); @@ -309,17 +345,37 @@ void cal_ni_6035e(void) } } -void cal_ni_6071e(void) +void cal_ni_at_mio_16e_10(void) { - // 6071e (old) + // 16e-10 (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); + cal1(ni_zero_offset_high,10); cal1(ni_zero_offset_high,0); cal1(ni_reference_low,3); + cal1(ni_unip_offset_low,2); + if(do_output){ + cal1(ni_ao0_zero_offset,5); // guess + cal1(ni_ao0_reference,6); // guess + cal1(ni_ao0_zero_offset,8); // guess + cal1(ni_ao0_reference,9); // guess + } +} + +void cal_ni_pci_mio_16xe_50(void) +{ + // 16xe-50 (old) (same as daqcard?) + postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); + cal1(ni_zero_offset_high,8); + cal1(ni_reference_low,0); if(do_output){ // unknown } } +void cal_ni_pci_6023e(void) +{ + cal_ni_pci_6035e(); +} double ni_get_reference(int lsb_loc,int msb_loc) { @@ -339,92 +395,7 @@ double ni_get_reference(int lsb_loc,int msb_loc) return ref; } -void cal_ni_unknown(void) -{ - comedi_range *range; - int bipolar_lowgain; - int bipolar_highgain; - int unipolar_lowgain; - int have_ao = 1; - - reset_caldacs(); - printf("Warning: device not calibrated due to insufficient information\n"); - printf("Please send this output to \n"); - printf("$Id$\n"); - printf("Device name: %s\n",comedi_get_board_name(dev)); - printf("Comedi version: %d.%d.%d\n", - (comedi_get_version_code(dev)>>16)&0xff, - (comedi_get_version_code(dev)>>8)&0xff, - (comedi_get_version_code(dev))&0xff); - - bipolar_lowgain = get_bipolar_lowgain(dev,ad_subdev); - bipolar_highgain = get_bipolar_highgain(dev,ad_subdev); - unipolar_lowgain = get_unipolar_lowgain(dev,ad_subdev); - - /* 0 offset, low gain */ - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"bipolar zero offset, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(0,bipolar_lowgain); - - /* 0 offset, high gain */ - range = comedi_get_range(dev,ad_subdev,0,bipolar_highgain); - DPRINT(0,"bipolar zero offset, high gain [%g,%g]\n", - range->min,range->max); - channel_dependence(0,bipolar_highgain); - - /* unip/bip offset */ - range = comedi_get_range(dev,ad_subdev,0,unipolar_lowgain); - DPRINT(0,"unipolar zero offset, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(0,unipolar_lowgain); - - /* voltage reference */ - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"bipolar voltage reference, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(5,bipolar_lowgain); - - have_ao = (comedi_get_subdevice_type(dev,da_subdev)==COMEDI_SUBD_AO); - if(have_ao){ - int ao_chan; - - /* ao 0, zero offset */ - ao_chan = 0; - set_ao(dev,da_subdev,ao_chan,0,0.0); - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"ao 0, zero offset, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(2,bipolar_lowgain); - - /* ao 0, gain */ - ao_chan = 0; - set_ao(dev,da_subdev,ao_chan,0,5.0); - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"ao 0, gain, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(6,bipolar_lowgain); - - /* ao 1, zero offset */ - ao_chan = 1; - set_ao(dev,da_subdev,ao_chan,0,0.0); - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"ao 1, zero offset, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(3,bipolar_lowgain); - - /* ao 1, gain */ - ao_chan = 1; - set_ao(dev,da_subdev,ao_chan,0,5.0); - range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain); - DPRINT(0,"ao 1, gain, low gain [%g,%g]\n", - range->min,range->max); - channel_dependence(7,bipolar_lowgain); - } - - cal_ni_results(); -} - +#if 0 void cal_ni_results(void) { comedi_range *range; @@ -458,7 +429,6 @@ void cal_ni_results(void) } -#if 0 void ni_mio_ai_postgain_cal(void) { linear_fit_t l;