Skip to content. | Skip to navigation

Personal tools

remote/presvac.cpp

remote/presvac.cpp

remote/presvac.cpp

/////////////////////////////////////////////////////////////////////////////
// PRESVAC.CPP
//
//  Last updated: 31/1/2005
//
//  Part of the source code for the remote M3 Program
//
//  This file contains code for the control of the pressure/vacuum behind
//  the tertiary mirror.
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CPresVac::Init - Initialize pressure/vacuum control
void CPresVac::Init()
{
/*
	PulseUpdateTime = msTimer;
	olderr = 0.0;
	target = 0.0;
*/
  ave = 0;
	P = 0.0;
	I = 0.0;
	D = 0.0;

	// Start reading first DGH
	CurrentDGH = 0;
	// Initialize DGH modules.
	DGHs[0].Init('a');
	DGHs[1].Init('b');
	DGHs[2].Init('c');

}

/////////////////////////////////////////////////////////////////////////////
// CPresVac::Update - Update pressure/vacuum control variables
void CPresVac::Update()
{
	char s[50];

	/*
	// Update DGH modules (mirror load cell readings)
	preverrorcount = DGHs[CurrentDGH].ErrorCount;
	e = DGHs[CurrentDGH].Update();
	if (e == -1)
		return;			// DGH module not finished updating
	if (e == 0)
	// DGH module read success
	{
		if (preverrorcount >= 3)
			EDSLog.Add(998,"DGH %c Error Messages Resumed",CurrentDGH+'A');
*/
  if (DGHs[CurrentDGH].ReadError == 0)
	{
  	sprintf(s,"%+7.3fV  ",DGHs[CurrentDGH].Reading);
		PutString16(s,468,548,168+16*CurrentDGH,BLACK,SHECMEDGRAY);
  }
/*
		EDSLog.Add(802,"D%cR%+07.3f",CurrentDGH+'A',DGHs[CurrentDGH].Reading);
	}
*/
	else
	// DGH module read error
	{
		PutString16("Read Error",468,548,168+16*CurrentDGH,SHECRED,SHECMEDGRAY);
  }
/*
		EDSLog.Add(802,"D%cRE",CurrentDGH+'A');
		if (DGHs[CurrentDGH].ErrorCount < 3)
			EDSLog.Add(50,"DGH %c Read Error",CurrentDGH+'A');
		else if (DGHs[CurrentDGH].ErrorCount == 3)
			EDSLog.Add(51,"DGH %c Error Messages Suspended",CurrentDGH+'A');
	}
*/
	CurrentDGH++;
	// Continue scanning DGH's
	if (CurrentDGH > 2)
		CurrentDGH = 0;

	if ((msTimer - PulseUpdateTime) > PulseCycle)
	{
		PulseUpdateTime  = msTimer;
/*
		ave = (DGHs[0].Reading + DGHs[1].Reading + DGHs[2].Reading) / 3.0;
		err = target - ave;
*/
		PresVacChart.Add(ave);
  }
/*
    if (PresVacMode == PVMAuto)
    {
		  // Calc derivative term
		  D = Kd * (err - olderr);
		  olderr = err;

		  // Calc proportional term
		  P = Kp * err;

		  // Calc integral term
		  I = I + Ki * err;

		  if (fabs(err) > IntegralThreshold)
			  I = 0.0;

		  // Limit I to within +/- VIl/PIl
		  if (I > VIl)
			  I = VIl;
		  if (I < -PIl)
			  I = -PIl;
    }
    else
		{
      P = 0.0;
      I = 0.0;
      D = 0.0;
    }

		// Calculate pulse width
		disable();

		if ((P + I + D) > 0.0)
		{
			VacuumPulseWidth = PulseCycle * (P + I + D) + VacuumMinPulseWidth;
			PressurePulseWidth = PressureMinPulseWidth;
		}
		else if ((P + I + D) < 0.0)
		{
			PressurePulseWidth = -PulseCycle * (P + I + D) + PressureMinPulseWidth;
			VacuumPulseWidth = VacuumMinPulseWidth;
		}
		else
		{
			VacuumPulseWidth = VacuumMinPulseWidth;
			PressurePulseWidth = PressureMinPulseWidth;
		}

		// Limit pulse width to 0..PulseCycle
		if (VacuumPulseWidth > PulseCycle) VacuumPulseWidth = PulseCycle;
		if (PressurePulseWidth > PulseCycle) PressurePulseWidth = PulseCycle;

		enable();
*/
		// Update screen
	  sprintf(s,"P:%7.3f",P);
	  PutString16(s,556,629,264,BLACK,SHECMEDGRAY);
	  sprintf(s,"I:%7.3f",I);
	  PutString16(s,556,629,280,BLACK,SHECMEDGRAY);
	  sprintf(s,"D:%7.3f",D);
		PutString16(s,556,629,296,BLACK,SHECMEDGRAY);
	  //sprintf(s,"Kp:%6.3f",Kp);
		//PutString16(s,556,629,264,BLACK,SHECMEDGRAY);
		//sprintf(s,"Ki:%6.3f",Ki);
		//PutString16(s,556,629,280,BLACK,SHECMEDGRAY);
		//sprintf(s,"Kd:%6.3f",Kd);
		//PutString16(s,556,629,296,BLACK,SHECMEDGRAY);
		sprintf(s,"%4d",PressurePulseWidth);
		PutString16(s,484,516,312,BLACK,SHECMEDGRAY);
		sprintf(s,"%4d",VacuumPulseWidth);
		PutString16(s,484,516,328,BLACK,SHECMEDGRAY);
	  // Display M3 average weight in Lbs
    sprintf(s,"%+7.3f",ave*49.0);
	  PutString16(s,532,588,216,BLACK,SHECMEDGRAY);
/*
	}
*/

	// Display pressure/vacuum valve status
	if (vacuum) // Vacuum
		PutChar16('þ',468,328,SHECGREEN,SHECMEDGRAY);
	else
		PutChar16('þ',468,328,BLACK,SHECMEDGRAY);
	if (pressure) // Pressure
		PutChar16('þ',468,312,SHECGREEN,SHECMEDGRAY);
	else
		PutChar16('þ',468,312,BLACK,SHECMEDGRAY);
}

/////////////////////////////////////////////////////////////////////////////
// CPresVac::Display - Display infrequently changed information
void CPresVac::Display()
{
  char s[10];

	// Display Mode
	if (PresVacMode == PVMAuto)
		PutString16("AUTO",596,629,312,BLACK,SHECMEDGRAY);
	else
		PutString16(" OFF",596,629,312,BLACK,SHECMEDGRAY);
  // Display graph scale
  sprintf(s,"ñ%3.1f",PresVacChart.GetScale());
  PutString16(s,372,412,276,BLACK,SHECMEDGRAY);
}

Generated by GNU Enscript 1.6.5.2.
Document Actions