Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interferometer delay for phase shift alignment (XC Correlator) #249

Merged
merged 38 commits into from Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
60a25f6
Update CMakeLists.txt
Nov 18, 2020
ebdef73
fixed conflict in CMakeLists.txt
Nov 19, 2020
feba279
Merge remote-tracking branch 'upstream/master'
Nov 20, 2020
bb0bb9d
Updated libahp_xc.so and indi_ahp_correlator.cpp
Nov 20, 2020
4799a06
Still connection issues, but functional AHP XC correlators
Nov 20, 2020
0172570
Updated class name
Nov 20, 2020
74bc44a
Fixed crashes on exit
Nov 20, 2020
1cb8797
Added BLOBs for live auto/cross correlators
Nov 21, 2020
26dc0b2
added autocorrelation and crosscorrelation blobs
Nov 22, 2020
9703942
Fixed conflict vs. master
Nov 22, 2020
40c3994
Merging upstream
Nov 22, 2020
d823750
Added autocorrelation and crosscorrelation BLOBs
Nov 22, 2020
9ac6370
Updated libahp_xc
Nov 22, 2020
499f0a9
Fixed exposure time issue
Nov 22, 2020
6574565
Updated libahp_xc
Nov 22, 2020
8282a7a
Merge remote-tracking branch 'refs/remotes/upstream/master' into inte…
Nov 23, 2020
42c59b1
Merge remote-tracking branch 'refs/remotes/upstream/master' into inte…
Nov 26, 2020
04f35c4
Fixing runtime errors in indi_ahp_correlator.cpp
Nov 26, 2020
842e6f6
Fixed issues in delay calculation
Nov 26, 2020
f5d710e
new delay calculation algorithm
Nov 27, 2020
8071feb
Merge remote-tracking branch 'refs/remotes/upstream/master' into inte…
Nov 27, 2020
e8f695e
Trying to fix baseline ordering
Nov 27, 2020
4549f68
changed type to correlation in cross-correlation count
Nov 27, 2020
4f23455
updated libahp_xc
Nov 28, 2020
05fd547
indi_ahp_correlator.cpp updated for libahp_xc conformation
Nov 28, 2020
330ec14
updated libahp_xc
Nov 28, 2020
0ae7ab7
updated libahp_xc
Nov 28, 2020
e723068
Fixing delays
Nov 28, 2020
011b411
updated delay algorithm
Nov 28, 2020
8810505
correlation counts in stats
Nov 28, 2020
45d5783
Closer line was farest
Nov 28, 2020
dfd0e67
Added plots BLOBs
Nov 28, 2020
c6bbc7b
merge indi_ahp_correlator.cpp
Nov 28, 2020
007f85f
merge indi_ahp_correlator.cpp
Nov 28, 2020
8d643a7
Additional and plot BLOBs
Nov 28, 2020
3efbfb7
Fixing exposure
Nov 28, 2020
06e5e63
updated libahp_xc.so
Nov 29, 2020
9a0bd65
updated libahp_xc
Nov 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
143 changes: 86 additions & 57 deletions indi-ahp-correlator/indi_ahp_correlator.cpp
Expand Up @@ -35,6 +35,7 @@
#include <connectionplugins/connectionserial.h>
#include "indi_ahp_correlator.h"

static int nplots = 1;
static std::unique_ptr<AHP_XC> array(new AHP_XC());

void ISGetProperties(const char *dev)
Expand Down Expand Up @@ -250,43 +251,38 @@ void AHP_XC::Callback()
if(ahp_xc_get_packet(autocorrelations, crosscorrelations))
continue;

int w = PrimaryCCD.getXRes();
int h = PrimaryCCD.getYRes();
int idx = 0;
double minalt = 90.0;
double minalt = 0.0;
int farest = 0;

