Esempio n. 1
0
    float
    Duration::parse(const IMC::Rows* maneuver, Position& last_pos, float last_dur,
                    std::vector<float>& durations, const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      Maneuvers::RowsStages rstages = Maneuvers::RowsStages(maneuver, NULL);

      Position pos;
      pos.z = maneuver->z;
      pos.z_units = maneuver->z_units;

      rstages.getFirstPoint(&pos.lat, &pos.lon);

      float distance = distance3D(pos, last_pos);
      durations.push_back(distance / speed + last_dur);

      last_pos = pos;

      distance += rstages.getDistance(&last_pos.lat, &last_pos.lon);

      std::vector<float>::const_iterator itr = rstages.getDistancesBegin();

      for (; itr != rstages.getDistancesEnd(); ++itr)
      {
        // compensate with path controller's eta factor
        float travelled = compensate(*itr, speed);
        durations.push_back(travelled / speed + durations.back());
      }

      return distance / speed;
    }
Esempio n. 2
0
    bool
    Duration::parse(const IMC::Rows* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      Maneuvers::RowsStages rstages = Maneuvers::RowsStages(maneuver, NULL);

      Position pos;
      pos.z = maneuver->z;
      pos.z_units = maneuver->z_units;

      rstages.getFirstPoint(&pos.lat, &pos.lon);

      float distance = distance3D(pos, last_pos);
      m_accum_dur->addDuration(distance / speed);

      last_pos = pos;

      distance += rstages.getDistance(&last_pos.lat, &last_pos.lon);

      std::vector<float>::const_iterator itr = rstages.getDistancesBegin();

      for (; itr != rstages.getDistancesEnd(); ++itr)
      {
        // compensate with path controller's eta factor
        float travelled = compensate(*itr, speed);
        m_accum_dur->addDuration(travelled / speed);
      }

      return true;
    }
Esempio n. 3
0
    float
    Duration::parse(const IMC::YoYo* maneuver, Position& last_pos, float last_dur,
                    std::vector<float>& durations, const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      extractPosition(maneuver, pos);

      // Use 2D distance here
      float horz_dist = distance2D(pos, last_pos);
      float travelled = horz_dist / std::cos(maneuver->pitch);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      durations.push_back(travelled / speed + last_dur);

      return durations.back();
    }
Esempio n. 4
0
    float
    Duration::parse(const IMC::Elevator* maneuver, Position& last_pos, float last_dur,
                    std::vector<float>& durations, const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      extractPosition(maneuver, pos);

      float goto_dist = distance3D(pos, last_pos);
      float amplitude = std::fabs(last_pos.z - maneuver->end_z);
      float real_dist = amplitude / std::sin(c_rated_pitch);

      float travelled = goto_dist + real_dist;

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      durations.push_back(travelled / speed + last_dur);

      return durations.back();
    }
Esempio n. 5
0
    bool
    TimeProfile::parse(const IMC::Elevator* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      Position pos;
      extractPosition(maneuver, pos);

      float goto_dist = distance3D(pos, last_pos);
      float amplitude = std::fabs(last_pos.z - maneuver->end_z);
      float real_dist = amplitude / std::sin(c_rated_pitch);

      float travelled = goto_dist + real_dist;

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      float duration = travelled / speed;

      // Update speed profile
      m_speed_vec->push_back(SpeedProfile(maneuver, duration));

      m_accum_dur->addDuration(duration);

      return true;
    }
Esempio n. 6
0
    bool
    TimeProfile::parse(const IMC::YoYo* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      Position pos;
      extractPosition(maneuver, pos);

      // Use 2D distance here
      float horz_dist = distance2D(pos, last_pos);
      float travelled = horz_dist / std::cos(maneuver->pitch);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      float duration = travelled / speed;

      // Update speed profile
      m_speed_vec->push_back(SpeedProfile(maneuver, duration));

      m_accum_dur->addDuration(duration);

      return true;
    }
