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

📄 learnview.cpp

📁 机器人路径规划程序 机器人路径规划程序 机器人路径规划程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			R_s=-4.0*Pi/12.0;
			break;
		}

		if (((int)trd08==Bit_color))//&&((int)trd10==Bit_color))
		{
			ColorSignB=1;trd_numB=12;
			dis2=dis;
			R_s=4.0*Pi/12.0;
			break;
		}

		if (((int)trd09==Bit_color))//&&((int)trd11==Bit_color))
		{
			ColorSignB=1;trd_numB=5;
			dis2=dis;
			R_s=-5.0*Pi/12.0;
			break;
		}

		if (((int)trd10==Bit_color))//&&((int)trd12==Bit_color))
		{
			ColorSignB=1;trd_numB=13;
			dis2=dis;
			R_s=5.0*Pi/12.0;
			break;
 		}
		
		if (((int)trd11==Bit_color))//&&((int)trd13==Bit_color))
		{
			ColorSignB=1;trd_numB=6;
			dis2=dis;
			R_s=-6.0*Pi/12.0;
			break;
 		}

        if (((int)trd12==Bit_color))//&&((int)trd14==Bit_color))
		{
			ColorSignB=1;trd_numB=14;
			dis2=dis;
			R_s=6.0*Pi/12.0;
			break;
 		}
		if (((int)trd13==Bit_color))//&&((int)trd15==Bit_color))
		{
			ColorSignB=1;trd_numB=7;
			dis2=dis;
			R_s=-7.0*Pi/12.0;
			break;
 		}
/*
        if (ColorSignB==1||ColorSignR==1||ColorSignG==1)
		{
			break;
        }*/
	} 

  //               CString str_dis;
//				 str_dis.Format("trd_numB:%d",trd_numB);
 //				 dc.TextOut(300,10,str_dis);

				 if (dis2<=4.0)
                  {
//					  Action(0);
					 x1=x0;
					 y1=y0;
					 rwd=-2.0; 
                  }
                else if ((dis2<dmin)&&(dis2>4.0))
                {
					 rwd=-2.0;
							 
								 
                 } 
				 else if ((dis2>=dmin)&&(dis<=dmax))
				{
					rwd=1.0;//
//					StopTest();
					
				}
				else if (dis2>dmax)
				{
				    rwd=-0.5;//
//					StopTest();
				}

//				CString str00;
//				int size;
//				str00.Format("%f",Qvamax);
//				str_all=str_all+str00+'\n';
//				CFile myFile;
//				size=sizeof(str_all);
//				if (myFile.Open("Qva.txt",CFile::modeCreate|CFile::modeWrite))
//				{
//					myFile.Write(str_all,size);
//					myFile.Close();
// 				}

//				cDC.LineTo(flag_dis+5,Qvamax-10200);
				flag_dis=+5;

		  return trd_numB;

}

void CLearnView::OnSave()
{

 	CFile myfile;
 	CFileException e;
 	CString filename;
 	filename="Qnew.txt";
 	int size;
 	//str="098\n324";
 	//str_G_PWM="2000";
 	size=str.GetLength();
	if(myfile.Open(filename,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite,&e))
 	{
		for (int i=0;i<100;i++)
		{
//			size=str.GetLength();
		    str.Format("%f",Q[i]);
		    myfile.Write(str,size);
		}

 	}
 	myfile.Close();

}

void CLearnView::OnRead()
{

	CFile myfile;
// 	CFileException e;
 	CString filename;
 	filename="Qold.txt";
	char *pBuf;
	pBuf=new char[90];
 	pBuf[89]=0;
//
	if(myfile.Open(filename,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite))
 	{
		myfile.Read(pBuf,100);
	 }
 	myfile.Close();
 	MessageBox(pBuf);
}

void CLearnView::OnWall(int wall)
{


}

