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

📄 up_balltrackdlg.cpp

📁 足球机器人功能demo
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	// TODO: Add your control notification handler code hereif (m_pCap)
	if (m_pAheadCap != NULL)	
	{
		m_pAheadCap->Stop();
		delete m_pAheadCap;
		m_pAheadCap = NULL;
	}
	m_pAheadCap = new CCaptureVideo();
	m_pAheadCap->mCB.m_nPosID = AHEAD;
	m_pAheadCap->Create(m_cAheadCombo.GetCurSel(),&m_cAheadView,0);
	m_pAheadCap->SetCmd(&m_cmd);

	//使能桌面控件
	GetDlgItem(IDC_OPENAHEAD)->EnableWindow(false);
	GetDlgItem(IDC_CLOSEAHEAD)->EnableWindow(true);
	GetDlgItem(IDC_AHEADCATCH)->EnableWindow(true);
	GetDlgItem(IDC_AHEADFIND)->EnableWindow(true);
	GetDlgItem(IDC_SETOVERLOOKPARAM)->SetFocus();
}

void CUP_BALLTRACKDlg::OnCloseahead() 
{
	// TODO: Add your control notification handler code here
	OnClearshow() ;
	Sleep(300);

	if (m_pAheadCap != NULL)
	{
		m_pAheadCap->Stop();
		delete m_pAheadCap;
		m_pAheadCap = NULL;
	}

	GetDlgItem(IDC_OPENAHEAD)->EnableWindow(true);
	GetDlgItem(IDC_CLOSEAHEAD)->EnableWindow(false);
	GetDlgItem(IDC_AHEADCATCH)->EnableWindow(false);
	GetDlgItem(IDC_AHEADFIND)->EnableWindow(false);
}

void CUP_BALLTRACKDlg::OnYenable() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CUP_BALLTRACKDlg::OnUenable() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CUP_BALLTRACKDlg::OnVenable() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CUP_BALLTRACKDlg::ColorRecord()
{
	if(m_firstClr == true)
	{
		m_Ymin = m_Ymax = Y;
		m_Umin = m_Umax = U;
		m_Vmin = m_Vmax = V;
		m_firstClr = false;
		return;
	}

	if (Y > m_Ymax)
	{
		m_Ymax = Y;
	}
	if (Y < m_Ymin)
	{
		m_Ymin = Y;
	}

	if (U > m_Umax)
	{
		m_Umax = U;
	}
	if (U < m_Umin)
	{
		m_Umin = U;
	}

	if (V > m_Vmax)
	{
		m_Vmax = V;
	}
	if (V < m_Vmin)
	{
		m_Vmin = V;
	}
	UpdateData(false);
}

void CUP_BALLTRACKDlg::OnForward() 
{
	// TODO: Add your control notification handler code here
	m_cmd.SetBothMotorsSpeed(m_iBothSpeed,m_iBothSpeed);
}

void CUP_BALLTRACKDlg::OnBackward() 
{
	// TODO: Add your control notification handler code here
	m_cmd.SetBothMotorsSpeed(-m_iBothSpeed,-m_iBothSpeed);
}

void CUP_BALLTRACKDlg::OnTurnleft() 
{
	// TODO: Add your control notification handler code here
	m_cmd.SetBothMotorsSpeed(-m_iBothSpeed,m_iBothSpeed);
	
}

void CUP_BALLTRACKDlg::OnTurnright() 
{
	// TODO: Add your control notification handler code here
	m_cmd.SetBothMotorsSpeed(m_iBothSpeed,-m_iBothSpeed);
	
}

void CUP_BALLTRACKDlg::OnBrake() 
{
	// TODO: Add your control notification handler code here
	m_cmd.Brake(1);
}

void CUP_BALLTRACKDlg::OnSetspeed() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

