instrument.h

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #ifndef __XSM_INSTRUMENT_H
00029 #define __XSM_INSTRUMENT_H
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 #include <cstdio>
00035 #include <cstdlib>
00036 #include <cmath>
00037 #include <cstring>
00038 
00039 #include <unistd.h>
00040 
00041 #include "xsmtypes.h"
00042 #include "xsmmasks.h"
00043 
00044 /* Instrumentendefinition */
00045 
00046 typedef enum OFFSET_MODE { OFM_UNDEFINED, OFM_DSP_OFFSET_ADDING, OFM_ANALOG_OFFSET_ADDING };
00047 
00048 class XSM_Instrument{
00049 public:
00050   XSM_Instrument(XSMRESOURCES &xsmres);
00051   virtual ~XSM_Instrument(){};
00052 
00053   double UOutLimit(double u){
00054     if(u>AnalogVMaxOut) { u=AnalogVMaxOut; }
00055     if(u<-AnalogVMaxOut) { u=-AnalogVMaxOut; }
00056     return u;
00057   };
00058 
00059   double UInLimit(double u){
00060     if(u>AnalogVMaxIn) { u=AnalogVMaxIn; }
00061     if(u<-AnalogVMaxIn) { u=-AnalogVMaxIn; }
00062     return u;
00063   };
00064   
00065   /* resultierende Grenzwerte */
00066   virtual double XRangeMax(){ return(xR*Vx); };
00067   virtual double YRangeMax(){ return(yR*Vy); };
00068   virtual double ZRangeMax(){ return(zR*Vz); };
00069 
00070   virtual double X0RangeMax(){ return(xR*Vx0); };
00071   virtual double Y0RangeMax(){ return(yR*Vy0); };
00072   virtual double Z0RangeMax(){ return(zR*Vz0); };
00073 
00074   virtual double XScanRangeMax(){ return(2*XRangeMax()); };
00075   virtual double YScanRangeMax(){ return(2*YRangeMax()); };
00076 
00077   virtual double XResolution(){ return(xd*Vx); };
00078   virtual double YResolution(){ return(yd*Vy); };
00079   virtual double ZResolution(const gchar *Z_Unit_Alias=NULL){ 
00080           if (Z_Unit_Alias){
00081 // Reference Base Units are AA for all Zscales, nA for Current, nN for Force, ...
00082                   if (strncmp (Z_Unit_Alias, "AA", 2) == 0) return zd*Vz;
00083                   if (strncmp (Z_Unit_Alias, "nm", 2) == 0) return zd*Vz;
00084                   if (strncmp (Z_Unit_Alias, "um", 2) == 0) return zd*Vz;
00085                   if (strncmp (Z_Unit_Alias, "mm", 2) == 0) return zd*Vz;
00086                   if (strncmp (Z_Unit_Alias, "nA", 2) == 0) return (AnalogVMaxIn/DigRangeIn)/nAmpere2Volt;
00087                   if (strncmp (Z_Unit_Alias, "pA", 2) == 0) return (AnalogVMaxIn/DigRangeIn)/nAmpere2Volt;
00088                   if (strncmp (Z_Unit_Alias, "nN", 2) == 0) return (AnalogVMaxIn/DigRangeIn)/nNewton2Volt;
00089                   if (strncmp (Z_Unit_Alias, "Hz", 2) == 0) return (AnalogVMaxIn/DigRangeIn)/dHertz2Volt;
00090 //                if (strncmp (Z_Unit_Alias, "Cps", 3) == 0) return (AnalogVMaxIn/DigRangeIn)/CountsPerSec2Volt;
00091 //                if (strncmp (Z_Unit_Alias, "K", 1) == 0) return (AnalogVMaxIn/DigRangeIn)/Kelvin2Volt;
00092                   if (strncmp (Z_Unit_Alias, "V" ,1) == 0) return AnalogVMaxIn/DigRangeIn;
00093                   if (strncmp (Z_Unit_Alias, "1" ,1) == 0) return 1.;
00094                   return 1.;
00095           }
00096           return zd*Vz; 
00097   };
00098   virtual double X0Resolution(){ return(xd*Vx0); };
00099   virtual double Y0Resolution(){ return(yd*Vy0); };
00100   virtual double Z0Resolution(const gchar *Z_Unit_Alias=NULL){ 
00101           return zd*Vz0; 
00102   };
00103 
00104   virtual double Dig2nAmpere(long I){return ((double)I*AnalogVMaxIn/(DigRangeIn*nAmpere2Volt));};
00105   virtual double Dig2V(long U){return(AnalogVMaxIn/(double)DigRangeIn*(double)U);};
00106 
00107   /* DigVal <-> Angstroem -Konversions */
00108   virtual double Dig2XA(long dig){ return(XResolution()*(double)dig); };
00109   virtual double Dig2YA(long dig){ return(YResolution()*(double)dig); };
00110   virtual double Dig2ZA(long dig){ return(ZResolution()*(double)dig); };
00111 
00112   virtual double XA2Dig(double ang){ return(ang/XResolution()); };
00113   virtual double YA2Dig(double ang){ return(ang/YResolution()); };
00114   virtual double ZA2Dig(double ang){ return(ang/ZResolution()); };
00115 
00116   virtual double Dig2X0A(long dig){ return(X0Resolution()*(double)dig); };
00117   virtual double Dig2Y0A(long dig){ return(Y0Resolution()*(double)dig); };
00118   virtual double Dig2Z0A(long dig){ return(Z0Resolution()*(double)dig); };
00119 
00120   virtual double X0A2Dig(double ang){ return(ang/X0Resolution()); };
00121   virtual double Y0A2Dig(double ang){ return(ang/Y0Resolution()); };
00122   virtual double Z0A2Dig(double ang){ return(ang/Z0Resolution()); };
00123 
00124   /* Get/Change Verstärkung */
00125   virtual double VX(int i=-1){ return(i>=0 ? Vx = VList[i] : Vx); };  
00126   virtual double VY(int i=-1){ return(i>=0 ? Vy = VList[i] : Vy); };  
00127   virtual double VZ(int i=-1){ return(i>=0 ? Vz = VList[i] : Vz); };  
00128 
00129   virtual double VX0(int i=-1){ return(i>=0 ? Vx0 = VList[i] : Vx0); };  
00130   virtual double VY0(int i=-1){ return(i>=0 ? Vy0 = VList[i] : Vy0); };  
00131   virtual double VZ0(int i=-1){ return(i>=0 ? Vz0 = VList[i] : Vz0); };  
00132 
00133   virtual OFFSET_MODE OffsetMode (OFFSET_MODE ofm=OFM_UNDEFINED);
00134 
00135   virtual double VoltOut2Dig(double U){ return U*DigRangeOut/AnalogVMaxOut; };
00136   virtual double Dig2VoltOut(double dig){ return dig/DigRangeOut*AnalogVMaxOut; };
00137 
00138   virtual double VoltIn2Dig(double U){ return U*DigRangeIn/AnalogVMaxIn; };
00139   virtual double Dig2VoltIn(double dig){ return dig/DigRangeIn*AnalogVMaxIn; };
00140 
00141   virtual double BiasV2Vabs(double U){ return UOutLimit(U/BiasGain); }; // correct Bias gain
00142   virtual double BiasV2V(double U){ return U/BiasGain; }; // correct Bias gain
00143   virtual double nAmpere2V(double I){ return UInLimit(I*nAmpere2Volt); };
00144   virtual double nNewton2V(double F){ return UInLimit(F*nNewton2Volt); };
00145   virtual double dHertz2V(double v){ return UInLimit(v*dHertz2Volt); };
00146   virtual double eV2V(double eV){ return UOutLimit(eV/eV2Volt); };
00147   virtual double V2BiasV(double U){return U*BiasGain; }; // used to determin the correct voltages for STS ramps
00148 
00149   gchar *type;
00150   gchar *name;
00151   gchar *xunitname;
00152   gchar *yunitname;
00153   gchar *zunitname;
00154 
00155 protected:
00156   /* STM/AFM Gerätedaten */
00157   long   DigRangeOut;     /* Digital DA Range [integer] */
00158   double AnalogVMaxOut; /* Analog DA Range [V] */
00159   long   DigRangeIn;     /* Digital DA Range [integer] */
00160   double AnalogVMaxIn; /* Analog DA Range [V] */
00161   double VList[GAIN_POSITIONS];   /* Liste möglicher Verstärkungsfaktoren */
00162   double Vx, Vy, Vz; /* Eingestellte Verstärkung "Scan" am Piezodriver [1,2,5,10,15] */
00163   double Vx0, Vy0, Vz0; /* Eingestellte Verstärkung "Offset" am Piezodriver [1,2,5,10,15] */
00164   double xPsens, yPsens, zPsens; /* Tube Sensitivitys [A/V] */
00165   double BiasGain;     /* Gain for optional Bias adjust */
00166   double nAmpere2Volt; /* nA (Tunnelcurrent) to Volt Factor */
00167   double nNewton2Volt; /* nN (Lever-Kraft) to Volt Factor */
00168   double dHertz2Volt;  /* dHz (Frq. Verstimmung) to Volt Factor */
00169   double eV2Volt;      /* eV to Volt Factor */
00170 
00171   /* Grenzdaten "Scan" für V=1 */
00172   double xR, yR, zR; /* Max Range für V=1 */
00173   double xd, yd, zd; /* Resolution (min dx,y,z) für V=1 */
00174 
00175 private:
00176   OFFSET_MODE offset_mode;
00177 };
00178 
00179 class STM_Instrument : public XSM_Instrument{
00180  public:
00181   STM_Instrument(XSMRESOURCES &xsmres) : XSM_Instrument(xsmres){ 
00182     type = g_strdup("STM"); 
00183     zunitname = yunitname = xunitname = g_strdup("Ang");
00184   };
00185   virtual ~STM_Instrument(){ 
00186     g_free(type); 
00187     g_free(xunitname);
00188   };
00189 
00190   /* DigVal <-> Angstroem -Konversions */
00191   /*  unchanged */
00192 };
00193 
00194 class AFM_Instrument : public XSM_Instrument{
00195  public:
00196   AFM_Instrument(XSMRESOURCES &xsmres) : XSM_Instrument(xsmres){ 
00197     type = g_strdup("AFM"); 
00198     zunitname = yunitname = xunitname = g_strdup("Ang");
00199   };
00200   virtual ~AFM_Instrument(){ 
00201     g_free(type); 
00202     g_free(xunitname);
00203   };
00204 
00205   /* DigVal <-> Angstroem -Konversions */
00206   /*  unchanged */
00207 };
00208 class SPALEED_Instrument : public XSM_Instrument{
00209  public:
00210   SPALEED_Instrument(XSMRESOURCES &xsmres, double *E, double *Gt, long *M);
00211   virtual ~SPALEED_Instrument(){ 
00212     g_free(type); 
00213     g_free(xunitname);
00214     g_free(yunitname);
00215     g_free(zunitname);
00216   };
00217 
00218   // to override Amplifier settings, always == 1
00219   virtual double XRangeMax(){ return(Transform2Usr(xR)); };
00220   virtual double YRangeMax(){ return(Transform2Usr(yR)); };
00221   virtual double ZRangeMax(){ return(zR); };
00222 
00223   virtual double XResolution(){ return(xd); };
00224   virtual double YResolution(){ return(yd); };
00225   virtual double ZResolution(){ return(1. / (*Gate)); };
00226 
00227   /* DigVal <-> K-space -Konversions */
00228   virtual double Dig2XA(long dig){ return(Transform2Usr(XResolution()*(double)dig)); };
00229   virtual double Dig2YA(long dig){ return(Transform2Usr(YResolution()*(double)dig)); };
00230   virtual double Dig2ZA(long dig){ return(ZResolution()*(double)dig); };
00231 
00232   virtual double XA2Dig(double ang){ return(Transform2V(ang)/XResolution()); };
00233   virtual double YA2Dig(double ang){ return(Transform2V(ang)/YResolution()); };
00234   virtual double ZA2Dig(double ang){ return(ang/ZResolution()); };
00235 
00236  private:
00237   double Transform2V(double x){ 
00238     return x;
00239   };
00240   
00241   double Transform2Usr(double x){ 
00242     return x;
00243   };
00244   
00245   long   *Mode;
00246   double *En;
00247   double *Gate;
00248   SUnit  *Su;
00249   BZUnit *BZu;
00250 };
00251 #endif

Generated on Sat Apr 1 09:03:59 2006 for GXSM by  doxygen 1.4.6