if(InExposure) {
timeleft = CalcTimeLeft(ExpStart, ExposureRequest);
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
for(int y = x+1; y < ahp_xc_get_nlines(); y++) {
if(lineEnableSP[x].sp[0].s == ISS_ON && lineEnableSP[y].sp[0].s == ISS_ON) {
int _idx = idx*(ahp_xc_get_crosscorrelator_jittersize()*2-1)+ahp_xc_get_crosscorrelator_jittersize();
INDI::Correlator::UVCoordinate uv = baselines[idx]->getUVCoordinates();
int xx = static_cast<int>(w*uv.u/2.0);
int yy = static_cast<int>(h*uv.v/2.0);
int z = w*h/2+w/2+xx+yy*w;
if(xx >= -w/2 && xx < w/2 && yy >= -w/2 && yy < h/2) {
framebuffer[z] += (double)crosscorrelations[_idx].coherence;
framebuffer[w*h-1-z] += (double)crosscorrelations[_idx].coherence;
}
}
idx++;
}
}
if(timeleft <= 0.0f) {
// We're no longer exposing...
AbortExposure();
// We're done exposing
LOG_INFO("Exposure done, downloading image...");
dsp_buffer_stretch(framebuffer, w*h, 0.0, 65535.0);
dsp_buffer_copy(framebuffer, static_cast<unsigned short*>(static_cast<void*>(PrimaryCCD.getFrameBuffer())), w*h);
memset(framebuffer, 0, w*h*sizeof(double));
// Let INDI::CCD know we're done filling the image buffer
ExposureComplete(&PrimaryCCD);
LOG_INFO("Integration complete, downloading plots...");
// Additional BLOBs
char **blobs = static_cast<char**>(malloc(sizeof(char*)*plotBP.nbp+1));
for(int x = 0; x < nplots; x++) {
size_t memsize = plot_str[x]->len*sizeof(double);
blobs[x] = static_cast<char*>(malloc(memsize));
void* fits = dsp_file_write_fits(-64, &memsize, plot_str[x]);
if(fits != nullptr) {
blobs[x] = (char*)realloc(blobs[x], memsize);
memcpy(blobs[x], fits, memsize);
free(fits);
}
plotB[x].blob = blobs[x];
plotB[x].bloblen = memsize;
}
LOG_INFO("Plots BLOBs generated, downloading...");
sendFile(plotB, plotBP, nplots);
for(int x = 0; x < nplots; x++) {
free(blobs[x]);
dsp_buffer_set(plot_str[x]->buf, plot_str[x]->len, 0);
}
LOG_INFO("Generating additional BLOBs...");
char **blobs = static_cast<char**>(malloc(sizeof(char*)*ahp_xc_get_nbaselines()+1));
if(ahp_xc_get_nlines() > 0 && ahp_xc_get_autocorrelator_jittersize() > 1) {
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
size_t memsize = autocorrelations_str[x]->len*sizeof(double);
Expand All @@ -299,12 +295,11 @@ void AHP_XC::Callback()
}
autocorrelationsB[x].blob = blobs[x];
autocorrelationsB[x].bloblen = memsize;
strcpy(autocorrelationsB[x].format, "fits");
autocorrelations_str[x]->sizes[1] = 1;
autocorrelations_str[x]->len = autocorrelations_str[x]->sizes[0];
dsp_stream_alloc_buffer(autocorrelations_str[x], autocorrelations_str[x]->len);
}
LOG_INFO("Autocorrelations BLOB generated, downloading...");
LOG_INFO("Autocorrelations BLOBs generated, downloading...");
sendFile(autocorrelationsB, autocorrelationsBP, ahp_xc_get_nlines());
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
free(blobs[x]);
Expand All @@ -324,14 +319,13 @@ void AHP_XC::Callback()
}
autocorrelationsB[x].blob = blobs[x];
autocorrelationsB[x].bloblen = memsize;
strcpy(autocorrelationsB[x].format, "fits");
crosscorrelations_str[idx]->sizes[1] = 1;
crosscorrelations_str[idx]->len = crosscorrelations_str[idx]->sizes[0];
dsp_stream_alloc_buffer(crosscorrelations_str[idx], crosscorrelations_str[idx]->len);
idx++;
}
}
LOG_INFO("Crosscorrelations BLOB generated, downloading...");
LOG_INFO("Crosscorrelations BLOBs generated, downloading...");
sendFile(crosscorrelationsB, crosscorrelationsBP, ahp_xc_get_nbaselines());
for(int x = 0; x < ahp_xc_get_nbaselines(); x++) {
free(blobs[x]);
Expand All @@ -340,7 +334,27 @@ void AHP_XC::Callback()
free(blobs);
LOG_INFO("Download complete.");
} else {
// Additional BLOBs
// Filling BLOBs
if(nplots > 0) {
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
for(int y = x+1; y < ahp_xc_get_nlines(); y++) {
if(lineEnableSP[x].sp[0].s == ISS_ON && lineEnableSP[y].sp[0].s == ISS_ON) {
int w = plot_str[0]->sizes[0];
int h = plot_str[0]->sizes[1];
int _idx = idx*(ahp_xc_get_crosscorrelator_jittersize()*2-1)+ahp_xc_get_crosscorrelator_jittersize();
INDI::Correlator::UVCoordinate uv = baselines[idx]->getUVCoordinates();
int xx = static_cast<int>(w*uv.u/2.0);
int yy = static_cast<int>(h*uv.v/2.0);
int z = w*h/2+w/2+xx+yy*w;
if(xx >= -w/2 && xx < w/2 && yy >= -w/2 && yy < h/2) {
plot_str[0]->buf[z] += (double)crosscorrelations[_idx].coherence;
plot_str[0]->buf[w*h-1-z] += (double)crosscorrelations[_idx].coherence;
}
}
idx++;
}
}
}
if(ahp_xc_get_nlines() > 0 && ahp_xc_get_autocorrelator_jittersize() > 1) {
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
int pos = autocorrelations_str[x]->len-autocorrelations_str[x]->sizes[0];
Expand All @@ -363,8 +377,6 @@ void AHP_XC::Callback()
}
}
}
} else {
memset(framebuffer, 0, PrimaryCCD.getXRes()*PrimaryCCD.getYRes()*sizeof(double));
}

