⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debugdlg.cpp

📁 本程序是2005年参加中国机器人大赛的比赛程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DebugDlg.cpp : implementation file

#include "stdafx.h"
#include "Robocup.h"
#include "DebugDlg.h"
#include "configdlg.h"
#include "videodlg.h"
#include "DecisionThread.h"
#include "ControlDlg.h"
#include "robocupdoc.h"
#include "Robocupview.h"
#include "Decision.h"
#include "InfoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDebugDlg dialog
CDebugDlg *CDebugDlg::m_pDebugDlg=NULL;
//FILE *Player::pFile1=NULL;
CDebugDlg::CDebugDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDebugDlg::IDD, pParent)         
{
//	Player::pFile=fopen("log.txt","a+");
//	Player::pFile1=fopen("log1.txt","a+");
//	Player::InitDiffMatrix();
	//{{AFX_DATA_INIT(CDebugDlg)
	m_n = 0;
	m_vl = 255;
	m_vr = 255;
	m_Num = 1;
	m_LeftForword = 0x7f ; 
	m_RightForword = 0x7f ;
	m_pInfoDlg = NULL ;
	m_pControlDlg = NULL ;
	//}}AFX_DATA_INIT
}


void CDebugDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDebugDlg)
	DDX_Text(pDX, IDC_N, m_n);
	DDX_Text(pDX, IDC_VL, m_vl);
	DDV_MinMaxInt(pDX, m_vl, -256, 256);
	DDX_Text(pDX, IDC_VR, m_vr);
	DDV_MinMaxInt(pDX, m_vr, -256, 256);
	DDX_Text(pDX, IDC_N2, m_Num);
	DDV_MinMaxInt(pDX, m_Num, 1, 5);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDebugDlg, CDialog)
	//{{AFX_MSG_MAP(CDebugDlg)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_SIMPLEACT, OnSimpleact)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_START2, OnStart2)
	ON_BN_CLICKED(IDC_STOP3, OnTry)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_BUTTON1, OnTurnAndMoveTest)
	ON_BN_CLICKED(IDC_TURN_TO, OnTurnTo)
	ON_BN_CLICKED(IDC_TURN_TEST, OnTurnTest)
	ON_BN_CLICKED(IDC_BOTELV, OnBotelv)
	ON_BN_CLICKED(IDC_BOTELV2, OnBotelv2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDebugDlg message handlers

int CDebugDlg::DoModal() 
{
	// TODO: Add your specialized code here and/or call the base class
	

	m_pDebugDlg=this;
	return CDialog::DoModal();
}
/*
void CDebugDlg::OnScan() 
{
	// TODO: Add your control notification handler code here
	
//	m_pVideoDlg=(CVideoDlg*)CDialog::GetDlgItem(IDD_VIDEO_DIALOG);	
	
	FILE* pFile=fopen("velocity.txt","a+");
	int k=m_team*5+m_number-1;
//	fprintf(pFile,"g_MyTeam[%d]=(%f,%f),Angle=%f\n",k,g_MyTeam[k].Get_vPos().x,g_MyTeam[k].Get_vPos().y,g_MyTeam[k].Get_m_Angle());
	m_jiajiao=g_MyTeam[k].Get_m_Angle()-m_angle;
	m_angle=g_MyTeam[k].Get_m_Angle()/m_times;

	fprintf(pFile,"VELO=%d,time=%u,m_angle=%4f\n",m_velocity,m_times,m_angle);
	fclose(pFile);

	UpdateData(0);
}
*/
extern unsigned long  timestart;
/*
void CDebugDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	FILE *pFile;
	pFile=fopen("log.txt","a+");
	if(nIDEvent==1)
	{
		static int count;
		count++;
		unsigned long t;
		t=GetTickCount()-timestart;
		fprintf(pFile,"\n\ncount=%d------time of vision start is %u",count,t);
		CVideoDlg::m_pVideoDlg->OnRead();
		CVideoDlg::m_pVideoDlg->SearchObject();	
		fprintf(pFile,"------time of vision last is %u------\n\n",GetTickCount()-t-timestart);

	}
	if(nIDEvent==2)
	{
		g_MyTeam[m_team*5+m_number-1].TurnTo4Debug(g_Ball.Get_vPos());
		g_MyTeam[m_team*5+m_number-1].BasicAct(0,FALSE,TRUE,0.8*MAX_VELOCITY);
	}
	fclose(pFile);
	CDialog::OnTimer(nIDEvent);
}
*/



void CDebugDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
//	KillTimer(2);
	g_MyTeam[5].BasicAct(0,0,0,0,10);
	g_MyTeam[1].BasicAct(0,0,0,0,10);
	g_MyTeam[2].BasicAct(0,0,0,0,10);
	g_MyTeam[3].BasicAct(0,0,0,0,10);
	g_MyTeam[4].BasicAct(0,0,0,0,10);

	//依次为1、2、3、4、5号
	Player::SendSingleCommand(0x2f,0x00,0x00);
	Player::SendSingleCommand(0x5f,0x00,0x00);
	Player::SendSingleCommand(0x7f,0x00,0x00);
	Player::SendSingleCommand(0x9f,0x00,0x00);
	Player::SendSingleCommand(0x1f,0x00,0x00);
//	CDebugDlg::m_pDebugDlg->m_StopFlag=FALSE;
}

