Example #1
0
/* ===================================================================*/
void ReadData(void)
{
	short Ax,Ay,Az,Mx,My,Mz,Gx,Gy,Gz;
	//extern TSENSORPtr tSENSORPtr;

    if(tSENSORPtr->sensorStatus.isDataReady == TRUE)
    {
    	get_mag(&Mx,&My,&Mz);
    	get_gyro(&Gx,&Gy,&Gz);
    	get_acc(&Ax,&Ay,&Az);
    	
    	tSENSORPtr->sensorData.rawData[0]= Mx;
    	tSENSORPtr->sensorData.rawData[1]= My;
    	tSENSORPtr->sensorData.rawData[2]= Mz;
    	tSENSORPtr->sensorData.rawData[3]= Gx;
    	tSENSORPtr->sensorData.rawData[4]= Gy;
    	tSENSORPtr->sensorData.rawData[5]= Gz;
    	tSENSORPtr->sensorData.rawData[6]= Ax;
    	tSENSORPtr->sensorData.rawData[7]= Ay;
    	tSENSORPtr->sensorData.rawData[8]= Az;   	
    	
        tSENSORPtr->sensorStatus.transmitionContent = eData;
        tSENSORPtr->sensorStatus.isDataReady = FALSE;
        tSENSORPtr->sensorStatus.sensorDataStatus = eReceived;
        readCnt++;
        readCnt %= 65535; 
     
    }

}
string StarWrapper1::getInfoString(const Navigator *nav) const {
  const Vec3d j2000_pos = getObsJ2000Pos(nav);
  double dec_j2000, ra_j2000;
  rect_to_sphe(&ra_j2000,&dec_j2000,j2000_pos);
  const Vec3d equatorial_pos = nav->j2000_to_earth_equ(j2000_pos);
  double dec_equ, ra_equ;
  rect_to_sphe(&ra_equ,&dec_equ,equatorial_pos);
  stringstream oss;
  if (s->hip)
  {
    const string commonNameI18 = HipStarMgr::getCommonName(s->hip);
    const string sciName = HipStarMgr::getSciName(s->hip);
    if (commonNameI18!="" || sciName!="")
	{
		oss << commonNameI18 << (commonNameI18 == "" ? "" : " ");
		if (commonNameI18!="" && sciName!="") oss << "(";
		oss << (sciName=="" ? "" : sciName);
		if (commonNameI18!="" && sciName!="") oss << ")";
		oss << endl;
    }
    oss << "HP " << s->hip;
    if (s->component_ids)
	{
		oss << " " << HipStarMgr::convertToComponentIds(s->component_ids).c_str();
    }
    oss << endl;
  }

  oss.setf(ios::fixed, ios::floatfield);
  oss.precision(2);
  oss << _("Magnitude: ") << get_mag(nav) << " " << _("B-V: ") << s->getBV() << endl;
  oss << _("J2000 RA/DE: ") << Utility::printAngleHMS(ra_j2000,true)
		  << " / " << Utility::printAngleDMS(dec_j2000,true) << endl;
  
  oss << _("Equ of date RA/DE: ") << Utility::printAngleHMS(ra_equ)
		  << " / " << Utility::printAngleDMS(dec_equ) << endl;

    // calculate alt az
  double az,alt;
  rect_to_sphe(&az,&alt,nav->earth_equ_to_local(equatorial_pos));
  az = 3*M_PI - az;  // N is zero, E is 90 degrees
  if (az > M_PI*2)
	  az -= M_PI*2;    
  oss << _("Alt/Az: ") << Utility::printAngleDMS(alt) << " / " << Utility::printAngleDMS(az) << endl;

  if (s->plx)
  {
		oss.precision(5);
		oss << _("Parallax: ") << (0.00001*s->plx) << endl;
		oss.precision(2);
		oss << _("Distance: ") << (AU/(SPEED_OF_LIGHT*86400*365.25)) / (s->plx*((0.00001/3600)*(M_PI/180)))
			<< " " << _("ly") << endl;
  }

  if (s->sp_int)
  {
	  oss << _("Spectral Type: ") << HipStarMgr::convertToSpectralType(s->sp_int).c_str() << endl;
  }
  return oss.str();
}
string StarWrapperBase::getInfoString(const Navigator *nav) const {
  const Vec3d j2000_pos = getObsJ2000Pos(nav);
  double dec_j2000, ra_j2000;
  rect_to_sphe(&ra_j2000,&dec_j2000,j2000_pos);
  const Vec3d equatorial_pos = nav->j2000_to_earth_equ(j2000_pos);
  double dec_equ, ra_equ;
  rect_to_sphe(&ra_equ,&dec_equ,equatorial_pos);
  stringstream oss;
  oss.setf(ios::fixed, ios::floatfield);
  oss.precision(2);
  oss << "Magnitude: " << get_mag(nav) << " B-V: " << getBV() << endl;
  oss << "J2000" << " " << "RA/DE: " << Utility::printAngleHMS(ra_j2000,true)
		  << " / " << Utility::printAngleDMS(dec_j2000,true) << endl;
  oss << "Equ of date" << " " << "RA/DE: " << Utility::printAngleHMS(ra_equ)
		  << " / " << Utility::printAngleDMS(dec_equ) << endl;

    // calculate alt az
  double az,alt;
  rect_to_sphe(&az,&alt,nav->earth_equ_to_local(equatorial_pos));
  az = 3*M_PI - az;  // N is zero, E is 90 degrees
  if(az > M_PI*2) az -= M_PI*2;    
  oss << "Alt/Az: " << Utility::printAngleDMS(alt) << " / " << Utility::printAngleDMS(az) << endl;
  
  return oss.str();
}
string StarWrapperBase::getShortInfoString(const Navigator *nav) const
{
	stringstream oss;
	oss.setf(ios::fixed, ios::floatfield);
	oss.precision(2);
	oss << "Magnitude: " << get_mag(nav);
	return oss.str();
}
Example #5
0
void MainWindow::graphMoveEvent(QMouseEvent *event)
{
  if (!(event->buttons() & Qt::LeftButton))  return;

  if (((event->pos() - dragStartPosition).manhattanLength()) < QApplication::startDragDistance()) return;

  BoxChecked(true);
  
  QPoint dis = (event->pos() - dragStartPosition);
  double xdis = dis.x();
  double ydis = dis.y();
  
  double x = M_PI*event->pos().x()/600.0;
  double y = event->pos().y()/400.0;
  
  double m = get_mag(x);
  bool in_passband = (m>-3);
	
  double y_db = -100.0*y + 10;
  bool above_stop = (-y_db < m);
  
  if (fabs(xdis) > fabs(ydis)) {
	// Bandpass or Bandstop
	if (get_filter_type() > 1) {
	  set_center(xdis);
	} else {
	  horiz_swipe(xdis,in_passband);
	}
  } else {
	vertical_swipe(-ydis,in_passband,above_stop);
  }

  order = get_order();
  ui->order->setText(QApplication::translate("MainWindow", std::to_string(order).c_str(), 0));
  ui->ripple->setText(QApplication::translate("MainWindow", std::to_string(ripple()).c_str(), 0));
  ui->fc->setText(QApplication::translate("MainWindow", std::to_string(fc()).c_str(), 0));
  
  QCPGraph* ptr = GetPtr();
  dragStartPosition = event->pos();
  if (ptr != NULL) {
	ui->customPlot->graph()->clearData();
	plot3(ui->customPlot);
  }
}
string StarWrapper1::getShortInfoString(const Navigator *nav) const
{
	stringstream oss;
	if (s->hip)
	{
		const string commonNameI18 = HipStarMgr::getCommonName(s->hip);
		const string sciName = HipStarMgr::getSciName(s->hip);
		if (commonNameI18!="" || sciName!="")
		{
			oss << commonNameI18 << (commonNameI18 == "" ? "" : " ");
			if (commonNameI18!="" && sciName!="") oss << "(";
			oss << (sciName=="" ? "" : sciName);
			if (commonNameI18!="" && sciName!="") oss << ")";
			oss << "  ";
		}
		oss << "HP " << s->hip;
		if (s->component_ids)
		{
			oss << " " << HipStarMgr::convertToComponentIds(s->component_ids).c_str();
		}
		oss << "  ";
	}
	
	oss.setf(ios::fixed, ios::floatfield);
	oss.precision(2);
	oss << _("Magnitude: ") << get_mag(nav) << "  ";

	if (s->plx)
	{
		oss << _("Distance: ") << (AU/(SPEED_OF_LIGHT*86400*365.25)) / (s->plx*((0.00001/3600)*(M_PI/180)))
			<< " " << _("ly") << "  ";
	}
	
	if (s->sp_int)
	{
		oss << _("Spectral Type: ") << HipStarMgr::convertToSpectralType(s->sp_int).c_str();
	}
	return oss.str();
}
Example #7
0
/* ===================================================================*/
void ReadData(void)
{
	short Ax,Ay,Az,Mx,My,Mz,Gx,Gy,Gz;
	uint32 i;
	//extern TSENSORPtr tSENSORPtr;
		
    if(tSENSORPtr->sensorStatus.isDataReady == TRUE)
    {
    	get_mag(&Mx,&My,&Mz);
    	get_gyro(&Gx,&Gy,&Gz);
    	get_acc(&Ax,&Ay,&Az);
    	
    	tSENSORPtr->sensorData.rawData[0]= Mx;//磁传感器变量;
    	tSENSORPtr->sensorData.rawData[1]= My;
    	tSENSORPtr->sensorData.rawData[2]= Mz;
    	tSENSORPtr->sensorData.rawData[3]= Gx;
    	tSENSORPtr->sensorData.rawData[4]= Gy;
    	tSENSORPtr->sensorData.rawData[5]= Gz;
    	tSENSORPtr->sensorData.rawData[6]= Ax;
    	tSENSORPtr->sensorData.rawData[7]= Ay;
    	tSENSORPtr->sensorData.rawData[8]= Az;   	
    	
        tSENSORPtr->sensorStatus.transmitionContent = eData;
        tSENSORPtr->sensorStatus.isDataReady = FALSE;
        tSENSORPtr->sensorStatus.sensorDataStatus = eReceived;
    	
        //printf("Mx=%d,My=%d,Mz=%d\n",Mx,My,Mz);     
        
    	//test the sample fre of read_data
    	PTD0_50HZ_ClrVal(NULL);
    	for(i=0;i<100;i++);
    	PTD0_50HZ_SetVal(NULL);
     
    }

}
Example #8
0
double vector::Vector::magval()
{
	return get_mag();
}
int main(int argc, char* argv[])
{
	// 3 local magnitudes and angles
	long double mag_a, mag_b, mag_c;
	
	// error validation
	char* end_ptr_a;
	char* end_ptr_b;

	// local output strings
	char* edge_t;
	char* angle_t;

	// check for correct number of args
	if(argc != 7)
	{
		printf("error\n");
		return -1;
	}

	//make 3 points, if any intializations fail, return and display errors.....
	//	inputs of '\0' will be treated as 0...
	// point a
	if(point_init(&p_a, strtoll(argv[1], &end_ptr_a, 10), strtoll(argv[2], &end_ptr_b, 10)) == -1)
	{
		printf("error\n");
		return -1;
	}
	if(*end_ptr_a != 0 || *end_ptr_b != 0)
	{
		printf("error\n");
		return -1;	
	}
	// point b
	if(point_init(&p_b, strtoll(argv[3], &end_ptr_a, 10), strtoll(argv[4], &end_ptr_b, 10)) == -1)
	{
		printf("error\n");
		return -1;
	}
	if(*end_ptr_a != 0 || *end_ptr_b != 0)
	{
		printf("error\n");
		return -1;	
	}
	// point c
	if(point_init(&p_c, strtoll(argv[5], &end_ptr_a, 10), strtoll(argv[6], &end_ptr_b, 10)) == -1)
	{
		printf("error\n");
		return -1;
	}
	if(*end_ptr_a != 0 || *end_ptr_b != 0)
	{
		printf("error\n");
		return -1;	
	}
	
	// if one of the coordinates was non-numeric
	if(errno == EINVAL)
	{
		printf("error\n");
		return -1;
	}

	// get three edge magnitudes (squared)
	mag_a = get_mag(&p_a, &p_b);
	mag_b = get_mag(&p_b, &p_c);
	mag_c = get_mag(&p_c, &p_a);

	//check for colinear points
	 //x_1(y_2-y_3)+x_2(y_3-y_1)+x_3(y_1-y_2)=0. 
	if((p_a.x*(p_b.y - p_c.y) + p_b.x*(p_c.y - p_a.y) + p_c.x*(p_a.y - p_b.y)) == 0)
	{
		printf("not a triangle\n");
		return 0;
	}

	// if all three edges are the same length...
	if(fabsl(mag_a - mag_b) < 0.00000001 && fabsl(mag_b - mag_c) < 0.00000001 && fabsl(mag_c - mag_a) < 0.00000001)
	{
		edge_t = "equilateral";    	
	}
	// else if all three edges have unique lengths...
	else if(mag_a != mag_b && mag_a != mag_c && mag_b != mag_c)
	{
		edge_t = "scalene"; 
	}
	// else if two edge lengths are identical     
	else
	{
		edge_t = "isosceles";
	}

	if(strcmp(edge_t, "equilateral") == 0)
	{
		angle_t = "acute";
		printf("%s %s\n", edge_t, angle_t);
		return 0;
	}
	
// 	Let "c" be the longest side on each set of three numbers.
	// If c^2 = a^2+b^2, the triangle is right
	// If c^2 > a^2 + b^2, the triangle is obtuse
	// If c^2 < a^2 + b^2, the triangle is acute.

	if(get_longest_side(mag_a, mag_b, mag_c) == 'a')
	{
		if(mag_a == (mag_b + mag_c))
		{
			angle_t = "right";
		}
		else if(mag_a > (mag_b + mag_c))
		{
			angle_t = "obtuse";
		}
		else
		{
			angle_t = "acute";
		}
	}
	else if(get_longest_side(mag_a, mag_b, mag_c) == 'b')
	{
		if(mag_b == (mag_a + mag_c))
		{
			angle_t = "right";
		}
		else if(mag_b > (mag_a + mag_c))
		{
			angle_t = "obtuse";
		}
		else
		{
			angle_t = "acute";
		}
	}
	else
	{	
		if(mag_c == (mag_a + mag_b))
		{
			angle_t = "right";
		}
		else if(mag_c > (mag_a + mag_b))
		{
			angle_t = "obtuse";
		}
		else
		{
			angle_t = "acute";
		}
	}

	// ******** assert both output strings were assigned values before completing ***********
	assert(edge_t != 0);
	assert(angle_t != 0);

	printf("%s %s\n", edge_t, angle_t);
}
Example #10
0
/* get jupiter info in md[0], moon info in md[1..J_NMOONS-1].
 * if !dir always use meeus model.
 * if !jop caller just wants md[] for names
 * N.B. we assume sop and jop are updated.
 */
