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

📄 voytestdlg.cpp

📁 机器人UP-VoyagerII源码 基本功能
💻 CPP
字号:
// VoyTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VoyTest.h"
#include "VoyTestDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CVoyTestDlg dialog

CVoyTestDlg::CVoyTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVoyTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVoyTestDlg)
	m_nPort = 0;
	m_nUSonicTime = 0;
	m_nInfraRedTime = 0;
	m_nCmpsTime = 0;
	m_nStraightSpd = 0;
	m_nAngel = 0;
	m_nCircleSpd = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CVoyTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVoyTestDlg)
	DDX_Control(pDX, IDC_LIST1, m_cShowList);
	DDX_Text(pDX, IDC_PORT, m_nPort);
	DDX_Text(pDX, IDC_USONICTIME, m_nUSonicTime);
	DDX_Text(pDX, IDC_INFRAREDTIME, m_nInfraRedTime);
	DDX_Text(pDX, IDC_CMPSTIME, m_nCmpsTime);
	DDX_Text(pDX, IDC_StraightSpd, m_nStraightSpd);
	DDX_Text(pDX, IDC_Angel, m_nAngel);
	DDX_Text(pDX, IDC_CircleSpd, m_nCircleSpd);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVoyTestDlg, CDialog)
	//{{AFX_MSG_MAP(CVoyTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_FORWARD, OnForward)
	ON_BN_CLICKED(IDC_BACKWARD, OnBackward)
	ON_BN_CLICKED(IDC_TURNLEFT, OnTurnleft)
	ON_BN_CLICKED(IDC_TURNRIGHT, OnTurnright)
	ON_BN_CLICKED(IDC_BRAKE, OnBrake)
	ON_BN_CLICKED(IDC_Autousonic, OnAutousonic)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_Stopusonic, OnStopusonic)
	ON_BN_CLICKED(IDC_AutoInfrared, OnAutoInfrared)
	ON_BN_CLICKED(IDC_StopInfrared, OnStopInfrared)
	ON_BN_CLICKED(IDC_StartBeh, OnStartBeh)
	ON_BN_CLICKED(IDC_StopBeh, OnStopBeh)
	ON_BN_CLICKED(IDC_AUTOCMPS, OnAutocmps)
	ON_BN_CLICKED(IDC_STOPCMPS, OnStopcmps)
	ON_BN_CLICKED(IDC_Demarcate, OnDemarcate)
	ON_BN_CLICKED(IDC_Straight, OnStraight)
	ON_BN_CLICKED(IDC_Circle, OnCircle)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVoyTestDlg message handlers

BOOL CVoyTestDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVoyTestDlg::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 CVoyTestDlg::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
	{
		CDialog::OnPaint();
	}
}

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

void CVoyTestDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	//CString str;
	//str.Format("the port number is %d",m_nPort);
	//AfxMessageBox(str);
	m_Com.SetCmd(&m_Cmd);
	m_Com.Create(m_nPort);
}

void CVoyTestDlg::OnForward() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.SetBothMotorsSpeed(100,100);
}

void CVoyTestDlg::OnBackward() 
{
	// TODO: Add your control notification handler code here
		m_Cmd.SetBothMotorsSpeed(-100,-100);
}

void CVoyTestDlg::OnTurnleft() 
{
	// TODO: Add your control notification handler code here
		m_Cmd.SetBothMotorsSpeed(-100,100);
}

void CVoyTestDlg::OnTurnright() 
{
	// TODO: Add your control notification handler code here
		m_Cmd.SetBothMotorsSpeed(100,-100);
}

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

void CVoyTestDlg::OnAutousonic() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_Cmd.AutoQueryUSonic (m_nUSonicTime);
	SetTimer(0,m_nUSonicTime,NULL);
}

void CVoyTestDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CString strTemp;
	
	switch(nIDEvent)
	{
	case 0:
		strTemp.Format("%d",m_Cmd.ValUSonic[0]);
		m_cShowList.AddString(strTemp);
		break;
	case 1:
		strTemp.Format("%d",m_Cmd.ValInfrared[0]);
        m_cShowList.AddString(strTemp);
		break;
	case 2:
        strTemp.Format("%f",m_Cmd.m_angle);
        m_cShowList.AddString(strTemp);
		break;
	}

	CDialog::OnTimer(nIDEvent);
}

void CVoyTestDlg::OnStopusonic() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.AutoQueryUSonic(0);
	KillTimer(0);
}

void CVoyTestDlg::OnAutoInfrared() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_Cmd.AutoQueryInfraRed(m_nInfraRedTime);
	SetTimer(1,m_nInfraRedTime,NULL);
}

void CVoyTestDlg::OnStopInfrared() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.AutoQueryInfraRed(0);
	KillTimer(1);
}

void CVoyTestDlg::OnStartBeh() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.SetBehavior(&m_Demo);
}

void CVoyTestDlg::OnStopBeh() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.SetBehavior(NULL);
}

void CVoyTestDlg::OnAutocmps() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_Cmd.AutoQueryCompass(m_nCmpsTime);
	SetTimer(2,m_nCmpsTime,NULL);
}

void CVoyTestDlg::OnStopcmps() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.AutoQueryCompass(0);
	KillTimer(2);
}

void CVoyTestDlg::OnDemarcate() 
{
	// TODO: Add your control notification handler code here
	m_Cmd.Demarcate();
}

void CVoyTestDlg::OnStraight() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_Cmd.SpeedByGyro(m_nStraightSpd);
}

void CVoyTestDlg::OnCircle() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_Cmd.CircleByGyro(m_nAngel,m_nCircleSpd);
}

⌨️ 快捷键说明

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