idx = 0;
Expand Down Expand Up @@ -395,8 +407,8 @@ void AHP_XC::Callback()
obs.lng = lineGPSNP[x].np[1].value;
ln_get_hrz_from_equ(&equ, &obs, julian, &hrz);

farest = (minalt < alt[x] ? farest : x);
minalt = (minalt < alt[x] ? minalt : alt[x]);
farest = (minalt > alt[x] ? farest : x);
minalt = (minalt > alt[x] ? minalt : alt[x]);
alt[x] = hrz.alt*M_PI/180.0;
az[x] = hrz.az*M_PI/180.0;
}
Expand Down Expand Up @@ -438,7 +450,6 @@ void AHP_XC::Callback()
}
}
EnableCapture(false);
free (framebuffer);
}

AHP_XC::AHP_XC()
Expand All @@ -450,6 +461,7 @@ AHP_XC::AHP_XC()

autocorrelationsB = static_cast<IBLOB*>(malloc(1));
crosscorrelationsB = static_cast<IBLOB*>(malloc(1));
plotB = static_cast<IBLOB*>(malloc(1));

lineStatsN = static_cast<INumber*>(malloc(1));
lineStatsNP = static_cast<INumberVectorProperty*>(malloc(1));
Expand Down Expand Up @@ -491,6 +503,7 @@ AHP_XC::AHP_XC()

autocorrelations_str = static_cast<dsp_stream_p*>(malloc(1));
crosscorrelations_str = static_cast<dsp_stream_p*>(malloc(1));
plot_str = static_cast<dsp_stream_p*>(malloc(1));

framebuffer = static_cast<double*>(malloc(1));
totalcounts = static_cast<double*>(malloc(1));
Expand All @@ -504,6 +517,10 @@ AHP_XC::AHP_XC()