void CLearnView::Robot()
{
	CClientDC cDC(this);
  	    x=x1+buchang*cos(R_k);     //显示机器人当前运行位置与目标点连线方向与X轴的夹角角度R_k
	    y=y1+buchang*sin(R_k);

        x1=x;
	    y1=y;

        CPen RedPen(PS_SOLID,1,RGB(255,0,255));
        cDC.SelectObject(RedPen);
        cDC.Ellipse((int)x+3,(int)y+3,(int)x-3,(int)y-3);    ///机器人运行轨迹
//		cDC.MoveTo(x,y);
//		CDC.LineTo((int)(x+5.0*cos(R_k+0.0*Pi/12.0)),(int)(y+5.0*sin(R_k+0.0*Pi/12.0)));
//		CDC.LineTo(100,100);

}

void CLearnView::StopTest()
{

	KillTimer(10);
	AfxMessageBox("stoptest");
}

void CLearnView::OnMap1() 
{
	// TODO: Add your command handler code here

	
}

void CLearnView::OnSP() 
{
	// TODO: Add your command handler code here
	if (flag_Timer==0)
	{
		KillTimer(10);
		flag_Timer++;
	}
	else if (flag_Timer==1)
	{
		SetTimer(10,5,NULL);
		flag_Timer--;
	}
	
	
}



int CLearnView::Blzm(double all, double qf)
{
	int bl;
	bl=floor(1000*exp(qf/2.0)/all);
	return bl;

}

void CLearnView::OnButtonStart() 
{
	// TODO: Add your control notification handler code here
    //开始按钮,开启定时器,同时对各个控件的可用性进行定义
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	((CComboBox *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_COMBO_MAP)))->EnableWindow(FALSE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITX)))->EnableWindow(FALSE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITY)))->EnableWindow(FALSE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALX)))->EnableWindow(FALSE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALY)))->EnableWindow(FALSE);
	((CButton *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_BUTTON_LEFT)))->EnableWindow(FALSE);
	LeftEnable=false;
	RightEnable=false;
	StartEnable=false;
	PauseEnable=true;
	SetTimer(10,Robotvelocity,NULL);

//	((CButton *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_BUTTON_START)))->EnableWindow(false);
//	AfxMessageBox(str);
}


void CLearnView::OnButtonPause() 
{
	// TODO: Add your control notification handler code here
	//暂停按钮
    KillTimer(10);
	LeftEnable=false;
	RightEnable=false;
	StartEnable=true;
	PauseEnable=false;
}

void CLearnView::OnButtonLeft() 
{
	// TODO: Add your control notification handler code here
/*
	CClientDC dc(this);
	LPPOINT lpPoint1,lpPoint2;
	GetCursorPos(lpPoint1);
*/
	ydsign=1;  //给出绘制向左运动的障碍物的标志

}

void CLearnView::OnButtonRight() 
{
	// TODO: Add your control notification handler code here
	ydsign=2;    //给出绘制向右运动的障碍物的标志
}

void CLearnView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	if(ydsign==1)
	{
		ydGPoint1[ydGnum]=point;
		MouseDown=1;   //鼠标按下的标志
		ydGPoint2[ydGnum].x=point.x;
		ydGPoint2[ydGnum].y=point.y;
	}
	else if (ydsign==2)
	{
		ydRPoint1[ydRnum]=point;
		MouseDown=1;
		ydRPoint2[ydRnum].x=point.x;
		ydRPoint2[ydRnum].y=point.y;
	}