Esempio n. 7
0
    bool
    TimeProfile::parse(const IMC::PopUp* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      // Travel time
      float travel_time;

      if ((maneuver->flags & IMC::PopUp::FLG_CURR_POS) != 0)
      {
        Position pos;
        extractPosition(maneuver, pos);

        float travelled = distance3D(pos, last_pos);

        // compensate with path controller's eta factor
        travelled = compensate(travelled, speed);

        travel_time = travelled / speed;

        last_pos = pos;
      }
      else
      {
        travel_time = 0;
      }

      // Update speed profile
      m_speed_vec->push_back(SpeedProfile(maneuver, travel_time));

      // Rising time and descending time
      float rising_time;
      float descending_time;
      if (maneuver->z_units == IMC::Z_DEPTH)
      {
        rising_time = (std::fabs(last_pos.z) / std::sin(c_rated_pitch)) / speed;
        descending_time = (std::fabs(maneuver->z) / std::sin(c_rated_pitch)) / speed;
      }
      else // altitude, assume zero
      {
        rising_time = 0.0;
        descending_time = 0.0;
      }

      // surface time
      float surface_time = c_fix_time;

      // Update speed profile
      m_speed_vec->push_back(SpeedProfile(maneuver, rising_time));
      m_speed_vec->push_back(SpeedProfile(0.0, 0, surface_time));
      m_speed_vec->push_back(SpeedProfile(maneuver, descending_time));

      m_accum_dur->addDuration(travel_time + rising_time + surface_time + descending_time);

      return true;
    }
Esempio n. 8
0
    bool
    TimeProfile::parse(const IMC::FollowPath* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      Position pos;
      pos.z = maneuver->z;
      pos.z_units = maneuver->z_units;

      IMC::MessageList<IMC::PathPoint>::const_iterator itr = maneuver->points.begin();

      if (!maneuver->points.size())
      {
        // Update speed profile
        m_speed_vec->push_back(SpeedProfile(0.0, 0));

        // Update duration
        m_accum_dur->addDuration(0.0);
      }
      else
      {
        // Iterate point list
        for (; itr != maneuver->points.end(); itr++)
        {
          if ((*itr) == NULL)
            continue;

          pos.lat = maneuver->lat;
          pos.lon = maneuver->lon;
          Coordinates::WGS84::displace((*itr)->x, (*itr)->y, &pos.lat, &pos.lon);

          float travelled = distance3D(pos, last_pos);

          last_pos = pos;

          float duration = compensate(travelled, speed) / speed;

          // Update speed profile
          m_speed_vec->push_back(SpeedProfile(maneuver, duration));

          // compensate with path controller's eta factor
          m_accum_dur->addDuration(duration);
        }
      }

      return true;
    }
Esempio n. 9
0
    float
    Duration::parse(const IMC::PopUp* maneuver, Position& last_pos, float last_dur,
                    std::vector<float>& durations, const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      // Travel time
      float travel_time;

      if ((maneuver->flags & IMC::PopUp::FLG_CURR_POS) != 0)
      {
        Position pos;
        extractPosition(maneuver, pos);

        float travelled = distance3D(pos, last_pos);

        // compensate with path controller's eta factor
        travelled = compensate(travelled, speed);

        travel_time = travelled / speed;

        last_pos = pos;
      }
      else
      {
        travel_time = 0;
      }

      // Rising time
      float rising_time;
      if (maneuver->z_units == IMC::Z_DEPTH)
        rising_time = std::fabs(last_pos.z) / speed;
      else // altitude, assume zero
        rising_time = 0.0;

      // surface time
      bool wait = (maneuver->flags & IMC::PopUp::FLG_WAIT_AT_SURFACE) != 0;
      float surface_time = wait ? maneuver->duration : c_fix_time;

      durations.push_back(travel_time + rising_time + surface_time + last_dur);

      return durations.back();
    }
Esempio n. 10
0
    float
    Duration::parse(const IMC::FollowPath* maneuver, Position& last_pos, float last_dur,
                    std::vector<float>& durations, const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      pos.z = maneuver->z;
      pos.z_units = maneuver->z_units;

      IMC::MessageList<IMC::PathPoint>::const_iterator itr = maneuver->points.begin();
      double total_duration = last_dur;

      if (!maneuver->points.size())
      {
        durations.push_back(0.0);
      }
      else
      {
        // Iterate point list
        for (; itr != maneuver->points.end(); itr++)
        {
          if ((*itr) == NULL)
            continue;

          pos.lat = maneuver->lat;
          pos.lon = maneuver->lon;
          Coordinates::WGS84::displace((*itr)->x, (*itr)->y, &pos.lat, &pos.lon);

          float travelled = distance3D(pos, last_pos);

          last_pos = pos;

          // compensate with path controller's eta factor
          total_duration += compensate(travelled, speed) / speed;
          durations.push_back(total_duration);
        }
      }

      return durations.back();
    }
Esempio n. 11
0
    float
    Duration::parseSimple(const Type* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      extractPosition(maneuver, pos);
      float travelled = distance3D(pos, last_pos);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      return travelled / speed;
    }
Esempio n. 12
0
static void cb(uev_t *w, void *arg, int events)
{
	double avg, load[3];
	struct sysinfo si;

	if (sysinfo(&si)) {
		ERROR("Failed reading system loadavg");
		return;
	}

	for (int i = 0; i < 3; i++)
		load[i] = (double)si.loads[i] / (1 << SI_LOAD_SHIFT);

#ifdef SYSLOG_MARK
//	LOG("Load avg: %.2f, %.2f, %.2f (1, 5, 15 min) | Num CPU cores: %d",
//	    load[0], load[1], load[2], (int)num);
	if (logmark)
		LOG("Loadavg: %.2f, %.2f, %.2f (1, 5, 15 min)", load[0], load[1], load[2]);
#endif

#if 0
	/* Compensate for number of CPU cores */
	compensate(load);
#endif

	avg = (load[0] + load[1]) / 2.0;
	DEBUG("System load: %.2f, %.2f, %.2f (1, 5, 15 min), avg: %.2f (1 + 5), warning: %.2f, reboot: %.2f",
	      load[0], load[1], load[2], avg, warning, critical);

	if (avg > warning) {
		if (above_watermark(avg, &si)) {
			ERROR("System load too high, %.2f > %0.2f, rebooting system ...", avg, critical);
			if (checker_exec(exec, "loadavg", 1, avg, warning, critical))
				wdt_forced_reset(w->ctx, getpid(), PACKAGE ":loadavg", 0);
			return;
		}

		WARN("System load average very high, %.2f > %0.2f!", avg, warning);
		checker_exec(exec, "loadavg", 0, avg, warning, critical);
	}
}
Esempio n. 13
0
    float
    Duration::parseSimple(const Type* maneuver, Position& last_pos,
                          float last_dur, std::vector<float>& durations,
                          const SpeedConversion& speed_conv)
    {
      float speed = convertSpeed(maneuver, speed_conv);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      extractPosition(maneuver, pos);
      float travelled = distance3D(pos, last_pos);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      durations.push_back(travelled / speed + last_dur);
      return durations[0];
    }
Esempio n. 14
0
    float
    TimeProfile::parseSimple(const Type* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return -1.0;

      Position pos;
      extractPosition(maneuver, pos);
      float travelled = distance3D(pos, last_pos);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      float duration = travelled / speed;

      // Update speed profile
      m_speed_vec->push_back(SpeedProfile(maneuver, duration));

      return duration;
    }
Esempio n. 15
0
    bool
    Duration::parse(const IMC::YoYo* maneuver, Position& last_pos)
    {
      float speed = convertSpeed(maneuver);

      if (speed == 0.0)
        return false;

      Position pos;
      extractPosition(maneuver, pos);

      // Use 2D distance here
      float horz_dist = distance2D(pos, last_pos);
      float travelled = horz_dist / std::cos(maneuver->pitch);

      // compensate with path controller's eta factor
      travelled = compensate(travelled, speed);

      last_pos = pos;

      m_accum_dur->addDuration(travelled / speed);

      return true;
    }
Esempio n. 16
0
DWORD WINAPI MdiMachiningBuildThreadProc(LPVOID lpParam)
{
	LPCmdThreadParam  pData; 
  	
	LPCmdThreadParam  pData_nc;
	DWORD dwThreadID;
	LPNCDATA pDataNcGraphMem;
	FILE *file;
	int nItemCount;
	int reallength;

	TCHAR szBuffer[501]; 
	
	
	int decodeNum,compasateNum,tapeNum,ComputeNum;
	int all_decode_num,all_creat_num;

	nc_data decodeData[2*DECODE_NUM_ONCE];
	nc_data compasateData[2*DECODE_NUM_ONCE];
	nc_data tapeData[2*DECODE_NUM_ONCE];
	nc_data ComputeData[2*DECODE_NUM_ONCE];
	M_data MChild[2*DECODE_NUM_ONCE];
	

	
	
	int  fdEdit;  //译码文件句柄定义
	int end_decode;
	

	double compasate_Start_point_X,compasate_Start_point_Y;
    int compasate_build_c;
	nc_data *compasate_cs;

	double tape_Start_point_X,tape_Start_point_Y;
	double tape_Start_point_B,tape_Start_point_C;
    int tape_build_c,first5152flag;
	nc_data *tape_cs;
	


	int nc_start_flag;

	int i;
	int j = 0,k = 0;
    char ptext[100];
	
	

	
			//以下添加mdi加工程序
			//SuspendThread(MdihThread);
			
			compasate_Start_point_X=0.;
			compasate_Start_point_Y=0.;
			compasate_build_c=0;
			
			tape_Start_point_X=0.;
			tape_Start_point_Y=0.;
			tape_build_c=0;
			
			memset(decodeData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));
			memset(compasateData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));
			memset(ComputeData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));
			memset(MChild,0,2*DECODE_NUM_ONCE*sizeof(M_data)); 
		   
			
			compasate_cs = (nc_data *)malloc(sizeof(nc_data));
			memset(compasate_cs,0,sizeof(nc_data));

			tape_cs = (nc_data *)malloc(sizeof(nc_data));
			memset(tape_cs,0,sizeof(nc_data));
			
			


			pData = (LPCmdThreadParam)lpParam;

			end_decode = 0;
			all_decode_num =0;
			all_creat_num = 0;

			nc_start_flag=1;


			
			//将mdi的nc码放到临时文件中
			
			
			
			if ((file = fopen("MdiTemp.txt", "w+")) == NULL)
			{	
				MessageBox (pData->hWnd,"can not create MdiTemp file in function MdiMachiningBuildThreadProc",NULL,NULL);
				
				return 1;
			}


			nItemCount = SendMessage(GetDlgItem(pData->hWnd,IDC_MDILIST),LB_GETCOUNT,0,0);
			
			if(nItemCount==0)
			{
				MessageBox (pData->hWnd,"there is no NCCODE in function MdiMachiningBuildThreadProc",NULL,NULL);
				
				return 1;
			}
			
			for(i=0;i<nItemCount;i++)
			{
				SendMessage(GetDlgItem(pData->hWnd,IDC_MDILIST),LB_GETTEXT,i,(LPARAM)szBuffer);
				reallength = SendMessage(GetDlgItem(pData->hWnd,IDC_MDILIST),LB_GETTEXTLEN,i,0);
				
				if (fwrite(szBuffer, 1, reallength, file) < 0)
				{
        				MessageBox (pData->hWnd,"write file err in function MdiMachiningBuildThreadProc" ,NULL,NULL);
						return 1;
						
				}
			}
			fclose (file);
			fdEdit = _open("MdiTemp.txt", O_RDONLY);

			do{

				do{
					reallength = _read(fdEdit, ptext+k, 1 );
					if(reallength == 0)
					{
						return 0;
					}
					k++;
				}while(ptext[k-1] != ';');
				ptext[k] = 0;


					if(strstr(ptext+j,"X")) 
					{
						data_coorswitch.x=Gcode2d(ptext+j,"X");
					}
					else 
					{
						data_coorswitch.x = 0;
					}
					if(strstr(ptext+j,"Y")) 
					{
						data_coorswitch.y=Gcode2d(ptext+j,"Y");
					}
					else 
					{
						data_coorswitch.y = 0;
					}
					if(strstr(ptext+j,"Z")) 
					{
						data_coorswitch.z=Gcode2d(ptext+j,"Z");
					}
					else 
					{
						data_coorswitch.z = 0;
					}
					if(strstr(ptext,"B")) 
					{
						data_coorswitch.b=Gcode2d(ptext,"B");
					}
					else 
					{
						data_coorswitch.b = 0;
					}
					if(strstr(ptext+j,"C")) 
					{
						data_coorswitch.c=Gcode2d(ptext+j,"C");
					}
					else 
					{
						data_coorswitch.c = 0;
					}

					if(strstr(ptext+j,"G54:"))
					{
						G54_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G55:"))
					{
						G55_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G56:"))
					{
						G56_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G57:"))
					{
						G57_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G58:"))
					{
						G58_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G59:"))
					{
						G59_coordinate = data_coorswitch;

					}
					if(strstr(ptext+j,"G92:"))
					{
						data_w = data_coorswitch;
						data_r.x = data_m.x - data_w.x;
						data_r.y = data_m.y - data_w.y;
						data_r.z = data_m.z - data_w.z;
						data_r.b = data_m.b - data_w.b;
						data_r.c = data_m.c - data_w.c;



					}
					j = k;
					readbuffer_to_fc(pData->hWnd);
					fc_upday(hWndCoor);
			}while(reallength !=0);
			




			SuspendThread(MdihThread);
			//开设译码绘图内存
			pDataNcGraphMem = (LPNCDATA)HeapAlloc(GetProcessHeap(),
											HEAP_ZERO_MEMORY,
											MAX_NC_MEM*sizeof(nc_data)
											);
			if(pDataNcGraphMem == NULL)
			{
				MessageBox(pData->hWnd,"can not alloc heapmemory in function MdiMachiningBuildThreadProc",NULL,NULL);
				return 1;
			}

			//开设NC代码内存
			lpNcCodeMem = (LPNCCODE)HeapAlloc(GetProcessHeap(),
											HEAP_ZERO_MEMORY,
											MAX_NC_MEM*sizeof(nc_code)
											);
			if(pDataNcGraphMem == NULL)
			{
				MessageBox(pData->hWnd,"can not alloc heapmemory in function AutoMachiningBuildThreadProc",NULL,NULL);
				return 1;
			}

			
			 //为读取文件到内存打开文件
			fdEdit = _open(szBuffer, O_RDONLY);
		 
			if (fdEdit <= 0) 
			{		                        
				MessageBox (pData->hWnd, "can not open file in AutoMachiningBuildThreadProc","Program", MB_OK | MB_ICONSTOP);
				return 1;
			}

			ReadNcCodeFileToMem(pData->hWnd,fdEdit,lpNcCodeMem,&NcCodeNum);
			_close(fdEdit);


			//打开译码文件
			fdEdit = _open("MdiTemp.txt", O_RDONLY);
		 
			if (fdEdit <= 0)
			{		                        
				MessageBox (pData->hWnd, "can not open file in MdiMachiningBuildThreadProc","Program", MB_OK | MB_ICONSTOP);
				return 1;
			}
			ReadNcCodeFileToMem(pData->hWnd,fdEdit,lpNcCodeMem,&NcCodeNum);
			do{
					if(decode(pData->hWnd,lpNcCodeMem,decodeData,&decodeNum,&all_decode_num,&end_decode,MChild)==1) return 1; // 分段译码
				
					if(compensate(pData->hWnd,decodeData,decodeNum,compasateData,&compasateNum,&compasate_Start_point_X,&compasate_Start_point_Y, &compasate_build_c,compasate_cs)==1) return 1;//分段刀具补偿
				  
				  	
					if(tape(pData->hWnd,compasateData,compasateNum,tapeData,&tapeNum,&tape_Start_point_X,&tape_Start_point_Y,&tape_build_c,&first5152flag,tape_cs,&tape_Start_point_B,&tape_Start_point_C)==1,&tape_Start_point_B,&tape_Start_point_C) return 1; //锥面补偿
					if(DSP_Compute(pData->hWnd,tapeData,tapeNum,ComputeData,&ComputeNum)==1) return 1; 			
					
							
					CopyMemory(pDataNcGraphMem+all_creat_num,ComputeData,(ComputeNum*sizeof(nc_data)));
						
				

					memset(compasateData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));
					memset(tapeData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));
					memset(ComputeData,0,2*DECODE_NUM_ONCE*sizeof(nc_data));


					all_creat_num=all_creat_num + ComputeNum;
					ComputeNum = 0;
					compasateNum=0;
					tapeNum=0;
					
					//开设向下位机传送数据线程
					if(nc_start_flag==1)
					{
						pData_nc = (LPCmdThreadParam)HeapAlloc(GetProcessHeap(),
											HEAP_ZERO_MEMORY,
											sizeof(CmdThreadParam)
											);

						if(pData_nc == NULL)
						{
							MessageBox(pData->hWnd,"can not alloc heapmemory in function MdiMachiningBuildThreadProc",NULL,NULL);
							return 1;
						}


						pData_nc->hWnd = pData->hWnd;
						pData_nc->wndCtrl = pData->wndCtrl;
						pData_nc->menuID = pData->menuID;
						pData_nc->notifyCode =pData-> notifyCode;
						pData_nc->ncMem = pDataNcGraphMem;

						NcSendhThread = CreateThread(
								NULL,
								0,
								NcSendThreadProc,
								pData_nc,
								0,
								&dwThreadID
								);

						if( NcSendhThread==NULL)
						{
							MessageBox(pData->hWnd,"can not create Thread in function MdiMachiningBuildThreadProc",NULL,NULL);
							return 1;
						}

						SendNCDriverUserDecodeEvent(pData->hWnd,NcSendhThread);  //向驱动程序下传传送数据线程的句柄
						nc_start_flag = 0;
					}


			}while(end_decode != 1);

			_close(fdEdit);



			
			//find_draw_param(GetDlgItem (pData->hWnd, IDC_AUTOGRAPH),pDataNcGraphMem,&auto_draw_width,&auto_draw_length,&auto_mw, &auto_ml,all_creat_num);//求取画图参数
			

			//draw_all(GetDlgItem (pData->hWnd, IDC_AUTOGRAPH),pDataNcGraphMem,auto_draw_width,auto_draw_length,auto_mw, auto_ml,all_creat_num); //画全部图
			
					
			free(tape_cs);
		    free(compasate_cs);
	

	//取消线程、释放内存
	CloseHandle(MdihThread);
	if(HeapFree(GetProcessHeap(),HEAP_NO_SERIALIZE,pData) == 0){
		MessageBox(pData->hWnd,"can not free heapmemory in function MdiMachiningBuildThreadProc",NULL,NULL);
		return 1;
	}
	return 0;
}
Esempio n. 17
0
 /**
  * This method is invoked to perform atomic patching at a given location to
  * unconditionally jump to a given destination when the runtime assumption
  * is violated. Location and destination being used here have been passed in
  * during the class constructor.
  */
 virtual void compensate(TR_FrontEnd *vm, bool isSMP, void *) { compensate(isSMP, _location, _destination); }
Esempio n. 18
0
pair<string, double> in1klap::calculateResult(const vector<pair<int, string> >& expected, vector<pair<int, string> >& received, const vector<int>& beatvector, bool anyKey){

	int beaterrors=0;
	vector<int>::const_iterator beatIt;
	vector<int>::size_type beatvectorSize=beatvector.size();

	int a[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	vector<int> passfail(a, a + 32);
	vector<int>::iterator passfailIt;
	int position_of_previous_match=0;
	

	vector<pair<int, string> >::const_iterator expectedIt;
	vector<pair<int, string> >::size_type expectedSize=expected.size();
	vector<pair<int, string> >::iterator receivedIt;
	vector<pair<int, string> >::size_type receivedSize=received.size();
	string lastReceivedKeycode=" ";
	int lastReceivedEventPos;
	vector<string> r;
	
	//std::cout << "expectedSize=" << expectedSize << std::endl;
	//std::cout << "beatvector size=" << beatvectorSize << std::endl;

	vector<double> timingDeviations;
	int receivedEventsInWindowCount;
	pair<string, double> ret;

	// After each test a median timing offset should be calculated, and applied to all received events.
	compensate(received, expected);
	
	beatIt=beatvector.begin();
	int prevbeat=0;
	bool firstnoteinmeasure=true;
	int measurecount=0;
//	The system looks for the nearest received event (either in the past or future).
//	When found, the system checks whether the nearest event is nearer to a different expected event or not.
//	If not, the absolute timing difference between the expected and received events is stored in a vector.
//	If a different expected event was closer to the received event,
//	then the system ignores this expected event and skips to the next expected event.
	
	// for each expected note
	for(expectedIt=expected.begin();expectedIt!=expected.end();expectedIt++){

		r=getPosOfNearestReceived(expectedIt->first, received, expected); // get a match if possible
		bool match=(r[0]=="true");
		double matchpos=toFloat(r[1]);
		string matchkey=r[2];
		
		// check that the key matches, if necessary
		if(!anyKey){
			if(matchkey==expectedIt->second){
			} else{
				match=false;	
			}
		}
		   
		if(match){
			
			timingDeviations.push_back(fabs(matchpos-expectedIt->first));
			//std::cout<<"Match found in measure "<< ofToString(measurecount) << std::endl;
			// check if we have extra notes
			if(detectExtraNote(double(position_of_previous_match),matchpos, received)){
				//std::cout<<"Extra note found! "<< ofToString(measurecount) << std::endl;

				// there is an extra note,
				if(measurecount==0){
					// if this is the first measure, add the error to the current measure
					passfail[measurecount]=0;
				} else if(firstnoteinmeasure){
					// if the current expected not s the first on in this measure, add the error to the previous measure
					passfail[measurecount-1]=0;
				} else {
					// in normal cases add the error to the current measure
					passfail[measurecount]=0;
				}
			}
			position_of_previous_match=matchpos;
		} else {
			passfail[measurecount]=0;
		}
		
		prevbeat=*beatIt; // rotate the prevbeat variable
		beatIt++;
		
		// did we transition to the next quarter measure?
		if(*beatIt!=prevbeat){
			firstnoteinmeasure=true;
			measurecount++;
		} else {
			firstnoteinmeasure=false;			  
		}
	}
	
	// finally, check if there is a received event after the position of last match
	// if so, fail the last measure.
	if(double(received.back().first) > double(position_of_previous_match)){
		passfail.back()=0;
	}
	
//	for(passfailIt=passfail.begin();passfailIt!=passfail.end();passfailIt++){
//		std::cout<<"Passfail "<< ofToString(*passfailIt) << std::endl;
//	}
	
	//std::cout<<"timing deviations size="<<timingDeviations.size()<< std::endl;;
	vector<double>::iterator tIt;
	
	beaterrors=count(passfail.begin(), passfail.end(), 0);

	//double meanDeviation=std::accumulate(timingDeviations.begin(),timingDeviations.end(), 0.0)/timingDeviations.size();
	//std::cout<<"mean deviation="<<meanDeviation<< std::endl;
	string s=ofToString(32 - beaterrors)+"/32";
	ret.first=s;
	double meanDeviation=std::accumulate(timingDeviations.begin(),timingDeviations.end(), 0.0)/timingDeviations.size();
	ret.second=meanDeviation;
	return(ret);
}