void
jupiter_data (
double Mjd,		/* mjd */
char dir[],             /* dir in which to look for helper files */
Obj *sop,               /* Sun */
Obj *jop,		/* jupiter */
double *sizep,		/* jup angular diam, rads */
double *cmlI, double *cmlII,		/* central meridian longitude, rads */
double *polera, double *poledec,	/* pole location */
MoonData md[J_NMOONS])	/* return info */
{
        double JD;

	/* always copy back at least for name */
	memcpy (md, jmd, sizeof(jmd));

	/* pole */
	if (polera) *polera = POLE_RA;
	if (poledec) *poledec = POLE_DEC;

	/* nothing else if repeat call or just want names */
	if (Mjd == mdmjd || !jop) {
	    if (jop) {
		*sizep = sizemjd;
		*cmlI = cmlImjd;
		*cmlII = cmlIImjd;
	    }
	    return;
	}
	JD = Mjd + MJD0;

	/* planet in [0] */
	md[0].ra = jop->s_ra;
	md[0].dec = jop->s_dec;
	md[0].mag = get_mag(jop);
	md[0].x = 0;
	md[0].y = 0;
	md[0].z = 0;
	md[0].evis = 1;
	md[0].svis = 1;

	/* size is straight from jop */
	*sizep = degrad(jop->s_size/3600.0);

	/* mags from JPL ephemeris */
	md[1].mag = 5.7;
	md[2].mag = 5.8;
	md[3].mag = 5.3;
	md[4].mag = 6.7;

	/* get moon data from BDL if possible, else Meeus' model.
	 * always use Meeus for cml
	 */
	if (use_bdl (JD, dir, md) == 0)
	    meeus_jupiter (Mjd, cmlI, cmlII, NULL);
	else
	    meeus_jupiter (Mjd, cmlI, cmlII, md);

	/* set visibilities */
	moonSVis (sop, jop, md);
	moonPShad (sop, jop, md);
	moonEVis (md);
	moonTrans (md);

	/* fill in moon ra and dec */
	moonradec (*sizep, md);

	/* save */
	mdmjd = Mjd;
	sizemjd = *sizep;
	cmlImjd = *cmlI;
	cmlIImjd = *cmlII;
	memcpy (jmd, md, sizeof(jmd));
}