~vbursian/research-assistant/intervers

« back to all changes in this revision

Viewing changes to RAPlugins/DemoDevices/DummyTunableCCDDriver.cpp

  • Committer: Viktor Bursian at blin-ubuntu
  • Date: 2017-04-07 20:48:57 UTC
  • mfrom: (8.6.2 DN)
  • mto: (8.9.1 DIST)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: vbursian@gmail.com-20170407204857-787xdycffm8enff0
CCD devices is rewritten + some other changes in DN devices

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file DummyTunableCCDDriver.cpp Имитатор драйвера ПЗС-линейки с перестройкой длины волны.
 
3
- Part of DemoDevices - Research Assistant Plugin package.
 
4
- Uses  RAGUI - Research Assistant Graphical User Interface Library.
 
5
- Uses  Qt v.5.0.2  - http://qt-project.org/
 
6
- Uses  RANet - Research Assistant Net Library.
 
7
- Copyright(C) 2017, Dmitrii Nelson, St.Petersburg, Russia.
 
8
                          d.nelson@mail.ioffe.ru
 
9
*///////////////////////////////////////////////////////////////////////////////
 
10
#include "DummyTunableCCDDriver.h"
 
11
#include "attr.h"
 
12
#include <QDebug>
 
13
#include "Log.h"
 
14
#include <cstdlib>
 
15
 
 
16
namespace RA {
 
17
//------------------------------------------------------------------------------
 
18
 
 
19
DEFINE_CLASS_TAG(sDummyTunableCCDDriver)
 
20
 
 
21
//-------------------------------------------- sDummyTunableCCDDriver ----------
 
22
 
 
23
void  sDummyTunableCCDDriver::Preconfigure (sNodePtr  DeviceCfg)
 
24
{
 
25
  sPtr<sFolderNode>              DeviceSettings;
 
26
  DeviceCfg |= "Settings";
 
27
  DeviceSettings = DeviceCfg >> "Settings";
 
28
  if( DeviceSettings.IsCorrect() ){
 
29
    DeviceSettings |= attr("NumberOfPixels",3648);
 
30
    DeviceSettings |= attr("MiddlePixel",1733);
 
31
    DeviceSettings |= attr("WL_0",sPhysValue(0.02389,"nm"));
 
32
    DeviceSettings |= attr("WL_k",sPhysValue(-7.8e-6,_Unitsless_));
 
33
  };
 
34
  sTunableCCDDriver::Preconfigure(DeviceCfg);
 
35
}
 
36
 
 
37
sDummyTunableCCDDriver::~sDummyTunableCCDDriver ()
 
38
{
 
39
}
 
40
 
 
41
sDummyTunableCCDDriver::sDummyTunableCCDDriver (sString   DevicetId
 
42
                               ,sNodePtr  DeviceCfg)
 
43
  :sTunableCCDDriver(DevicetId,DeviceCfg)
 
44
  ,Amplitude(50000)
 
45
  ,WL_0(sPhysValue(1.0,"nm"))
 
46
  ,WL_k(sPhysValue(1,_Unitsless_))
 
47
{
 
48
}
 
49
 
 
50
void  sDummyTunableCCDDriver::PostConstructor ()
 
51
{
 
52
  sTunableCCDDriver::PostConstructor();
 
53
  try{ //get config parameters
 
54
    get_from<sPhysValueNode>(DeviceSettings >> "WL_0" ,WL_0);
 
55
    get_from<sPhysValueNode>(DeviceSettings >> "WL_k" ,WL_k);
 
56
  }catch(...){
 
57
    SetInvalid(tr("Something wrong in configuration."));
 
58
  }
 
59
}
 
60
 
 
61
void  sDummyTunableCCDDriver::ConnectUSBDevice ()
 
62
{
 
63
  emit Connected();
 
64
}
 
65
 
 
66
void  sDummyTunableCCDDriver::GetCCD_Data ()
 
67
{
 
68
    ushort NoiseDivider = RAND_MAX/320;
 
69
    Amplitude = Amplitude - 1000;
 
70
    if (Amplitude < 2000) Amplitude = 50000;
 
71
    ushort Width = 1000;
 
72
    for(int i = 0;i < NumOfPixels; i ++) {
 
73
        DataArray.ArrBody[i] = Amplitude/(1+(i-NumOfPixels/2)*(i-NumOfPixels/2)/Width)
 
74
                              +std::rand()/NoiseDivider;
 
75
    }
 
76
    emit NewData(DataArray);
 
77
}
 
78
 
 
79
void  sDummyTunableCCDDriver::CalculateWavelengths ()
 
80
{
 
81
  sPhysValue dWL = WL_0 + WL_k * WLPosition;
 
82
  sPhysValue LeftPos = WLPosition - dWL*MiddlePixel;
 
83
  sPhysValue RightPos = WLPosition + dWL*((NumOfPixels -1) - MiddlePixel);
 
84
  real dX_0 = ((WL_0 + WL_k * LeftPos)/(sPhysValue(1.0,"nm"))).ToReal();
 
85
  real dX_1 = ((WL_0 + WL_k * RightPos)/(sPhysValue(1.0,"nm"))).ToReal();
 
86
  real dX = (dWL/(sPhysValue(1.0,"nm"))).ToReal(); // in "nm/pixel"
 
87
  real d2X = (dX_1 - dX_0)/NumOfPixels;
 
88
  real  XM = (WLPosition/(sPhysValue(1.0,"nm"))).ToReal(); // in "nm"
 
89
  for (int i = 0; i < NumOfPixels; i++) {
 
90
    Wavelengths.ArrBody[i] = XM + (dX + d2X *(i - MiddlePixel))*(i - MiddlePixel);
 
91
  }
 
92
  emit NewWavelengths (Wavelengths);
 
93
}
 
94
 
 
95
void  sDummyTunableCCDDriver::StartCCD ()
 
96
{
 
97
  int _IT = Parameters.IntegrationTime / 1000;
 
98
  if (_IT < 1) _IT = 1;
 
99
  State_O_Measuring->SetTimeout(_IT);
 
100
}
 
101
 
 
102
void  sDummyTunableCCDDriver::StopCCD ()
 
103
{
 
104
  WLDriver.ReleaseExclusiveControl();
 
105
}
 
106
 
 
107
void  sDummyTunableCCDDriver::SetCCD_Parameters (sCCDDriver::sParameters Params)
 
108
{
 
109
  if( ! WLDriver.TakeExclusiveControl() ){
 
110
    emit IsBusy();
 
111
  }else{
 
112
    Parameters =  Params;
 
113
    emit ParamsSet();
 
114
  }
 
115
}
 
116
 
 
117
//------------------------------------------------------------------------------
 
118
} //namespace RA