📄 stewartwin_dlg.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
//#include <iostream.h>
//#include <afxsock.h>
#include "stdafx.h"
#include "stewartWin.h"
#include "stewartWin_Dlg.h"
#include "matrix.h"
#include "usTime.h"
#include "LINE.h"
#include "TriAgl.h"
#include "YuanClass.h"
#include "PetalClass.h"
#include "SwingClass.h"
#include "machine.h"
#include "DriverStatus.h"
#include "API.h"
#include "SysSetClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
LINE LineA; //声明LINE类 对象LineA;
TriAgl TriAglA;
YuanClass CircleA;
PetalClass Petal_oo;
SwingClass Swing_oo;
DriverStatus DriverStatusOO;
SysSetClass SysSetOO;
/////////////////////////////////////////////////////////////////////////////
//================全局变量==================//
double Legd[6][2000];
long Nt, i_disp;
unsigned char APIdata[256] ;
//double *APIdataP;
//FILE * RecodeFile;
int GoHomeFlage = 1;
int AtHomeFlage = 0; //不在家
int Direct[MOTOR_NUMBER]={-1,-1,-1,-1,-1,-1};
int BeiXi[MOTOR_NUMBER]={1015,819,1098,1196,671,1507}; //背隙, beixi, bx
//int BeiXi[MOTOR_NUMBER]={0,0,0,0,0,0};//背隙, beixi, bx // Duan X C, 10.20
int BuCangFlage[MOTOR_NUMBER]={0,0,0,0,0,0};
/////////////////////////////////////////////////////////////////////////////
mei::MeiObjects* meiObjectsExtern;//指向 meiObjects 用于在
//其他对话框中对meiObjects进行操作
CCStewartWinAppDlg* MypMainDlg;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
using namespace mei;
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()
/////////////////////////////////////////////////////////////////////////////
// CCStewartWinAppDlg dialog
CCStewartWinAppDlg::CCStewartWinAppDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCStewartWinAppDlg::IDD, pParent)
{
MPIControlType controlType;
MPIControlAddress controlAddress;
MypMainDlg = this;
//{{AFX_DATA_INIT(CCStewartWinAppDlg)
m_ActLeg1 = _T("");
m_ActLeg2 = _T("");
m_ActLeg3 = _T("");
m_ActLeg4 = _T("");
m_ActLeg5 = _T("");
m_ActLeg6 = _T("");
m_ActPitch = _T("");
m_ActPosX = _T("");
m_ActPosY = _T("");
m_ActPosZ = _T("");
m_ActRoll = _T("");
m_ActYaw = _T("");
m_CmdLeg1 = _T("");
m_CmdLeg2 = _T("");
m_CmdLeg3 = _T("");
m_CmdLeg4 = _T("");
m_CmdLeg5 = _T("");
m_CmdLeg6 = _T("");
m_CmdPitch = _T("");
m_CmdPosX = _T("");
m_CmdPosY = _T("");
m_CmdPosZ = _T("");
m_CmdRoll = _T("");
m_CmdYaw = _T("");
m_AmpEnable = FALSE;
m_MotionStatus1 = _T("");
m_MotionStatus2 = _T("");
m_MotionStatus3 = _T("");
m_MotionStatus4 = _T("");
m_MotionStatus5 = _T("");
m_MotionStatus6 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_FirmwareVer = _T("");
meiObjects = NULL;
// Use default motion controller parameters
controlType = MPIControlTypeDEFAULT;
controlAddress.number = 0;
try
{
// Create and initialize MEI objects
meiObjects = new MeiObjects(controlType,
&controlAddress,
MOTION_NUMBER,
//MOTION_NUMBER,
AXIS_NUMBER,
FILTER_NUMBER,
MOTOR_NUMBER,
//RECORDER_NUMBER,
CAPTURE_COUNT);
meiObjectsExtern = meiObjects;
// Set m_FirmwareVer to the current controllers' firmware version
MEIControlVersion controlVersion;
long mpiMsg;
char firmwareVersion[16];
char firmwareRevision[2] = "\0";
char firmwareSubRevision[16];
mpiMsg = meiControlVersionGet(meiObjects->MpiControl(), &controlVersion);
CheckMessage(mpiMsg);
itoa(controlVersion.xmp.firmware.version, firmwareVersion, 10);
itoa(controlVersion.xmp.firmware.subRevision, firmwareSubRevision, 10);
firmwareRevision[0] = controlVersion.xmp.firmware.revision;
CString firmwareVersionStr = CString(firmwareVersion) + CString(firmwareRevision) + CString(firmwareSubRevision);
m_FirmwareVer = firmwareVersionStr;
meiObjects->SysInit();
//=============================================================
// Change the LIMIT_HW_POS configuration //
meiObjects->limitConfigure( MOTOR_NUMBER, //电机的数目//
MPIEventTypeLIMIT_HW_POS, // +HW limit //
MPIActionE_STOP, // E-STOP on limit //
FALSE, // Active Lo //
FALSE, // Use velocity as a trigger qualifier //
EVENT_DURATION);
// Change the LIMIT_HW_POS configuration //
meiObjects->limitConfigure( MOTOR_NUMBER, //电机的数目//
MPIEventTypeLIMIT_HW_NEG, // -HW limit //
MPIActionE_STOP, // E-STOP on limit //
FALSE, // Active High //
FALSE, // Use velocity as a trigger qualifier //
EVENT_DURATION);
meiObjects->MotionSysInit();
// RecodeFile = fopen("RecodeData.dat","w");
//=============================================================
}
catch (MeiException& e)
{
// Handle MEI exceptions here
throw e;
}
catch (...)
{
// Handle unknown exceptions here
throw;
}
}
CCStewartWinAppDlg::~CCStewartWinAppDlg()
{
delete meiObjects;
delete MypMainDlg;
MypMainDlg=NULL;
}
void CCStewartWinAppDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCStewartWinAppDlg)
DDX_Text(pDX, IDC_FIRMWARE_VER, m_FirmwareVer);
DDV_MaxChars(pDX, m_FirmwareVer, 255);
DDX_Text(pDX, IDC_ActLeg1, m_ActLeg1);
DDX_Text(pDX, IDC_ActLeg2, m_ActLeg2);
DDX_Text(pDX, IDC_ActLeg3, m_ActLeg3);
DDX_Text(pDX, IDC_ActLeg4, m_ActLeg4);
DDX_Text(pDX, IDC_ActLeg5, m_ActLeg5);
DDX_Text(pDX, IDC_ActLeg6, m_ActLeg6);
DDX_Text(pDX, IDC_ActPitch, m_ActPitch);
DDX_Text(pDX, IDC_ActPosX, m_ActPosX);
DDX_Text(pDX, IDC_ActPosY, m_ActPosY);
DDX_Text(pDX, IDC_ActPosZ, m_ActPosZ);
DDX_Text(pDX, IDC_ActRoll, m_ActRoll);
DDX_Text(pDX, IDC_ActYaw, m_ActYaw);
DDX_Text(pDX, IDC_CmdLeg1, m_CmdLeg1);
DDX_Text(pDX, IDC_CmdLeg2, m_CmdLeg2);
DDX_Text(pDX, IDC_CmdLeg3, m_CmdLeg3);
DDX_Text(pDX, IDC_CmdLeg4, m_CmdLeg4);
DDX_Text(pDX, IDC_CmdLeg5, m_CmdLeg5);
DDX_Text(pDX, IDC_CmdLeg6, m_CmdLeg6);
DDX_Text(pDX, IDC_CmdPitch, m_CmdPitch);
DDX_Text(pDX, IDC_CmdPosX, m_CmdPosX);
DDX_Text(pDX, IDC_CmdPosY, m_CmdPosY);
DDX_Text(pDX, IDC_CmdPosZ, m_CmdPosZ);
DDX_Text(pDX, IDC_CmdRoll, m_CmdRoll);
DDX_Text(pDX, IDC_CmdYaw, m_CmdYaw);
DDX_Check(pDX, IDC_AmpEnable, m_AmpEnable);
DDX_Text(pDX, IDC_MotionStatus1, m_MotionStatus1);
DDX_Text(pDX, IDC_MotionStatus2, m_MotionStatus2);
DDX_Text(pDX, IDC_MotionStatus3, m_MotionStatus3);
DDX_Text(pDX, IDC_MotionStatus4, m_MotionStatus4);
DDX_Text(pDX, IDC_MotionStatus5, m_MotionStatus5);
DDX_Text(pDX, IDC_MotionStatus6, m_MotionStatus6);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCStewartWinAppDlg, CDialog)
//{{AFX_MSG_MAP(CCStewartWinAppDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO1, OnSelectLine)
ON_BN_CLICKED(IDC_Run, OnRun)
ON_BN_CLICKED(IDC_Exit, OnExit)
ON_BN_CLICKED(IDC_RADIO2, OnSelectRadio)
ON_BN_CLICKED(IDC_Recoder, OnRecoder)
ON_BN_CLICKED(IDC_BUTTON1, OnReadIO)
ON_BN_CLICKED(IDC_BUTTON2, OnAPI)
ON_BN_CLICKED(IDC_RADIO4, OnTriAgl)
ON_BN_CLICKED(IDC_RADIO5, OnSwing)
ON_BN_CLICKED(IDC_Petal, OnPetal)
ON_BN_CLICKED(IDC_oo, OnGoHome)
ON_BN_CLICKED(IDC_SysSet, OnSysSet)
ON_BN_CLICKED(IDC_AmpEnable, OnAmpEnable)
ON_BN_CLICKED(IDC_ClearError, OnClearError)
ON_BN_CLICKED(IDC_ClearEncoder, OnClearEncoder)
ON_BN_CLICKED(IDC_AmpEnable, OnAmpEnable)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCStewartWinAppDlg message handlers
BOOL CCStewartWinAppDlg::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
SetTimer(102,1000,NULL);
DisplyMotionStatus();
UpdateData(false);
// 网络初始化
//
return TRUE; // return TRUE unless you set the focus to a control
}
void CCStewartWinAppDlg::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 CCStewartWinAppDlg::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 CCStewartWinAppDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCStewartWinAppDlg::OnSelectLine()
{
LineA.DoModal();
//UpdateData(true); // 输入数据的更新
PToPTrace();
}
void CCStewartWinAppDlg::OnSelectRadio()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -