Exemple #1
0
bool ADbg::setDebugFile(const char * NewFilename) {
	bool result;
	result = unsetDebugFile();

	if (result) {
		result = false;

#ifdef WIN32
		hFile = CreateFileA(NewFilename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
		
		if (hFile != INVALID_HANDLE_VALUE) {
			SetFilePointer( hFile, 0, 0, FILE_END );

			result = true;
#else
		hFile = fopen(NewFilename, "w+");
		if (hFile != NULL) {
			fseek(hFile, 0, SEEK_END);
#endif
			OutPut(-1,"Debug hFile Opening succeeded");

		}
		else
			OutPut(-1,"Debug hFile %s Opening failed",NewFilename);
	}

	return result;
}

bool ADbg::unsetDebugFile() {
	bool result = (hFile == NULL);
	
#ifdef WIN32
	if (hFile != NULL) {
		result = (CloseHandle(hFile) != 0);
#else
	if (hFile != NULL) {
		result = (fclose(hFile) == 0);
#endif

		if (result) {
			OutPut(-1,"Debug hFile Closing succeeded");
			hFile = NULL;
		}
	}
	return result;
}

#endif // defined(DEBUG)

END_LIBEBML_NAMESPACE
Exemple #2
0
int main() {
  MatrixGraph graph;
  int i, j, s, t;
  char select;

  do {
    printf("输入生成图的类型(0:无向图,1:有向图):");
    scanf("%d", &graph.graphType);

    printf("输入图的顶点数量和边数量(n,m):");
    scanf("%d,%d", &graph.vertexNum,&graph.edgeNum);

    for(i=0;i<graph.vertexNum;i++)
      for(j=0;j<graph.vertexNum;j++)
        graph.edges[i][j] = MAXVALUE;

    Create(&graph);
    printf("邻接矩阵数据如下:\n");
    OutPut(&graph);

    Prim(graph);

    printf("图遍历完毕,是否要继续?Y/N: \n");
    getchar();
    scanf("%c", &select);
  }while(select !='N' && select != 'n');

  return 0;
}
void BackTrack()
{
	int k;
	x[1] = 0;		//初始化为0
	k = 1;
	while (k >= 1)	//循环
	{
		x[k] += 1;	//先放在第一个位置
		while ((x[k] <= n) && !(Place(k)))	//如果不能放
			x[k] += 1;						//放在下一个位置
		if (x[k] <= n)						//放置完成
		{
			if (k == n)						//如果已经放完了n个皇后
			{
				sum++;						//处理次数,输出
				OutPut();
			}
			else							//没有处理完,让k自加,处理下一个皇后
			{
				k++;
				x[k] = 0;
			}
		}									//x[k] > n,说明没有合适的位置了
		else
			k--;							//回溯回去,回到第k-1步
	}
}
Exemple #4
0
void Main()
{
  double accele_x_bias = 0.0, accele_y_bias = 0.0;
  double jyro_x_bias   = 0.0, jyro_y_bias   = 0.0;
  double accele_x      = 0.0, accele_y      = 0.0, accele_z = 0.0;
  double jyro_x        = 0.0, jyro_y        = 0.0;
  double theta_x       = 0.0, theta_y       = 0.0;
  double roll          = 0.0, pitch         = 0.0;
  int    i             = 0;

  SetUp();

  for(i = 0; i < 100; i ++){
    accele_x_bias += ADC_Read(ANAROG_PIN_ACCELE_X);
    accele_y_bias += ADC_Read(ANAROG_PIN_ACCELE_Y);
    jyro_x_bias   += ADC_Read(ANAROG_PIN_JYRO_X);
    jyro_y_bias   += ADC_Read(ANAROG_PIN_JYRO_Y);
  }

  accele_x_bias /= 100.0;
  accele_y_bias /= 100.0;
  jyro_x_bias   /= 100.0;
  jyro_y_bias   /= 100.0;

  while(1){
    TMR0 = 0;

    accele_x = (ADC_read(ANAROG_PIN_ACCELE_X) - accele_x_bias) * ACCELE_COEFFICIENT;
    accele_y = (ADC_read(ANAROG_PIN_ACCELE_Y) - accele_y_bias) * ACCELE_COEFFICIENT;
    accele_z = (ADC_read(ANAROG_PIN_ACCELE_Z) - ACCELE_Z_BIAS) * ACCELE_COEFFICIENT;
    jyro_x   = (ADC_read(ANAROG_PIN_JYRO_X)   - jyro_x_bias)   * JYRO_COEFFICIENT;
    jyro_y   = (ADC_read(ANAROG_PIN_JYRO_Y)   - jyro_y_bias)   * JYRO_COEFFICIENT;

    theta_x = atan(accele_x / sqrt(accele_y * accele_y + accele_z * accele_z)) * (180.0 / PI);
    theta_y = atan(accele_y / sqrt(accele_x * accele_x + accele_z * accele_z)) * (180.0 / PI);

    roll  += (jyro_x * DT) - (W * roll  * DT) + (W * theta_x * DT); //相補フィルタ
    pitch += (jyro_y * DT) - (W * pitch * DT) + (W * theta_y * DT);
    
    if(-0.15 < roll  && roll  < 0.15)
      roll = 0.0;
    if(-0.15 < pitch && pitch < 0.15)
      pitch = 0.0;

    #if DEBUG_MODE
    #if ACCELE_CHECK_MODE
    accele_x = ADC_read(ANAROG_PIN_ACCELE_X);
    accele_y = ADC_read(ANAROG_PIN_ACCELE_Y);
    accele_z = ADC_read(ANAROG_PIN_ACCELE_Z);
    AcceleCheck(accele_x, accele_y, accele_z);
    #else
    Debug(roll, pitch);
    #endif
    #else
    OutPut(pitch - roll, pitch + roll);  //right, left
    #endif
  }
}
Exemple #5
0
ADbg::ADbg(int level)
:my_level(level)
,my_time_included(false)
,my_use_file(false)
,my_debug_output(true)
,hFile(NULL)
{
	prefix[0] = '\0';
	OutPut(-1,"ADbg Creation at debug level = %d (0x%08X)",my_level,this);
}
int main() {
  ListGraph graph;
  printf("输入生成图的类型(0:无向图,1:有向图): ");
  scanf("%d" , &graph.graphType);

  printf("输入顶点数量和边数量:");
  scanf("%d,%d", &graph.vertexNum, &graph.edgeNum);

  printf("输入构成各边的两个顶点及权值(用逗号隔开):\n");

  Create(&graph);

  printf("输出的邻接表:\n");
  OutPut(&graph);
  return 0;
}
void BackTrack1(int t)
{
	//如果t>n说明已经完成一次放置
	if (t > n)
	{
		sum++;
		OutPut();
	}
	else
	{
		for (int i = 1; i <= n; ++i)
		{
			x[t] = i;
			if (Place(t))					//可以放在i位置处,则继续搜索
				BackTrack1(t + 1);
		}
	}
}
Exemple #8
0
void Main()
{
  double accele_x_bias = 0.0, accele_y_bias = 0.0;
  double jyro_x_bias   = 0.0, jyro_y_bias   = 0.0;
  double accele_x[2]   = {0.0, 0.0};
  double accele_y[2]   = {0.0, 0.0};
  double accele_z[2]   = {0.0, 0.0};
  double jyro_x        = 0.0, jyro_y        = 0.0;
  double theta_x       = 0.0, theta_y       = 0.0;
  double roll          = 0.0, pitch         = 0.0;
  int    i             = 0;

  SetUp();

  for(i = 0; i < 100; i ++){
    accele_x_bias += ADC_Read(ANAROG_PIN_ACCELE_X);
    accele_y_bias += ADC_Read(ANAROG_PIN_ACCELE_Y);
    jyro_x_bias   += ADC_Read(ANAROG_PIN_JYRO_X);
    jyro_y_bias   += ADC_Read(ANAROG_PIN_JYRO_Y);
  }

  accele_x_bias /= 100.0;
  accele_y_bias /= 100.0;
  jyro_x_bias   /= 100.0;
  jyro_y_bias   /= 100.0;

  while(1){
    do{
      Output(0.0, 0.0);
      Delay_ms(1);
    }while(ARM_STATE == 0);
  
    accele_x[1] = accele_x[0];
    accele_y[1] = accele_y[0];
    accele_z[1] = accele_z[0];

    TMR0 = 0;

    accele_x[0] = (ADC_read(ANAROG_PIN_ACCELE_X) - accele_x_bias) * ACCELE_COEFFICIENT;
    accele_y[0] = (ADC_read(ANAROG_PIN_ACCELE_Y) - accele_y_bias) * ACCELE_COEFFICIENT;
    accele_z[0] = (ADC_read(ANAROG_PIN_ACCELE_Z) - ACCELE_Z_BIAS) * ACCELE_COEFFICIENT;
    jyro_x      = (ADC_read(ANAROG_PIN_JYRO_X)   - jyro_x_bias)   * JYRO_COEFFICIENT;
    jyro_y      = (ADC_read(ANAROG_PIN_JYRO_Y)   - jyro_y_bias)   * JYRO_COEFFICIENT;

    accele_x[0] = accele_x[1] * 0.9 + accele_x[0] * 0.1;  //加重平均
    accele_y[0] = accele_y[1] * 0.9 + accele_y[0] * 0.1;
    accele_z[0] = accele_z[1] * 0.9 + accele_z[0] * 0.1;

    theta_x = atan(accele_x[0] / sqrt(accele_y[0] * accele_y[0] + accele_z[0] * accele_z[0])) * (180.0 / PI);
    theta_y = atan(accele_y[0] / sqrt(accele_x[0] * accele_x[0] + accele_z[0] * accele_z[0])) * (180.0 / PI);

    roll  += (jyro_x * DT) - (W * roll  * DT) + (W * theta_x * DT); //相補フィルタ
    pitch += (jyro_y * DT) - (W * pitch * DT) + (W * theta_y * DT);

    if(-0.1 < roll  && roll  < 0.1)
      roll = 0.0;
    if(-0.1 < pitch && pitch < 0.1)
      pitch = 0.0;
      
    #if DEBUG_MODE
    #if ACCELE_CHECK_MODE
    accele_x[0] = ADC_read(ANAROG_PIN_ACCELE_X);
    accele_y[0] = ADC_read(ANAROG_PIN_ACCELE_Y);
    accele_z[0] = ADC_read(ANAROG_PIN_ACCELE_Z);
    AcceleCheck(accele_x[0], accele_y[0], accele_z[0]);
    #else
    Debug(roll, pitch);
    #endif
    #else
    OutPut(-pitch + roll * 0.5, -pitch - roll * 0.5);  //right, left
    #endif
  }
}
void CheckForVariables(char * program)
{
	int index=0;
	int numberOfInteger=0, totIntMem=0;
	int numberOfBool=0, totBoolMem=0;
	int numberOfChar=0, totCharMem=0;
	int numberOfFloat=0, totFloatMem=0;
	int numberOfDouble=0, totDoubleMem=0;
	bool test= false;

	while( program[index] != NULL)
	{
		switch(program[index])
		{
		case '/' : index++;
				   switch( program[index] )
				   {
				   case '/' : index++;
					          while( program[index] != '\n')
							  {
									index++;
							  }
					          
							  break;
				   case '*' : index++;
							  while( (test != true) && (program[index] != NULL) )
							  {
								  switch( program[index] )
								  {
								  case '*' : index++;
									         switch( program[index] )
											 {
											 case '/' : index++;
												        test= true;
														break;
											 }
											 break;
								  }
								  index++;
							  }//end test while loop
				   }
				   index--; //had to decriment because while loop causes a skip over 1 extra char
				   break;
		case 'i' : numberOfInteger += TestForIntegers(index, program); break;
		case 'b' : numberOfBool+= TestForBool(index, program); break;
		case 'c' : numberOfChar+= TestForChar(index, program); break;
		case 'f' : numberOfFloat+= TestForFloat(index, program); break;
		case 'd' : numberOfDouble+= TestForDouble(index, program); break;
		}
		cout<<"Prosessing\n";
		index++;
	}
	
	totIntMem= numberOfInteger * sizeof(int);
	totBoolMem= numberOfBool * sizeof(bool);
	totCharMem= numberOfChar * sizeof(char);
	totFloatMem= numberOfFloat * sizeof(float);
	totDoubleMem= numberOfDouble * sizeof(double);
	
	OutPut(totBoolMem, numberOfBool, sizeof(bool), "bool");
	OutPut(totIntMem, numberOfInteger, sizeof(int), "int");
	OutPut(totCharMem, numberOfChar, sizeof(char), "char");
	OutPut(totDoubleMem, numberOfDouble, sizeof(double), "double");
	OutPut(totFloatMem, numberOfFloat, sizeof(float), "float");
	
	delete(program);

	return;
}
Exemple #10
0
ADbg::~ADbg()
{
	unsetDebugFile();
	OutPut(-1,"ADbg Deletion (0x%08X)",this);
}