📄 robotdlg.cpp
字号:
// RobotDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Robot.h"
#include "RobotDlg.h"
#include "glut.h"
#include "841M.h"
#include "OS.h"
#include "DRIVER.H"
#include "Tjuzhen.h"
#include "matlab.hpp"
#include "parameters.h"//曲线运动规划的关节数据
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int zhu=1,bao=1,fa=1,leng=1,dian=1;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CRobotDlg dialog
CRobotDlg::CRobotDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRobotDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRobotDlg)
m_xrot = 0;
m_yrot = 0;
m_zrot = 0;
m_firstangel = 0.0f;
m_fiveangel = 0.0f;
m_fourangel = 0.0f;
m_secondangel = 0.0f;
m_sixangel = 0.0f;
m_threeangel = 0.0f;
m_hand = FALSE;
m_tongxun = FALSE;
m_robotangel = 0.0f;
m_robotnumber = _T("");
m_RxID4 = 0;
m_RxID5 = 0;
m_rmsg0 = 0.0f;
m_rmsg1 = 0.0f;
m_rmsg2 = 0;
m_rmsg3 = 0;
m_rmsg4 = 0;
m_rmsg5 = 0;
m_rmsg51 = 0.0f;
m_rmsg52 = 0.0f;
m_rsmg53 = 0;
m_rsmg54 = 0;
m_rsmg55 = 0;
m_rsmg56 = 0;
m_v4 = 0.0f;
m_v5 = 0.0f;
m_r1 = 0.0f;
m_r2 = 0.0f;
m_r3 = 0.0f;
m_r4 = 0.0f;
m_r5 = 0.0f;
m_r6 = 0.0f;
m_positionX = 0.0f;
m_positionY = 0.0f;
m_positionZ = 0.0f;
m_P1 = 0;
m_control = 0;
m_seven = 0.0f;
m_x1ctrl = 0.0f;
m_x2ctrl = 0.0f;
m_x3ctrl = 0.0f;
m_plan = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRobotDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRobotDlg)
DDX_Control(pDX, ROBOT_NUMBER_COMBO, CComboBox);
DDX_Control(pDX, IDC_OPGLCTRL1, m_opengl);
DDX_Slider(pDX, IDC_SLIDER_X, m_xrot);
DDX_Slider(pDX, IDC_SLIDER_Y, m_yrot);
DDX_Slider(pDX, IDC_SLIDER_Z, m_zrot);
DDX_Text(pDX, FIRST_ANGEL_EDIT, m_firstangel);
DDX_Text(pDX, FIVE_ANGEL_EDIT, m_fiveangel);
DDX_Text(pDX, FOUR_ANGEL_EDIT, m_fourangel);
DDX_Text(pDX, SECOND_ANGEL_EDIT, m_secondangel);
DDX_Text(pDX, SIX_ANGEL_EDIT, m_sixangel);
DDX_Text(pDX, THREE_ANGEL_EDIT, m_threeangel);
DDX_Check(pDX, OPGL_DISPLAY_CHECK, m_hand);
DDX_Check(pDX, IDC_CHECK_TONGXUN, m_tongxun);
DDX_Text(pDX, ROBOT_ANGEL_EDIT, m_robotangel);
DDV_MinMaxFloat(pDX, m_robotangel, -105.f, 105.f);
DDX_CBString(pDX, ROBOT_NUMBER_COMBO, m_robotnumber);
DDX_Text(pDX, IDC_EDIT_RecID4, m_RxID4);
DDX_Text(pDX, IDC_EDIT_RecID5, m_RxID5);
DDX_Text(pDX, IDC_EDIT_RMSG0, m_rmsg0);
DDX_Text(pDX, IDC_EDIT_RMSG1, m_rmsg1);
DDX_Text(pDX, IDC_EDIT_RMSG2, m_rmsg2);
DDX_Text(pDX, IDC_EDIT_RMSG3, m_rmsg3);
DDX_Text(pDX, IDC_EDIT_RMSG4, m_rmsg4);
DDX_Text(pDX, IDC_EDIT_RMSG5, m_rmsg5);
DDX_Text(pDX, IDC_EDIT_Rmsg51, m_rmsg51);
DDX_Text(pDX, IDC_EDIT_Rmsg52, m_rmsg52);
DDX_Text(pDX, IDC_EDIT_Rmsg53, m_rsmg53);
DDX_Text(pDX, IDC_EDIT_Rmsg54, m_rsmg54);
DDX_Text(pDX, IDC_EDIT_Rmsg55, m_rsmg55);
DDX_Text(pDX, IDC_EDIT_Rmsg56, m_rsmg56);
DDX_Text(pDX, IDC_EDIT_V4, m_v4);
DDX_Text(pDX, IDC_EDIT_V5, m_v5);
DDX_Text(pDX, ZHENG_R1_EDIT, m_r1);
DDV_MinMaxFloat(pDX, m_r1, -60.f, 30.f);
DDX_Text(pDX, ZHENG_R2_EDIT, m_r2);
DDV_MinMaxFloat(pDX, m_r2, -50.f, 40.f);
DDX_Text(pDX, ZHENG_R3_EDIT, m_r3);
DDV_MinMaxFloat(pDX, m_r3, -50.f, 40.f);
DDX_Text(pDX, ZHENG_R4_EDIT, m_r4);
DDV_MinMaxFloat(pDX, m_r4, -105.f, 105.f);
DDX_Text(pDX, ZHENG_R5_EDIT, m_r5);
DDV_MinMaxFloat(pDX, m_r5, -105.f, 105.f);
DDX_Text(pDX, ZHENG_R6_EDIT, m_r6);
DDV_MinMaxFloat(pDX, m_r6, -140.f, 140.f);
DDX_Text(pDX, ZHENG_X_EDIT, m_positionX);
DDX_Text(pDX, ZHENG_Y_EDIT, m_positionY);
DDX_Text(pDX, ZHENG_Z_EDIT, m_positionZ);
DDX_Text(pDX, IDC_P1_EDIT, m_P1);
DDX_Text(pDX, IDC_CONTROL_EDIT, m_control);
DDX_Text(pDX, IDC_SEVEN_EDIT, m_seven);
DDX_Text(pDX, IDC_EDIT_X1ROT, m_x1ctrl);
DDX_Text(pDX, IDC_EDIT_X2ROT, m_x2ctrl);
DDX_Text(pDX, IDC_EDIT_X3ROT, m_x3ctrl);
DDX_CBString(pDX, IDC_COMBO_SELECTPLAN, m_plan);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRobotDlg, CDialog)
//{{AFX_MSG_MAP(CRobotDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(MENU_FILE_QUIT, OnFileQuit)
ON_BN_CLICKED(OPGL_UP_BUTTON, OnUpButton)
ON_BN_CLICKED(OPGL_DOWN_BUTTON, OnDownButton)
ON_BN_CLICKED(OPGL_FRONT_BUTTON, OnFrontButton)
ON_BN_CLICKED(OPGL_BACK_BUTTON, OnBackButton)
ON_BN_CLICKED(OPGL_LEFT_BUTTON, OnLeftButton)
ON_BN_CLICKED(OPGL_RIGHT_BUTTON, OnRightButton)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_X, OnReleasedcaptureSliderX)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_Y, OnReleasedcaptureSliderY)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_Z, OnReleasedcaptureSliderZ)
ON_NOTIFY(UDN_DELTAPOS, FIRST_SPIN, OnDeltaposSpinFirst)
ON_NOTIFY(UDN_DELTAPOS, FIVE_SPIN, OnDeltaposSpinFive)
ON_NOTIFY(UDN_DELTAPOS, FOUR_SPIN, OnDeltaposSpinFour)
ON_NOTIFY(UDN_DELTAPOS, SECOND_SPIN, OnDeltaposSpinSecond)
ON_NOTIFY(UDN_DELTAPOS, SIX_SPIN, OnDeltaposSpinSix)
ON_NOTIFY(UDN_DELTAPOS, THREE_SPIN, OnDeltaposSpinThree)
ON_BN_CLICKED(CAN_INIT_BUTTON, OnInitButton)
ON_BN_CLICKED(ROBOT_RESET_BUTTON, OnRobotResetButton)
ON_BN_CLICKED(ROBOT_DIRECT_BUTTON, OnDirectControlButton)
ON_WM_TIMER()
ON_BN_CLICKED(ROBOT_STOP_BUTTON, OnRobotStopButton)
ON_BN_CLICKED(ZHENG_COMPUTE_BUTTON, OnZhengComputeButton)
ON_BN_CLICKED(ZHENG_RESET_BUTTON, OnZhengResetButton)
ON_BN_CLICKED(ZHENG_RESULT_BUTTON, OnZhengResultButton)
ON_BN_CLICKED(ZHENG_GO_BUTTON, OnZhengGoButton)
ON_BN_CLICKED(IDC_ZHUBENG_BUTTON, OnZhubengButton)
ON_BN_CLICKED(IDC_FA_BUTTON, OnFaButton)
ON_BN_CLICKED(IDC_LENGQUE_BUTTON, OnLengqueButton)
ON_BN_CLICKED(IDC_POWER_BUTTON, OnPowerButton)
ON_BN_CLICKED(IDC_ERROR_BUTTON, OnErrorButton)
ON_BN_CLICKED(IDC_BUTTON_PLANRUN, OnButtonPlanrun)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRobotDlg message handlers
BOOL CRobotDlg::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
//CComboBox.SetCurSel(1);
//机器人系统参数初试化
m_upanddown=0;
m_behind=0;
m_leftandright=0;
one=0;
two=0;
three=0;
four=0;
five=0;
six=0;
m_xrot=0;
m_yrot=0;
m_zrot=0;
m_positionX=1796;
m_positionY=0;
m_positionZ=940;
Ttime=0;
start_time=0;
for(int i=0;i<451;i++)
yResult[i]=0;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRobotDlg::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 CRobotDlg::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();
}
int x_rot=520,y_rot=10;
int i;
CString str;
//double y;
// Creat a DC object
CClientDC dc(this);
// Creat a new pen
CPen MyNewPen;
MyNewPen.CreatePen(PS_SOLID,
1,
RGB(0,0,255));
// Select the new pen
CPen* pOriginalPen;
pOriginalPen=dc.SelectObject(&MyNewPen);
CRect MyRectangle(x_rot,
y_rot,
x_rot+500,//x轴方向长度为550个像素单位
y_rot+200);//y轴方向长度为300个像素单位
// Draw the Rectangle
dc.Rectangle(&MyRectangle);
//坐标轴标示
dc.TextOut(x_rot+240,y_rot+205,"t(ms)");
dc.TextOut(x_rot-10,y_rot+5,"y");
dc.TextOut(x_rot-10,y_rot+100,"0");
dc.MoveTo(x_rot,y_rot+100);
dc.LineTo(x_rot+500,y_rot+100);
//时间轴坐标标示
CPen MyNewPen1;
MyNewPen1.CreatePen(PS_SOLID,
1,
RGB(255,0,0));
pOriginalPen=dc.SelectObject(&MyNewPen1);
for(i=0;i<=50;i++)
{
if(i%5!=0)
{
dc.MoveTo(x_rot+i*10,y_rot+100);
dc.LineTo(x_rot+i*10,y_rot+95);
}
else
{
dc.MoveTo(x_rot+i*10,y_rot+100);
dc.LineTo(x_rot+i*10,y_rot+90);
}
}
//y轴坐标标示
for(i=0;i<=20;i++)
{
if(i%5!=0)
{
dc.MoveTo(x_rot,y_rot+i*10);
dc.LineTo(x_rot+5,y_rot+i*10);
}
else
{
dc.MoveTo(x_rot,y_rot+i*10);
dc.LineTo(x_rot+10,y_rot+i*10);
}
}
//Return the original pen
dc.SelectObject(pOriginalPen);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRobotDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRobotDlg::OnFileQuit()
{
// TODO: Add your command handler code here
OnOK();
}
BEGIN_EVENTSINK_MAP(CRobotDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CRobotDlg)
ON_EVENT(CRobotDlg, IDC_OPGLCTRL1, 2 /* InitOpenGL */, OnInitOpenGLOpgl, VTS_NONE)
ON_EVENT(CRobotDlg, IDC_OPGLCTRL1, 4 /* ReSize */, OnReSizeOpgl, VTS_I4 VTS_I4)
ON_EVENT(CRobotDlg, IDC_OPGLCTRL1, 5 /* ReDraw */, OnReDrawOpgl, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CRobotDlg::OnInitOpenGLOpgl()
{
// TODO: Add your control notification handler code here
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
glEnable(GL_DEPTH_TEST); // Hidden surface removal
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
//glBACKFace(GL_CCW);
glEnable(GL_CULL_FACE); // Do not calculate inside of jet
// Enable lighting
glEnable(GL_LIGHTING);
// Setup and enable light 0
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glEnable(GL_LIGHT0);
// Enable color tracking
glEnable(GL_COLOR_MATERIAL);
// Set Material properties to follow glColor values
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Light blue background
glClearColor(0.0f, 0.0f, 0.0f, 0.0f );
// Light values
// Bright white light
}
void CRobotDlg::OnReSizeOpgl(long cx, long cy)
{
// TODO: Add your control notification handler code here
glViewport(0,0,(GLsizei) cx,(GLsizei) cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65,(GLfloat) cx/(GLfloat) cy,1.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
}
void CRobotDlg::OnReDrawOpgl()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
UpdateData(true);
GLUquadricObj *qobj;
qobj=gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_FILL);
gluQuadricNormals(qobj,GLU_SMOOTH);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef((GLfloat)m_leftandright-0.5,(GLfloat)m_upanddown-0.5,(GLfloat)m_behind+0.7);
glRotatef(m_xrot, 1.0f, 0.0f, 0.0f);
glRotatef(m_yrot, 0.0f, 1.0f, 0.0f);
glRotatef(m_zrot, 0.0f, 0.0f, 1.0f);
glPushMatrix();
//glScalef(5.0,5.0,5.0);//
glTranslatef(2.0,0.0,0.0);//底座
glPushMatrix();//
glColor3f(0.75,0.75,0.75);
glTranslatef(0.0,-0.5,0.0);
glScalef(1.5,1.0,1.5);
glutSolidCube(1.0);
glPopMatrix();//
glRotatef(one,0.0,1.0,0.0);//一关节沿y轴
glTranslatef(0.0,0.0,0.0);
glPushMatrix();
glColor3f(1.0,0.2,1.0);
//glScalef(2.0,0.5,3.0);//底盘
//glutSolidCube(0.5);
glRotatef(90,1.0,0.0,0.0);
glTranslatef(0.0,0.0,-0.15);
gluCylinder(qobj,0.7,0.7,0.15,20,2);
glPopMatrix();
glTranslatef(0.0,-0.06,0.0);
glRotatef(two+90,0.0,0.0,1.0);//二关节沿z轴
glTranslatef(1.0,0.0,0.0);
glPushMatrix();
glColor3f(1.0,0.5,0.5);
glScalef(1.88,0.4,0.62);//第一根杆长度为940
glutSolidCube(1.0);
glPopMatrix();
//*****圆柱
glPushMatrix();
glTranslatef(0.94,0.0,-0.33);
glColor3f(1.0,0.0,0.0);
glPushMatrix();
glRotatef(180,0.0,1.0,0.0);
gluDisk(qobj,0,0.21,20,2);
glPopMatrix();
//glColor3f(1.0,0.5,0.0);
gluCylinder(qobj,0.21,0.21,0.66,20,2);
glTranslatef(0.0,0.0,+0.66);
//glColor3f(1.0,0.0,0.0);
gluDisk(qobj,0,0.21,20,2);
glPopMatrix();
//********
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -