//---------------------------------------------------------------------------
#include <math.h>
#include <vcl.h>
#pragma hdrstop
#include "angle.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int iHighBit_X,iLowBit_X;
float m_fFBPos_X=0.0,m_fFBPos_Y=0.0;
float maxerr1=0.0,maxerr2=0.0,maxerr3=0.0,maxerr4=0.0;
float e[8] = {0.0};
int HexError[8] = {0};
int TestPos[8] = {0};
float TestValue;
float cos1,sin1,cos2,sin2;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
COS->Clear();
SIN->Clear();
Chart1->LeftAxis->Axis->Width = 1;
Chart1->BottomAxis->Axis->Width = 1;
Chart1->BottomAxis->RoundFirstLabel = false;
Chart1->Axes->FastCalc = true;
Chart1->BufferedDisplay = true;
Chart1->Canvas->ReferenceCanvas->Pen->OwnerCriticalSection = NULL;
Chart1->RightAxis->SetMinMax(0, 360);
COS->XValues->Order = loNone;
COS->LinePen->OwnerCriticalSection = NULL;
SIN->XValues->Order = loNone;
SIN->LinePen->OwnerCriticalSection = NULL;
TestPos[0] = StrToInt(Edit1->Text);
TestPos[1] = StrToInt(Edit2->Text);
TestPos[2] = StrToInt(Edit3->Text);
TestPos[3] = StrToInt(Edit4->Text);
TestPos[4] = StrToInt(Edit5->Text);
TestPos[5] = StrToInt(Edit6->Text);
TestPos[6] = StrToInt(Edit7->Text);
TestPos[7] = StrToInt(Edit8->Text);
TestPos[8] = StrToInt(Edit9->Text);
// if(TestPos[0]>1000)
// {
//e[0]=(360.0/65536.0)*TestPos[0]-45*8;
e[0] = 0;
HexError[0]= 0 ;
// }
// else
// e[0]=(360.0/65536.0)*TestPos[0]-45*0;
/*
e[1]=(360.0/65536.0)*TestPos[1]-45*1;
e[2]=(360.0/65536.0)*TestPos[2]-45*2;
e[3]=(360.0/65536.0)*TestPos[3]-45*3;
e[4]=(360.0/65536.0)*TestPos[4]-45*4;
e[5]=(360.0/65536.0)*TestPos[5]-45*5;
e[6]=(360.0/65536.0)*TestPos[6]-45*6;
e[7]=(360.0/65536.0)*TestPos[7]-45*7;
*/
if((TestPos[1]- TestPos[0])>1000)
{
e[1]=(360.0/65536.0)*(TestPos[1]- TestPos[0]- 8192);
HexError[1]=fabs(TestPos[1]-TestPos[0]-8192);
}
else
{
e[1]=(360.0/65536.0)*(TestPos[1]- TestPos[0]- 8192 + 65536);
HexError[1]=fabs(TestPos[1]-TestPos[0]-8192 + 65536);
}
if((TestPos[2]- TestPos[0])>1000)
{
e[2]=(360.0/65536.0)*(TestPos[2]- TestPos[0]- 16384);
HexError[2]=fabs(TestPos[2]-TestPos[0]-16384);
}
else
{
e[2]=(360.0/65536.0)*(TestPos[2]- TestPos[0]- 16384 + 65536);
HexError[2]=fabs(TestPos[2]-TestPos[0]-16384 + 65536);
}
if((TestPos[3]- TestPos[0])>1000)
{
e[3]=(360.0/65536.0)*(TestPos[3]- TestPos[0]- 24576);
HexError[3]=fabs(TestPos[3]-TestPos[0]-24576);
}
else
{
e[3]=(360.0/65536.0)*(TestPos[3]- TestPos[0]- 24576 + 65536);
HexError[3]=fabs(TestPos[3]-TestPos[0]-24576 + 65536);
}
if((TestPos[4]- TestPos[0])>1000)
{
e[4]=(360.0/65536.0)*(TestPos[4]- TestPos[0]- 32768);
HexError[4]=fabs(TestPos[4]-TestPos[0]-32768);
}
else
{
e[4]=(360.0/65536.0)*(TestPos[4]- TestPos[0]- 32768 + 65536);
HexError[4]=fabs(TestPos[4]-TestPos[0]-32768 + 65536);
}
if((TestPos[5]- TestPos[0])>1000)
{
e[5]=(360.0/65536.0)*(TestPos[5]-TestPos[0]- 40960);
HexError[5]=fabs(TestPos[5]-TestPos[0]-40960);
}
else
{
e[5]=(360.0/65536.0)*(TestPos[5]-TestPos[0]- 40960 + 65536);
HexError[5]=fabs(TestPos[5]-TestPos[0]-40960 + 65536);
}
if((TestPos[6]- TestPos[0])>1000)
{
e[6]=(360.0/65536.0)*(TestPos[6]-TestPos[0]- 49152);
HexError[6]=fabs(TestPos[6]-TestPos[0]-49152);
}
else
{
e[6]=(360.0/65536.0)*(TestPos[6]-TestPos[0]- 49152 + 65536);
HexError[6]=fabs(TestPos[6]-TestPos[0]-49152 + 65536);
}
if((TestPos[7]- TestPos[0])>1000)
{
e[7]=(360.0/65536.0)*(TestPos[7]-TestPos[0]- 57344);
HexError[7]=fabs(TestPos[7]-TestPos[0]-57344);
}
else
{
e[7]=(360.0/65536.0)*(TestPos[7]-TestPos[0]- 57344 + 65536);
HexError[7]=fabs(TestPos[7]-TestPos[0]-57344 + 65536);
}
if((TestPos[8]-TestPos[0])>1000)
{
e[8]=(360.0/65536.0)*(TestPos[8]-TestPos[0]- 65536);
HexError[8] = fabs(TestPos[8]-TestPos[0]-65536);
}
else
{
e[8]=(360.0/65536.0)*(TestPos[8]-TestPos[0]);
HexError[8]=fabs(TestPos[8]-TestPos[0]);
}
Form1->COS->AddXY(45*0, e[0]);
Form1->COS->AddXY(45*2, e[2]);
Form1->COS->AddXY(45*4, e[4]);
Form1->COS->AddXY(45*6, e[6]);
Form1->COS->AddXY(45*8, e[8]);
Form1->SIN->AddXY(45*1, e[1]);
Form1->SIN->AddXY(45*3, e[3]);
Form1->SIN->AddXY(45*5, e[5]);
Form1->SIN->AddXY(45*7, e[7]);
Form1->ZERO->AddXY(0, 0);
Form1->ZERO->AddXY(360, 0);
// if( TestPos[0]>1000 )
// {
// HexError[0] = fabs(TestPos[0]-65536);
// }
// else
/*
HexError[1]=fabs(TestPos[1]-TestPos[0]-8192);
HexError[2]=fabs(TestPos[2]-TestPos[0]-16384);
HexError[3]=fabs(TestPos[3]-TestPos[0]-24576);
HexError[4]=fabs(TestPos[4]-TestPos[0]-32768);
HexError[5]=fabs(TestPos[5]-TestPos[0]-40960);
HexError[6]=fabs(TestPos[6]-TestPos[0]-49152);
HexError[7]=fabs(TestPos[7]-TestPos[0]-57344);
if( TestPos[8]>1000 )
{
HexError[8] = fabs(TestPos[8]-TestPos[0]-65536);
}
else
HexError[8]=fabs(TestPos[8]-TestPos[0]);
*/
// if ( e[0] < 0 ) //TestPos[0]>1000
// {
// Edit10->Text="-"+IntToHex(HexError[0],2);
// }
// else
// {
Edit10->Text="00";//IntToHex(HexError[0],2);
// }
if (e[1] < 0)
Edit11->Text="-"+IntToHex(HexError[1],2);
else
Edit11->Text=IntToHex(HexError[1],2);
if (e[2] < 0)
Edit12->Text="-"+IntToHex(HexError[2],2);
else
Edit12->Text=IntToHex(HexError[2],2);
if (e[3] < 0)
Edit13->Text="-"+IntToHex(HexError[3],2);
else
Edit13->Text=IntToHex(HexError[3],2);
if (e[4] < 0)
Edit14->Text="-"+IntToHex(HexError[4],2);
else
Edit14->Text=IntToHex(HexError[4],2);
if (e[5] < 0)
Edit15->Text="-"+IntToHex(HexError[5],2);
else
Edit15->Text=IntToHex(HexError[5],2);
if (e[6] < 0)
Edit16->Text="-"+IntToHex(HexError[6],2);
else
Edit16->Text=IntToHex(HexError[6],2);
if (e[7] < 0)
Edit17->Text="-"+IntToHex(HexError[7],2);
else
Edit17->Text=IntToHex(HexError[7],2);
if ( e[8] < 0 )
Edit18->Text="-"+IntToHex(HexError[8],2);
else
Edit18->Text=IntToHex(HexError[8],2);
for(int i=0;i<=8;i++)
{
if(e[i]>maxerr1)
{
maxerr1=e[i];
}
if(e[i]<maxerr2)
{
maxerr2=e[i];
}
}
for(int i=1;i<=8;i+=2)
{
if(e[i]>maxerr3)
{
maxerr3=e[i];
}
if(e[i]<maxerr4)
{
maxerr4=e[i];
}
}
/* if ((maxerr1-maxerr2)<0.4)
{
Application->MessageBox(("峰值小于0.4,符合耦合条件,不需要进行调整!" ), "可以休息了!",MB_OK + MB_ICONEXCLAMATION);
}
else */
if((e[2] > e[0])&(e[3]<0))
{
Application->MessageBox(("COS项调整:请把粗测显示到0000,然后调节P10,向上调在4000点的误差值! \n\nSIN项调整:请把粗测显示到6000,然后调节P6或者是P7,向上调此曲线中峰值除以2的值!" ), "辛苦了!",MB_OK + MB_ICONINFORMATION);
}
else if((e[2] > e[0])&(e[3]>0))
{
Application->MessageBox(("COS项调整:请把粗测显示到0000,然后调节P10,向上调在4000点的误差值!\n\nSIN项调整:请把粗测显示到6000,然后调节P6或者是P7,向下调此曲线中峰值除以2的值!" ), "辛苦了!",MB_OK + MB_ICONINFORMATION);
}
else if((e[2] < e[0])&(e[3]>0))
{
Application->MessageBox(("COS项调整:请把粗测显示到0000,然后调节P10,向下调在4000点的误差值!\n\nSIN项调整:请把粗测显示到6000,然后调节P6或者是P7,向下调此曲线中峰值除以2的值!" ), "辛苦了!",MB_OK + MB_ICONINFORMATION);
}
else if((e[2] < e[0])&(e[3]<0))
{
Application->MessageBox(("COS项调整:请把粗测显示到0000,然后调节P