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

📄 irexpplatformdlg.cpp

📁 机器人视觉处理程序
💻 CPP
字号:
// IRExpPlatformDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IRExpPlatform.h"
#include "IRExpPlatformDlg.h"

#include "TeleoperationDlg.h"
#include "WalkWhiteDlg.h"
#include "SearchObjectDlg.h"


#include "global.h"
#include "vfw.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIRExpPlatformDlg dialog

CIRExpPlatformDlg::CIRExpPlatformDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIRExpPlatformDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIRExpPlatformDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
}

void CIRExpPlatformDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIRExpPlatformDlg)
	DDX_Control(pDX, IDC_MSCOMMINWELCOMEDLG, m_ctrlComm);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIRExpPlatformDlg, CDialog)
	//{{AFX_MSG_MAP(CIRExpPlatformDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CLOSEWELCOMEDLG, OnClosewelcomedlg)
	ON_BN_CLICKED(IDC_EXP1, OnExp1)
	ON_BN_CLICKED(IDC_EXP2, OnExp2)
	ON_BN_CLICKED(IDC_EXP3, OnExp3)
	ON_BN_CLICKED(IDC_TOTALABOUT, OnTotalabout)
	ON_BN_CLICKED(IDC_TOTALHELP, OnTotalhelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIRExpPlatformDlg message handlers

BOOL CIRExpPlatformDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	//得到当前目录
	GetCurrentDirectory(_MAX_PATH, m_strCurDir.GetBuffer(_MAX_PATH));  
	m_strCurDir.ReleaseBuffer();
	m_strCurDir = m_strCurDir + "\\SoftWareHelp.chm";

	////////////////////////////////////////////////////////
	//初始化阈值调节各变量为相应值
	theApp.rWhiteMax	= 0.38;
	theApp.rWhiteMin	= 0.35;
	theApp.gWhiteMax	= 0.305;
	theApp.gWhiteMin	= 0.29;
	theApp.bWhiteMax	= 0.36;
	theApp.bWhiteMin	= 0.32;

	theApp.rRedMax		= 0.9;
	theApp.rRedMin		= 0.71;
	theApp.gRedMax		= 0.125;
	theApp.gRedMin		= 0.08;
	theApp.bRedMax		= 0.08;
	theApp.bRedMin		= 0.04;

	theApp.rBlueMax		= 0.095;
	theApp.rBlueMin		= 0.045;
	theApp.gBlueMax		= 0.303;
	theApp.gBlueMin		= 0.283;
	theApp.bBlueMax		= 0.66;
	theApp.bBlueMin		= 0.60;

	theApp.rYellowMax	= 0.67;
	theApp.rYellowMin	= 0.6;
	theApp.gYellowMax	= 0.355;
	theApp.gYellowMin	= 0.315;
	theApp.bYellowMax	= 0.02;
	theApp.bYellowMin	= 0;
	//////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////
	//初始化参数设置各变量
	theApp.nWhiteParm1			= 35;
	theApp.nWhiteParm2			= 80;
	theApp.nObjectParm1			= 45;
	theApp.nObjectParm2			= 10;
	theApp.nObstacleParm1		= 45;
	theApp.nObstacleParm2		= 10;
	theApp.nLineEdgeParm1		= 80;
	theApp.nLineEdgeparm2		= 15;
	theApp.nColumnEdgeParm1		= 30;
	theApp.nColumnEdgeParm2		= 50;
	theApp.nLeftRightEdgeParm1	= 30;
	theApp.nLeftRightEdgeParm2	= 25;
	/////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////	
	//以下用API函数CreateFile()打开串口目的仅在于检查串口是否已经被另一应用程序打开,
	//如果是,则弹出警告对话框提示用户,因为本程序要用到串口,
	//而串口是独占资源
	/*
	HANDLE m_hComm;
	int vReturned;
	m_hComm = CreateFile("COM1",		//打开串口1

	GENERIC_READ | GENERIC_WRITE,		//读写方式

	0,									//不能共享

	NULL,								//不用安全结构

	OPEN_EXISTING,						//打开已存在的设备
	
	FILE_FLAG_OVERLAPPED,				//异步方式

	0);									//无模板

	if(m_hComm == INVALID_HANDLE_VALUE) //串口打开失败
	{	
		vReturned = MessageBox("串口正在被另一应用程序所使用!你必须先关闭该应用程序才能运行本应用程序!",
								"打开串口错误!",
								MB_OK|MB_ICONWARNING);
		if(vReturned == IDOK)        
			exit(0);
	}
	else
		CloseHandle(m_hComm);			//如果串口打开成功,为了以后使用控件方式打开串口,先关闭串口
*/
	//选择com1
	m_ctrlComm.SetCommPort(1); 
	m_ctrlComm.SetInBufferSize(1024);
	m_ctrlComm.SetOutBufferSize(512);
	
	if(!m_ctrlComm.GetPortOpen())
		m_ctrlComm.SetPortOpen(TRUE);	//打开串口

    //波特率9600,无校验,8个数据位,1个停止位 
	m_ctrlComm.SetSettings("9600, n, 8, 1"); 

	//1:表示以二进制方式检取数据
	m_ctrlComm.SetInputMode(1); 

	//参数1表示每当串口接收缓冲区中有多于或
	//等于1个字符时将引发一个接收数据的OnComm事件
	m_ctrlComm.SetRThreshold(1); 
	
	m_ctrlComm.SetSThreshold(1);

	//设置当前接收区数据长度为0   读取所有数据
	m_ctrlComm.SetInputLen(0);	

	//先预读缓冲区以清除残留数据
	m_ctrlComm.GetInput();	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CIRExpPlatformDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CIRExpPlatformDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this);

	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CIRExpPlatformDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CIRExpPlatformDlg::OnClosewelcomedlg() 
{
	// TODO: Add your control notification handler code here

		StopCar();	
		//关闭串口
		if(m_ctrlComm.GetPortOpen()==TRUE)
			m_ctrlComm.SetPortOpen(FALSE);
		EndDialog(IDCANCEL);
	
}

void CIRExpPlatformDlg::OnExp1()
{
	// TODO: Add your control notification handler code here
	CTeleoperationDlg dlgTeleoperation;
	dlgTeleoperation.DoModal();
	
}

void CIRExpPlatformDlg::OnExp2() 
{
	// TODO: Add your control notification handler code here
	CWalkWhiteDlg dlgWalkWhite; 
	dlgWalkWhite.DoModal();
}


void CIRExpPlatformDlg::OnExp3() 
{
	// TODO: Add your control notification handler code here
	CSearchObjectDlg dlgSearchObject;
	dlgSearchObject.DoModal();	
}

void CIRExpPlatformDlg::OnTotalabout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}



void CIRExpPlatformDlg::OnTotalhelp() 
{
	// TODO: Add your control notification handler code here
	::HtmlHelp(NULL, m_strCurDir, HH_DISPLAY_TOPIC, 0);   //打开帮助文件
	
}

⌨️ 快捷键说明

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