/*
	CClientDC dc(this);
        COLORREF  trd00;
		trd00=dc.GetPixel(point.x,point.y);
		CString str;
		str.Format("%d",trd00);
		AfxMessageBox(str);
*/

	CView::OnLButtonDown(nFlags, point);
	
}
void CLearnView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
   
	CClientDC dc(this);
	CBrush GreenBrush(RGB(0,255,0)),RedBrush(RGB(255,0,0)),WhiteBrush(RGB(255,255,255));
    if (MouseDown==1) 
	{
    	if(ydsign==1)
		{
			dc.SelectObject(GreenBrush);
			dc.Rectangle(ydGPoint1[ydGnum].x,ydGPoint1[ydGnum].y,point.x,point.y);
			ydGPoint2[ydGnum].x=point.x;
			ydGPoint2[ydGnum].y=point.y;
		}
	    else if (ydsign==2)
		{
			dc.SelectObject(RedBrush);
			dc.Rectangle(ydRPoint1[ydRnum].x,ydRPoint1[ydRnum].y,point.x,point.y);
			ydRPoint2[ydRnum].x=point.x;
			ydRPoint2[ydRnum].y=point.y;
		}

   }
	CView::OnMouseMove(nFlags, point);
}
void CLearnView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CBrush GreenBrush(RGB(0,255,0)),RedBrush(RGB(255,0,0));
	if(ydsign==1)
	{
		dc.SelectObject(GreenBrush);
		dc.Rectangle(ydGPoint1[ydGnum].x,ydGPoint1[ydGnum].y,point.x,point.y);
		ydGPoint2[ydGnum]=point;
		ydsign=3;
    	ydGnum++;
	    Invalidate();
	}
	if (ydsign==2)
	{
		dc.SelectObject(RedBrush);
		dc.Rectangle(ydRPoint1[ydRnum].x,ydRPoint1[ydRnum].y,point.x,point.y);
		ydRPoint2[ydRnum]=point;
		ydsign=4;
		ydRnum++;
	    Invalidate();
	}
	MouseDown=0;


	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	ydvelocity=fabs(((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_YDVELOCITY)))->GetPos()-100);
    if (ydsign==4) 
	{
		SetTimer(2,ydvelocity,NULL);
    }
	if (ydsign==3) 
	{   
		SetTimer(1,ydvelocity,NULL);
	}
	
	CView::OnLButtonUp(nFlags, point);
}


void CLearnView::OnReleasedcaptureSliderYdvelocity(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	//用滑块来控制运动障碍物的运动速度
	CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	ydvelocity=fabs(((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_YDVELOCITY)))->GetPos()-100);//改变速度
	if (ydsign==3||ydsign==4) 
	{   
    	KillTimer(1);
		SetTimer(1,ydvelocity,NULL);
    	KillTimer(2);
		SetTimer(2,ydvelocity,NULL);
    }
	
	*pResult = 0;
}

void CLearnView::OnReleasedcaptureSliderRobotvelocity(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	Robotvelocity=(fabs(((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_ROBOTVELOCITY)))->GetPos()-100))/4;
	if (!StartEnable)   //在按了开始按钮后此滑块才起作用
	{
		KillTimer(10);
		SetTimer(10,Robotvelocity,NULL);
	}

	*pResult = 0;
}

void CLearnView::OnSelchangeComboMap() 
{
	// TODO: Add your control notification handler code here
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	//地图的导入
	mapnum=((CComboBox *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_COMBO_MAP)))->GetCurSel();
	Invalidate();
}

void CLearnView::OnChangeEditInitx() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITX)))->GetWindowText(str);
	x0=atof(str);
    x1=x0;
	Invalidate();
	// TODO: Add your control notification handler code here
	
}

void CLearnView::OnChangeEditInity() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITY)))->GetWindowText(str);
	y0=atof(str);
	y1=y0;
	Invalidate();
	// TODO: Add your control notification handler code here
	
}

void CLearnView::OnChangeEditGoalx() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALX)))->GetWindowText(str);
	x2=atof(str);
	Invalidate();
	// TODO: Add your control notification handler code here
	
}

void CLearnView::OnChangeEditGoaly() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALY)))->GetWindowText(str);
	y2=atof(str);
	Invalidate();
	// TODO: Add your control notification handler code here
	
}