BOOL CUP_BALLTRACKDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_KEYDOWN)	//判断是否为按键消息
	{
		
		switch (pMsg->wParam)		//根据虚拟键表值来判断按下的是什么键
		{
		case VK_UP:			//按下向前键
				OnForward();
				break;

		case VK_DOWN:		//按下后退键
				OnBackward();
				break;

		case VK_LEFT:		//按下左转键
				OnTurnleft();
				break;

		case VK_RIGHT:		//按下右转键
				OnTurnright();
				break;

		case VK_CONTROL:	//按下ctrl
				m_bGetClr = true;
				break;

		case VK_SHIFT:
				OnRemovebeh();
				m_cmd.Brake(1);
				break;

		default:
			break;
		}
	}

	if (pMsg->message==WM_KEYUP)	//判断是否为键弹起消息
	{
		switch(pMsg->wParam)
		{
		case VK_UP:			//向前键
		case VK_DOWN:		//后退键
		case VK_LEFT:		//左转键
		case VK_RIGHT:		//右转键
		case VK_SHIFT:
			m_cmd.Brake(1);
			break;
		case VK_CONTROL:
			m_bGetClr = false;
			break;
		default:
			break;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CUP_BALLTRACKDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	CButton* ptemp = (CButton*) GetDlgItem(IDC_OPEN);

	if (m_ProgramState == 0)
	{	//处于关闭状态,则打开通讯
		UpdateData();

			m_com.SetCmd(&m_cmd);			//将指令协议对象于硬件通讯对象对接
			if (!m_com.Create(m_nPort))		//打开硬件通讯对象(串口)
			{
				AfxMessageBox("串口打开失败!");
				return;
			}
		ptemp->SetWindowText("关闭");

		(CWnd*)GetDlgItem(IDC_PORT)->EnableWindow(FALSE);
		(CWnd*)GetDlgItem(IDC_BAUDRATE)->EnableWindow(FALSE);
		m_ProgramState = 1;
	} 
	else
	{	//处于打开状态,则关闭通讯
		m_cmd.Brake(1);				//先停下机器人确保安全
		
			m_com.Close();			//关闭硬件通讯对象(串口)
		ptemp->SetWindowText("打开");

		(CWnd*)GetDlgItem(IDC_PORT)->EnableWindow(TRUE);
		(CWnd*)GetDlgItem(IDC_BAUDRATE)->EnableWindow(TRUE);
		m_ProgramState = 0;
	}
}

void CUP_BALLTRACKDlg::OnSetoverlookparam() 
{
	// TODO: Add your control notification handler code here
	//读取界面参数
	m_UpdateParam(&m_OverlookParam);

	//将读到的参数传递给行为
	m_overbeh.m_para = m_OverlookParam;
	m_Demo.m_para = m_OverlookParam;

	//用显示行为进行显示
	m_Demo.pos = OVERLOOK;
	m_Demo.m_BehShow = &m_cOverlookList;
	m_cmd.SetBehavior(&m_Demo);
	m_Demo.Active = TRUE;
}

void CUP_BALLTRACKDlg::OnSetaheadparam() 
{
	// TODO: Add your control notification handler code here
	//读取界面参数
	m_UpdateParam(&m_AheadParam);

	//将读到的参数传递给行为
	m_Demo.m_para = m_AheadParam;
	m_finding.m_para = m_AheadParam;
	m_catching.m_para = m_AheadParam;

	//用显示行为进行显示
	m_Demo.m_BehShow = &m_cAheadList;
	m_Demo.pos = AHEAD;
	m_cmd.SetBehavior(&m_Demo);
	m_Demo.Active = TRUE;
}

void CUP_BALLTRACKDlg::OnClearparam() 
{
	// TODO: Add your control notification handler code here
	m_Yenb = FALSE;
	m_Ymax = m_Ymin = 0;

	m_Uenb = FALSE;
	m_Umax = m_Umin = 0;

	m_Venb = FALSE;
	m_Vmax = m_Vmin = 0;

	m_firstClr = true;
	
	UpdateData(false);
}

void CUP_BALLTRACKDlg::m_UpdateParam(YUVParam *inParam)
{
	UpdateData();
	inParam->ReSet();

	inParam->Yen = m_Yenb;
	inParam->Ymax = m_Ymax;
	inParam->Ymin = m_Ymin;

	inParam->Uen = m_Uenb;
	inParam->Umax = m_Umax;
	inParam->Umin = m_Umin;

	inParam->Ven = m_Venb;
	inParam->Vmax = m_Vmax;
	inParam->Vmin = m_Vmin;
}

void CUP_BALLTRACKDlg::OnAheadcatch() 
{
	// TODO: Add your control notification handler code here
	m_catching.m_BehShow = &m_cBehList;
	m_cmd.SetBehavior(&m_catching);
}

void CUP_BALLTRACKDlg::OnOverlookcatch() 
{
	// TODO: Add your control notification handler code here
	m_overbeh.m_BehShow = &m_cBehList;
	m_cmd.SetBehavior(&m_overbeh);
}

void CUP_BALLTRACKDlg::OnRemovebeh() 
{
	// TODO: Add your control notification handler code here
	m_cmd.SetBehavior(&m_idle);
}

void CUP_BALLTRACKDlg::OnClearshow() 
{
	// TODO: Add your control notification handler code here
	m_Demo.Active = FALSE;
	m_cmd.SetBehavior(&m_idle);
}

void CUP_BALLTRACKDlg::OnAheadfind() 
{
	// TODO: Add your control notification handler code here	
	m_finding.m_BehShow = &m_cBehList;
	m_cmd.SetBehavior(&m_finding);
}

⌨️ 快捷键说明

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