bool AHP_XC::Disconnect()
{
for(int x = 0; x < nplots; x++) {
dsp_stream_free_buffer(plot_str[x]);
dsp_stream_free(plot_str[x]);
}
for(int x = 0; x < ahp_xc_get_nlines(); x++) {
if(ahp_xc_get_autocorrelator_jittersize() > 1) {
dsp_stream_free_buffer(autocorrelations_str[x]);
Expand Down Expand Up @@ -562,7 +579,7 @@ bool AHP_XC::initProperties()
// Must init parent properties first!
INDI::CCD::initProperties();

SetCCDCapability(CCD_CAN_ABORT|CCD_CAN_SUBFRAME|CCD_HAS_DSP);
SetCCDCapability(CCD_CAN_ABORT|CCD_HAS_DSP);

IUFillNumber(&settingsN[0], "INTERFEROMETER_WAVELENGTH_VALUE", "Filter wavelength (m)", "%g", 3.0E-12, 3.0E+3, 1.0E-9, 0.211121449);
IUFillNumber(&settingsN[1], "INTERFEROMETER_BANDWIDTH_VALUE", "Filter bandwidth (m)", "%g", 3.0E-12, 3.0E+3, 1.0E-9, 1199.169832);
Expand Down Expand Up @@ -659,17 +676,17 @@ bool AHP_XC::updateProperties()
***************************************************************************************/
void AHP_XC::setupParams()
{
float pixelsize = (float)AIRY * (float)LIGHTSPEED / (float)ahp_xc_get_frequency();
float pixelsize = (float)AIRY * (float)LIGHTSPEED / ahp_xc_get_frequency();
int size = (float)ahp_xc_get_delaysize()*2.0f*pixelsize;
SetCCDParams(size, size, 16, pixelsize, pixelsize);
framebuffer = static_cast<double*>(realloc(framebuffer, static_cast<unsigned long>(size*size)*sizeof(double)+1));

// Let's calculate how much memory we need for the primary CCD buffer
int nbuf;
nbuf = PrimaryCCD.getXRes() * PrimaryCCD.getYRes() * PrimaryCCD.getBPP() / 8;
nbuf += 512; // leave a little extra at the end
PrimaryCCD.setFrameBufferSize(static_cast<unsigned int>(nbuf));
memset(PrimaryCCD.getFrameBuffer(), 0, static_cast<unsigned int>(PrimaryCCD.getFrameBufferSize()));
pixelsize *= 1000000.0f;
SetCCDParams(size, size, 64, pixelsize, pixelsize);

if(nplots > 0) {
plot_str[0]->sizes[0] = size;
plot_str[0]->sizes[1] = size;
plot_str[0]->len = size*size;
dsp_stream_alloc_buffer(plot_str[0], plot_str[0]->len);
}
}

/**************************************************************************************
Expand Down Expand Up @@ -719,8 +736,6 @@ bool AHP_XC::ISNewNumber(const char *dev, const char *name, double values[], cha
return true;
}

framebuffer = static_cast<double*>(realloc(framebuffer, static_cast<unsigned long>(PrimaryCCD.getXRes()*PrimaryCCD.getYRes())*sizeof(double)+1));

return true;
}

Expand Down Expand Up @@ -915,17 +930,17 @@ void AHP_XC::addFITSKeywords(fitsfile *fptr, INDI::CCDChip *targetChip)

float AHP_XC::CalcTimeLeft(timeval start, float req)
{
double timesince;
double timeleft;
float timesince;
float timeleft;
struct timeval now
{
0, 0
};
gettimeofday(&now, nullptr);

timesince =
(double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) - (double)(start.tv_sec * 1000.0 + start.tv_usec / 1000);
timesince = timesince / 1000;
(float)(now.tv_sec * 1000.0f + now.tv_usec / 1000.0f) - (float)(start.tv_sec * 1000.0f + start.tv_usec / 1000.0f);
timesince = timesince / 1000.0f;
timeleft = req - timesince;
return timeleft;
}
Expand Down Expand Up @@ -965,7 +980,7 @@ void AHP_XC::TimerHit()

if(InExposure) {
// Just update time left in client
PrimaryCCD.setExposureLeft(timeleft);
PrimaryCCD.setExposureLeft((double)timeleft);
}

SetTimer(POLLMS);
Expand Down Expand Up @@ -1022,11 +1037,15 @@ bool AHP_XC::Connect()
autocorrelationsB = static_cast<IBLOB*>(realloc(autocorrelationsB, static_cast<unsigned long>(ahp_xc_get_nlines())*sizeof(IBLOB)+1));
if(ahp_xc_get_crosscorrelator_jittersize() > 1)
crosscorrelationsB = static_cast<IBLOB*>(realloc(crosscorrelationsB, static_cast<unsigned long>(ahp_xc_get_nbaselines())*sizeof(IBLOB)+1));
if(nplots > 0)
plotB = static_cast<IBLOB*>(realloc(plotB, static_cast<unsigned long>(nplots)*sizeof(IBLOB)+1));

if(ahp_xc_get_autocorrelator_jittersize() > 1)
autocorrelations_str = static_cast<dsp_stream_p*>(realloc(autocorrelations_str, static_cast<unsigned long>(ahp_xc_get_nlines())*sizeof(dsp_stream_p)+1));
if(ahp_xc_get_crosscorrelator_jittersize() > 1)
crosscorrelations_str = static_cast<dsp_stream_p*>(realloc(crosscorrelations_str, static_cast<unsigned long>(ahp_xc_get_nbaselines())*sizeof(dsp_stream_p)+1));
if(nplots > 0)
plot_str = static_cast<dsp_stream_p*>(realloc(plot_str, static_cast<unsigned long>(nplots)*sizeof(dsp_stream_p)+1));

totalcounts = static_cast<double*>(realloc(totalcounts, static_cast<unsigned long>(ahp_xc_get_nlines())*sizeof(double)+1));
totalcorrelations = static_cast<correlation*>(realloc(totalcorrelations, static_cast<unsigned long>(ahp_xc_get_nbaselines())*sizeof(correlation)+1));
Expand Down Expand Up @@ -1054,6 +1073,18 @@ bool AHP_XC::Connect()
char tab[MAXINDINAME];
char name[MAXINDINAME];
char label[MAXINDINAME];

for(int x = 0; x < nplots; x++) {
plot_str[x] = dsp_stream_new();
dsp_stream_add_dim(plot_str[x], 1);
dsp_stream_add_dim(plot_str[x], 1);
dsp_stream_alloc_buffer(plot_str[x], plot_str[x]->len);
sprintf(name, "PLOT%02d", x+1);
sprintf(label, "Plot %d", x+1);
IUFillBLOB(&plotB[x], name, label, ".fits");
}
IUFillBLOBVector(&plotBP, plotB, nplots, getDeviceName(), "PLOTS", "Plots", "Stats", IP_RO, 60, IPS_BUSY);

for (int x = 0; x < ahp_xc_get_nlines(); x++) {
if(ahp_xc_get_autocorrelator_jittersize() > 1) {
autocorrelations_str[x] = dsp_stream_new();
Expand Down Expand Up @@ -1139,7 +1170,7 @@ bool AHP_XC::Connect()
IUFillBLOB(&crosscorrelationsB[idx], name, label, ".fits");
}
sprintf(name, "CORRELATIONS_%0d_%0d", x+1, y+1);
sprintf(label, "Correlations (%d*%d)", x+1, y+1, x+1, y+1);
sprintf(label, "Correlations (%d*%d)", x+1, y+1);
IUFillNumber(&correlationsN[idx++], name, label, "%1.4f", 0, 1.0, 1, 0);
}
}
Expand All @@ -1149,8 +1180,6 @@ bool AHP_XC::Connect()
IUFillBLOBVector(&crosscorrelationsBP, crosscorrelationsB, ahp_xc_get_nbaselines(), getDeviceName(), "CROSSCORRELATIONS", "Crosscorrelations", "Stats", IP_RO, 60, IPS_BUSY);
IUFillNumberVector(&correlationsNP, correlationsN, ahp_xc_get_nbaselines(), getDeviceName(), "CORRELATIONS", "Correlations", "Stats", IP_RO, 60, IPS_BUSY);

setupParams();

// Start the timer
SetTimer(POLLMS);

Expand Down
8 changes: 6 additions & 2 deletions indi-ahp-correlator/indi_ahp_correlator.h
Expand Up @@ -24,8 +24,6 @@
#include "indicorrelator.h"
#include <ahp/ahp_xc.h>

#define HEADER_SIZE 16

class baseline : public INDI::Correlator
{
public:
Expand Down Expand Up @@ -92,9 +90,11 @@ class AHP_XC : public INDI::CCD

free(autocorrelationsB);
free(crosscorrelationsB);
free(plotB);

free(autocorrelations_str);
free(crosscorrelations_str);
free(plot_str);

free(totalcounts);
free(totalcorrelations);
Expand Down Expand Up @@ -198,8 +198,12 @@ class AHP_XC : public INDI::CCD
IBLOB *crosscorrelationsB;
IBLOBVectorProperty crosscorrelationsBP;

IBLOB *plotB;
IBLOBVectorProperty plotBP;

dsp_stream_p *autocorrelations_str;
dsp_stream_p *crosscorrelations_str;
dsp_stream_p *plot_str;

INumber settingsN[2];
INumberVectorProperty settingsNP;
Expand Down
Binary file modified libahp_xc/libahp_xc.so.amd64
Binary file not shown.
Binary file modified libahp_xc/libahp_xc.so.arm64
Binary file not shown.
Binary file modified libahp_xc/libahp_xc.so.armhf
Binary file not shown.
Binary file modified libahp_xc/libahp_xc.so.i686
Binary file not shown.