void CLearnView::OnButtonOk() 
{
	// TODO: Add your control notification handler code here

    //复位按钮
	//使所有数据还原
	int i=0,j=0,k=0;
	
	for (k=0;k<100;k++)
	{
		Q[k]=10;
	}

	for (i=0;i<17;i++)
	{
		for (j=0;j<6;j++)
		{
			Qsa[i][j]=10.0;
		}
	}
	
	Qvamax=0;
	qq=0;
	dis2=4.0;
	trd_numB=16;//状态标志
	flag_Timer=0;
	first=0;
	flag0=0;
	flag1=0;
	flag_dis=100;
	flag_num=0;
	num0=0;
 	bushu0=0;
	x=0.0;
	y=0.0;
	x0=20;//20.0;
	y0=50;//50.0;
	x1=x0;
	y1=y0;
	x2=800.0;
	y2=500;//500.0;
	di=12.0;                      //探测范围
	Pi=3.1415926;
	R_k=0.0;
//	R_z=atan((y2-y)/(x2-x));
	R_Angle=45;
	buchang=1.5;
	test1=0;
	test2=0;
	test3=0;
	Bit_color=16711680;
	MidValue=0.0;
	mapnum=0;
	ydsign=0;
	ydGnum=0;
	ydRnum=0;
	RedColor=255;
	GreenColor=65280;
	ColorSignB=0;
	ColorSignG=0;
	ColorSignR=0;
	LeftEnable=true;
	RightEnable=true;
	StartEnable=true;
	PauseEnable=false;

	for(i=0;i<50;i++)
	{
		ydGPoint1[i]=0;
		ydGPoint2[i]=0;
		ydRPoint1[i]=0;
		ydRPoint2[i]=0;
	}

	//对对话框进行初始化设置
	CString str;
    CMainFrame *pw=(CMainFrame *)AfxGetMainWnd(); 
	str.Format("%f",x0);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITX)))->SetWindowText(str);
	str.Format("%f",y0);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITY)))->SetWindowText(str);
	str.Format("%f",x2);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALX)))->SetWindowText(str);
	str.Format("%f",y2);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALY)))->SetWindowText(str);
	((CComboBox *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_COMBO_MAP)))->SetCurSel(0);

    //初始化运动障碍物的速度
	((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_YDVELOCITY)))->SetPos(50);
	ydvelocity=fabs(((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_YDVELOCITY)))->GetPos()-100);

	//初始化机器人的速度
	((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_ROBOTVELOCITY)))->SetPos(50);
	Robotvelocity=(fabs(((CSliderCtrl *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_SLIDER_ROBOTVELOCITY)))->GetPos()-100))/4;


	((CComboBox *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_COMBO_MAP)))->EnableWindow(TRUE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITX)))->EnableWindow(TRUE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_INITY)))->EnableWindow(TRUE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALX)))->EnableWindow(TRUE);
	((CEdit *)(pw->m_wndMyDialogBar.GetDlgItem(IDC_EDIT_GOALY)))->EnableWindow(TRUE);
	LeftEnable=true;
	RightEnable=true;
	StartEnable=true;
	PauseEnable=false;

	KillTimer(1);
	KillTimer(2);
	KillTimer(10);

	Invalidate();
}
void CLearnView::OnupdataLeftButton(CCmdUI   *pCmdUI)   
{  
	if (LeftEnable)
	{
		pCmdUI->Enable(TRUE);
	}
	else if (!LeftEnable) pCmdUI->Enable(FALSE);
}   
void CLearnView::OnupdataRightButton(CCmdUI   *pCmdUI)   
{  
	if (RightEnable)
	{
		pCmdUI->Enable(TRUE);
	}
	else if (!RightEnable) pCmdUI->Enable(FALSE);
}   
void CLearnView::OnupdataStartButton(CCmdUI   *pCmdUI)   
{  
	if (StartEnable)
	{
		pCmdUI->Enable(TRUE);
	}
	else if (!StartEnable) pCmdUI->Enable(FALSE);
}   
void CLearnView::OnupdataPauseButton(CCmdUI   *pCmdUI)   
{  
	if (PauseEnable)
	{
		pCmdUI->Enable(TRUE);
	}
	else if (!PauseEnable) pCmdUI->Enable(FALSE);
}   

⌨️ 快捷键说明

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