home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <values.h>
- #include <math.h>
- #include <iostream.h>
- #include <iomanip.h>
- #include <fstream.h>
- #include <strstrea.h>
- #include <conio.h>
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
-
- #include "common.h"
- #include "video.hpp"
- #include "atimes.hpp"
- #include "pport.hpp"
- #include "handpad.hpp"
- #include "coord.hpp"
- #include "cmosclk.hpp"
- #include "steppers.hpp"
- #include "pec.hpp"
- #include "guide.hpp"
-
- Guide::Guide
- (
- const int GuideArcsecSec,
- const int FullstepsPerPECArray,
- const int InvertOutput,
- const int MaxDelay,
- const int MinDelay,
- const int HsDelayX,
- const int InterruptHs,
- const int HoldReps,
- const int MsRepsTick,
- const int MsDelayX,
- const int MsPause,
- const int Ms,
- int* PWM,
- const unsigned PPortAddr
- ):
- PEC
- (
- FullstepsPerPECArray,
- InvertOutput,
- MaxDelay,
- MinDelay,
- HsDelayX,
- InterruptHs,
- HoldReps,
- MsRepsTick,
- MsDelayX,
- MsPause,
- Ms,
- PWM,
- PPortAddr
- ),
- GuideArcsecSec(GuideArcsecSec)
- {
- InitGuide();
- }
-
- void Guide::InitGuide(void)
- {
- GuideFlag=Yes;
- GuideRadTick=GuideArcsecSec/RadToArcsec/ClockTicksSec;
- AccumGuide.Alt=AccumGuide.Az=0;
- GuideIxA=GuideIxZ=0;
- }
-
- void Guide::EndAndSaveGuide(void)
- {
- int Ix;
-
- GuideFlag=Off;
- AccumGuide.Alt=AccumGuide.Az=0;
- ofstream Output(GuideFile);
- for(Ix=0;Ix<GuideIxA;Ix++)
- Output<<(int)GuideA[Ix].PECIx<<" "<<GuideA[Ix].TenthsArcsec<<endl;
- Output<<endl;
- for(Ix=0;Ix<GuideIxZ;Ix++)
- Output<<(int)GuideZ[Ix].PECIx<<" "<<GuideZ[Ix].TenthsArcsec<<endl;
- }
-
- void Guide::ProcessGuide(void)
- {
- static int SoundA,SoundZ;
- static int HoldPECIxA,HoldPECIxZ;
-
- // only write to file if PEC index changes
- if(PECIxA!=HoldPECIxA)
- {
- if(!PECIxA)
- {
- sound(1000);
- SoundA=!SoundA;
- }
- else
- if(SoundA)
- {
- SoundA=!SoundA;
- nosound();
- }
- GuideA[GuideIxA].PECIx=PECIxA;
- GuideA[GuideIxA].TenthsArcsec=AccumGuide.Alt*RadToTenthsArcsec;
- HoldPECIxA=PECIxA;
- GuideIxA++;
- }
- if(PECIxZ!=HoldPECIxZ)
- {
- if(!PECIxZ)
- {
- sound(500);
- SoundZ=!SoundZ;
- }
- else
- if(SoundZ)
- {
- SoundZ=!SoundZ;
- nosound();
- }
- GuideZ[GuideIxZ].PECIx=PECIxZ;
- GuideZ[GuideIxZ].TenthsArcsec=AccumGuide.Az*RadToTenthsArcsec;
- HoldPECIxZ=PECIxZ;
- GuideIxZ++;
- }
- if(GuideIxA>=MaxGuideIx || GuideIxZ>=MaxGuideIx)
- EndAndSaveGuide();
- }
-
- void Guide::AddGuideToPEC(int ArrayIx, GuideArray Array[], int PEC[])
- {
- int IxA,IxB;
- int IxOffset;
- int K;
- int Drift;
- double Slide;
- double SlideDrift;
- int ZeroIx[1+MaxGuideIx/PECSize];
- int Ix;
- int ZeroCount;
-
- // store all Array.PECIx==0 in ZeroIx[] array;
- // ZeroIx[0] contains 1st occurance of PECIx=0, ZeroIx[1] next occurance...
- // ZeroCount is count of all zero PECIx's
- for(IxA=0,Ix=0;IxA<ArrayIx;IxA++)
- if(!Array[IxA].PECIx)
- ZeroIx[Ix++]=IxA;
- ZeroCount=Ix;
- if(ZeroCount>=2)
- {
- // copy repetitions of PEC into 1st PEC
- for(Ix=ZeroCount;Ix>2;Ix--)
- {
- IxOffset=PECSize*(Ix-2);
- for(IxA=ZeroIx[0];IxA<ZeroIx[1];IxA++)
- Array[IxA].TenthsArcsec+=Array[IxA+IxOffset].TenthsArcsec;
- }
- // start PEC with 1st TenthsArcsec value = 0
- K=Array[ZeroIx[0]].TenthsArcsec;
- for(IxA=ZeroIx[0];IxA<ZeroIx[1];IxA++)
- Array[IxA].TenthsArcsec-=K;
- // eliminate drift, ie, final TenthsArcsec should = 0
- Drift=Array[ZeroIx[1]-1].TenthsArcsec;
- for(IxA=ZeroIx[0],IxB=0;IxA<ZeroIx[1];IxA++,IxB++)
- {
- Slide=(double)IxB/PECSize;
- SlideDrift=Slide*Drift;
- Array[IxA].TenthsArcsec-=(int)SlideDrift;
- }
- // add to PEC
- for(IxA=ZeroIx[0];IxA<ZeroIx[1];IxA++)
- PEC[Array[IxA].PECIx]+=Array[IxA].TenthsArcsec;
- }
- }
-
- void Guide::Test(void)
- {
- char ValueA[ValueSize];
- char ValueB[ValueSize];
- int A,B;
- int AFlag=Yes;
-
- GuideIxA=0;
- ifstream File(GuideFile);
- if(File)
- {
- while(!File.eof() && GuideIxA<MaxGuideIx && AFlag)
- {
- File>>ValueA>>ValueB;
- GuideA[GuideIxA].PECIx=atoi(ValueA);
- GuideA[GuideIxA].TenthsArcsec=atoi(ValueB);
- if(GuideIxA)
- {
- // check for end of altitude portion of GuideFile
- A=GuideA[GuideIxA].PECIx;
- B=GuideA[GuideIxA-1].PECIx;
- if(A==(B-1) || A==(B+1) || (A==0)&&(B==(PECSize-1))
- || (B==0)&&(A==(PECSize-1)))
- ;
- else
- AFlag=No;
- }
- GuideIxA++;
- }
- AddGuideToPEC(GuideIxA,GuideA,PECA);
- EndAndSaveGuide();
- SavePEC();
- }
-
- else
- cout<<GuideFile<<" not found"<<endl;
- }
-
-