/*
void CDebugDlg::OnTurnto() 
{
	// TODO: Add your control notification handler code here
	
}
/*
void CDebugDlg::OnOK()
{
	// TODO: Add extra validation here
	UpdateData(true);
//	Player::SendSingleCommand(0x3f,0x7f,0x7f);
/*	
	Player::SendSingleCommand(0x4c,0x7f,0xff);
	Player::SendSingleCommand(0x6c,0x7f,0xff);
	Player::SendSingleCommand(0x8c,0x7f,0xff);
	Player::SendSingleCommand(0x0c,0x7f,0xff);
*/
//	g_MyTeam[0].Set_vL(200);
//	g_MyTeam[0].Set_vR(200);
//	g_MyTeam[0].SendCommand(120);
//	g_MyTeam[0].BasicAct(0,0,0,200,0);

//	g_MyTeam[0].BasicAct(0,0,1,MAX_VELOCITY,50);

/*	
	FILE* pFile=fopen("velocity.txt","a+");
	fprintf(pFile,"g_MyTeam[%d]=(%f,%f),Angle=%f\n",m_team*5+m_number-1,g_MyTeam[m_team*5+m_number-1].Get_vPos().x,g_MyTeam[m_team*5+m_number-1].Get_vPos().y,g_MyTeam[m_team*5+m_number-1].Get_m_Angle());
	m_angle=g_MyTeam[m_team*5+m_number-1].Get_m_Angle();
	g_MyTeam[0].BasicAct(0,0,FALSE,m_velocity*MAX_VELOCITY/256,m_times);
*/

//	g_MyTeam[0].BasicAct(0,0,1,MAX_VELOCITY,50);
//	g_MyTeam[0].BasicAct(0,0,1,200,100);

//}

/*
UINT Thread_WriteProc(LPVOID param)
{
	CDebugDlg *dlg=(CDebugDlg*)param;
	WaitForSingleObject(dlg->handle2,INFINITE);

	{
	//	::MessageBox((HWND)param,"write proc","Thread Write Proc",MB_OK);
		
		fprintf(Player::pFile,"write proc\n");	
	}
	
	ResetEvent(dlg->handle2);
	Sleep(1000);
	SetEvent(dlg->handle1);
	return 0;
}


*/
/*
void CDebugDlg::OnCalcVelocity() 
{
	// TODO: Add your control notification handler code here
	UpdateData(1);
	FILE *pFile=fopen("velocity.txt","a+");
	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();	
	
	int k=m_team*5+m_number-1;
	m_dist=((g_MyTeam[k].Get_vPos())-Vector(m_xPos,m_yPos)).mod();

	m_xPos=g_MyTeam[k].Get_vPos().x;
	m_yPos=g_MyTeam[k].Get_vPos().y;


	m_velo=m_dist/m_times;

	fprintf(pFile,"VELO=%d,time=%u,m_velo=%4f\n",m_velocity,m_times,m_velo);
	fclose(pFile);
	UpdateData(0);
	

/*
	handle1=CreateEvent(0,TRUE,TRUE,NULL);
	handle2=CreateEvent(0,TRUE,FALSE,NULL);
	
	while(1)
	{
		MSG	lpMsg;
		PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE);
		if((GetKeyState(VK_ESCAPE) &0x80) == 0x80)
		break; 
		AfxBeginThread(Thread_WriteProc,(LPVOID)this);
		AfxBeginThread(Thread_ReadProc,(LPVOID)this);
	}*/
//}





void CDebugDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	KillTimer(1);
	KillTimer(2);
//	fclose(Player::pFile);
//	fclose(Player::pFile1);
	CDialog::OnCancel();
}
/*
void CDebugDlg::OnTurnangle2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();	
	
//	g_MyTeam[m_team*5+m_number-1].TurnAngle4Debug(g_Ball.Get_vPos());
//	g_MyTeam[0].TurnTo(g_Ball.Get_vPos());
//	g_MyTeam[1].TurnTo(g_Ball.Get_vPos());
	g_MyTeam[0].TurnTo(g_Ball.Get_vPos());
//	g_MyTeam[3].TurnTo(g_Ball.Get_vPos());
//	g_MyTeam[4].TurnTo(g_Ball.Get_vPos());
	return;
}
*/
extern	CDecisionThread* pDThread;
void CDebugDlg::OnStart() //从左往右攻
{
// TODO: Add your control notification handler code here
	pDThread->NewRound();
}

void CDebugDlg::OnStart2() //死循环试验
{
	// TODO: Add your control notification handler code here
//	DeciFlag=1;
//	pDThread2->NewRound2();
	FILE *pFile;	
	pFile=fopen("good.txt","w");
	int t1,t2;
		
	for(;;)
	{
		LPVOID pParam ; 
		t1=GetTickCount();
		CVideoDlg::m_pVideoDlg->OnRead();
		CVideoDlg::m_pVideoDlg->SearchObject();	
		t2 = GetTickCount();
		fprintf(pFile," \nVisual Proc Comsume time: %d \n", t2-t1);
		//VisualProc();
		DecisionProc2( pParam );
		t1=GetTickCount();
		fprintf(pFile," \nDecision Proc Comsume time: %d \n", t1-t2);

		MSG	lpMsg;
	    PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE);
//		if((GetKeyState(VK_ESCAPE) &0x80) == 0x80)break; 
		
		// MSG	lpMsg;
		PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE);//结束命令, 所有机器人全都停止
		if((GetKeyState(VK_RSHIFT) &0x80) == 0x80)
		{
			g_MyTeam[0].BasicAct(0,0,0,0);
			g_MyTeam[1].BasicAct(0,0,0,0);
			g_MyTeam[2].BasicAct(0,0,0,0);
			g_MyTeam[3].BasicAct(0,0,0,0);
			g_MyTeam[4].BasicAct(0,0,0,0);
		//	return 0;
			break; 
		}
	}
	fclose( pFile ) ;
}

/*
void CDebugDlg::OnMoveto() 
{
	// TODO: Add your control notification handler code here

	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();
	g_MyTeam[m_team*5+m_number-1].MoveTo4Debug(g_Ball.Get_vPos());
}
*/
/*
void CDebugDlg::OnTry2() 
{

	UpdateData(1);
	
	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();	

	FILE* pFile=fopen("velocity.txt","a+");
	int k=m_team*5+m_number-1;
	fprintf(pFile,"g_MyTeam[%d]=(%f,%f),Angle=%f\n",k,g_MyTeam[k].Get_vPos().x,g_MyTeam[k].Get_vPos().y,g_MyTeam[k].Get_m_Angle());
	m_xPos=g_MyTeam[k].Get_vPos().x;
	m_yPos=g_MyTeam[k].Get_vPos().y;
	UpdateData(0);
	g_MyTeam[k].BasicAct(0,0,1,m_velocity*MAX_VELOCITY/256,m_times);

}
*/
/*
void CDebugDlg::OnShoot() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	MSG	lpMsg;
	for( int i = 0; i < 20; i++ )
	{
		
		PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE);
		
		if((GetKeyState(VK_SPACE) &0x80) == 0x80)
		{
			Player::SendSingleCommand(0x20,0x00,0x00);
			break;
		}
		CVideoDlg::m_pVideoDlg->OnRead();
		CVideoDlg::m_pVideoDlg->SearchObject();	
//	g_MyTeam[0].TurnTo(g_Ball.Get_vPos());
		g_MyTeam[0].MoveToNoOA(g_Ball.Get_vPos());
	}


//	CVideoDlg::m_pVideoDlg->OnRead();
//	CVideoDlg::m_pVideoDlg->SearchObject();
//	g_MyTeam[0].Shoot4Debug();
//	g_MyTeam[1].Shoot4Debug();
//	g_MyTeam[0].BasicAct(0,0,1,200);
//	g_MyTeam[3].Shoot4Debug();
//	g_MyTeam[4].Shoot4Debug();
//	g_MyTeam[m_team*5+m_number].Shoot4Debug();
//	g_MyTeam[m_team*5+m_number+1].Shoot4Debug();
}
*/
/*
void CDebugDlg::OnTrunangle() 
{
	// TODO: Add your control notification handler code here
	UpdateData(1);
	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();	
	g_MyTeam[m_team*5+m_number-1].TurnTo(g_Ball.Get_vPos(),1);
	g_MyTeam[m_team*5+m_number].TurnTo(g_Ball.Get_vPos(),1);
}
*/

void CDebugDlg::SetDebugDlg(CDebugDlg *pDlg)
{
	m_pDebugDlg=pDlg;
}


/*
void CDebugDlg::OnEditchangeMygoal() 
{
	// TODO: Add your control notification handler code here
	Player::My_Side=m_mygoal;
}
*/
/*
void CDebugDlg::OnBoundary() 
{
	// TODO: Add your control notification handler code here
	CVideoDlg::m_pVideoDlg->OnRead();
	CVideoDlg::m_pVideoDlg->SearchObject();
	g_MyTeam[m_team*5+m_number-1].BoundaryProc(CRect(200,100,200,100));
}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -