?? sdudemodlg.cpp
字號:
if(StateMessage&STATEID_MOD_FULLBUFFER)
{
//AfxMessageBox("STATEID_MOD_FULLBUFFER ");
pucState[i]="FBUR_"+pucState[i];
}
//#define STATEID_MOD_INPROGRESS 0x00010000L
if(StateMessage&STATEID_MOD_INPROGRESS )
{
//AfxMessageBox("STATEID_MOD_INPROGRESS ");
pucState[i]="INPR_"+pucState[i];
}
//#define STATEID_MOD_RAMP_END 0x00008000L
if(StateMessage&STATEID_MOD_RAMP_END )
{
//AfxMessageBox("STATEID_MOD_RAMP_END ");
pucState[i]="END_"+pucState[i];
}
//#define STATEID_MOD_RAMP_DEC 0x00004000L
if(StateMessage&STATEID_MOD_RAMP_DEC)
{
//AfxMessageBox("STATEID_MOD_RAMP_DEC ");
pucState[i]="DEC_"+pucState[i];
}
//#define STATEID_MOD_RAMP_STEADY 0x00002000L
if(StateMessage&STATEID_MOD_RAMP_STEADY )
{
//AfxMessageBox("STATEID_MOD_RAMP_STEADY ");
pucState[i]="STEADY_"+pucState[i];
}
//#define STATEID_MOD_RAMP_ACC 0x00001000L
if(StateMessage&STATEID_MOD_RAMP_ACC )
{
//AfxMessageBox("STATEID_MOD_RAMP_ACC ");
pucState[i]="_ACC_"+pucState[i];
}
//#define STATEID_MOD_MOTION 0x00000800L
if(StateMessage&STATEID_MOD_MOTION )
{
//AfxMessageBox("STATEID_MOD_MOTION ");
pucState[i]="MOV_"+pucState[i];
}
//define STATEID_MOD_CURLIMIT 0x00000400L
if(StateMessage&STATEID_MOD_CURLIMIT)
{
//AfxMessageBox("STATEID_MOD_CURLIMIT ");
pucState[i]="CUR_"+pucState[i];
}
//#define STATEID_MOD_BRAKEACTIVE 0x00000200L
if(StateMessage&STATEID_MOD_BRAKEACTIVE)
{
//AfxMessageBox("STATEID_MOD_BRAKEACTIVE ");
pucState[i]="BRA_"+pucState[i];
}
//#define STATEID_MOD_SW2 0x00000100L
if(StateMessage&STATEID_MOD_SW2 )
{
//AfxMessageBox("STATEID_MOD_SW2 ");
pucState[i]="SW2_"+pucState[i];
}
//#define STATEID_MOD_SW1 0x00000080L
if(StateMessage&STATEID_MOD_SW1)
{
//AfxMessageBox("STATEID_MOD_SW1 ");
pucState[i]="SW1_"+pucState[i];
}
//#define STATEID_MOD_SWR 0x00000040L
if(StateMessage&STATEID_MOD_SWR)
{
//AfxMessageBox("STATEID_MOD_SWR ");
pucState[i]="SWR_"+pucState[i];
}
//#define STATEID_MOD_COMM_ERROR 0x00000020L
if(StateMessage&STATEID_MOD_COMM_ERROR)
{
//AfxMessageBox("STATEID_MOD_COMM_ERROR ");
pucState[i]="CERR_"+pucState[i];
}
//#define STATEID_MOD_TOW_ERROR 0x00000010L
if(StateMessage&STATEID_MOD_TOW_ERROR)
{
//AfxMessageBox("STATEID_MOD_TOW_ERROR ");
pucState[i]="TERR_"+pucState[i];
}
//#define STATEID_MOD_POWERFAULT 0x00000008L
if(StateMessage&STATEID_MOD_POWERFAULT)
{
//AfxMessageBox("STATEID_MOD_POWERFAULT ");
pucState[i]="POW_"+pucState[i];
}
//#define STATEID_MOD_HALT 0x00000004L
if(StateMessage&STATEID_MOD_HALT)
{
//AfxMessageBox("STATEID_MOD_HALT ");
pucState[i]="HLT_"+pucState[i];
}
//#define STATEID_MOD_HOME 0x00000002L
if(StateMessage&STATEID_MOD_HOME)
{
//AfxMessageBox("STATEID_MOD_HOME ");
pucState[i]="HOK_"+pucState[i];
}
//#define STATEID_MOD_ERROR 0x00000001L
if(StateMessage&STATEID_MOD_ERROR )
{
//AfxMessageBox("STATEID_MOD_ERROR ");
pucState[i]="ERR_"+pucState[i];
}
}
BOOL CSduDemoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
int index=-1;
int indexChange;
int indexCount;
int Idtemp;
unsigned long Valuetemp;
unsigned long Statetemp;
CString strtemp;
indexCount=m_ListSeq.GetItemCount();
index=m_ListSeq.GetNextItem(-1,LVNI_SELECTED);
if(pMsg->message == WM_KEYDOWN)
{
if(index!=-1)
{
switch((int)(pMsg->wParam))
{
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_UP:
indexChange=index-1;
if(indexChange<0)
{
return true;
}
bChange=true;
break;
case VK_DOWN:
indexChange=index+1;
if(indexChange>indexCount-1)
{
return true;
}
bChange=true;
break;
default:
break;
}
}
return TRUE;
}
else if(pMsg->message == WM_KEYUP)
{
switch((int)(pMsg->wParam))
{
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_UP:
indexChange=index-1;
if(indexChange<0)
{
return true;
}
bChange=true;
break;
case VK_DOWN:
indexChange=index+1;
if(indexChange>indexCount-1)
{
return true;
}
bChange=true;
break;
default:
break;
}
if(bChange)
{
Idtemp=LogicIdMap[index];
LogicIdMap[index]=LogicIdMap[indexChange];
LogicIdMap[indexChange]=Idtemp;
Valuetemp=LogicValue[index];
LogicValue[index]=LogicValue[indexChange];
LogicValue[indexChange]=Valuetemp;
Statetemp=puiState[index];
LogicState[index]=puiState[indexChange];
puiState[indexChange]=Statetemp;
strtemp.Format("%d",LogicIdMap[index]);
m_ListSeq.SetItemText(index,1,strtemp);
strtemp.Format("%d",LogicIdMap[indexChange]);
m_ListSeq.SetItemText(indexChange,1,strtemp);
strtemp.Format("%d",LogicValue[index]);
m_ListSeq.SetItemText(index,2,strtemp);
strtemp.Format("%d",LogicValue[indexChange]);
m_ListSeq.SetItemText(indexChange,2,strtemp);
ShowModuleState(LogicState[index],index);
ShowModuleState(puiState[indexChange],indexChange);
m_ListSeq.SetItemText(index,3,pucState[index]);
m_ListSeq.SetItemText(indexChange,3,pucState[indexChange]);
}
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CSduDemoDlg::GetState()
{
for(int i=0; i<numOfModules;i++)
{
PCube_getModuleState( DeviceID, LogicIdMap[i], &LogicState[i] );
ShowModuleState (LogicState[i],i);
m_ListSeq.SetItemText(i,3,pucState[i]);
}
}
void CSduDemoDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//GetState();
CDialog::OnTimer(nIDEvent);
}
void CSduDemoDlg::OnDestroy()
{
DestroySystem();
PCube_closeDevice(DeviceID);
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CSduDemoDlg::OnStart()
{
// TODO: Add your control notification handler code here
//m_pMotion->Start();
if(!TempState||numOfModules==0)
{
AfxMessageBox("Please Scan MRobot");
return;
}
//CheckPtr(m_pImageProcess,FALSE);
bStart=true;
m_pMotion->Init();
// speedLeft=-600;
// speedRight=-600;
SetDlgItemText(IDC_EDITINFO,"尋找目標");
GetDlgItem(IDC_START)->EnableWindow(FALSE);
}
BOOL CSduDemoDlg::InitEnv()
{
m_pRobot = CASRSystem::GetInstance();
IASRProcess* pProcess = NULL;
PROCESS_DESC proc_desc;
proc_desc.nType = SEQUENCE;
m_pRobot->CreateProcess(proc_desc,pProcess);
IASRDevice* pDevice = NULL;
m_pRobot->CreateDevice("MOTION",pDevice);
RequestInterface(pDevice,ASR_IID_MOTION,m_pMotion);
CheckPtr(m_pMotion,FALSE);
pDevice = NULL;
m_pRobot->CreateDevice("IMAGE_CAP_DS",pDevice);
pDevice->QueryInterface(ASR_IID_IMAGECAPTURE,(LPVOID*)&m_pImageCap);
//CheckPtr(m_pImageCap,FALSE);
m_pRobot->AddToProcess(pProcess,m_pImageCap);
CWnd* pWnd = (CWnd*)GetDlgItem(IDC_VIDEO);
m_pImageCap->BindGUIWnd(pWnd->GetSafeHwnd());
//m_pImageCap->BindIndex(0);
pDevice = NULL;
m_pRobot->CreateDevice("ASR_IMAGE_PROCESS",pDevice);
pDevice->QueryInterface(ASR_IID_IMAGE,(LPVOID*)&m_pImage);
CheckPtr(m_pImage,FALSE);
m_pRobot->AddToProcess(pProcess,m_pImage);
//CWnd* pWnd = (CWnd*)GetDlgItem(IDC_VIDEO);
//m_process.SetHWnd(pWnd->GetSafeHwnd());
IMAGEPROC_DESC ImageDesc;
ImageDesc.nHeight = 240;
ImageDesc.nWidth = 320;
m_pImage->SetParam(ImageDesc);
IASRStreamLocal* pStream = pDevice->GetLocalStream();
pStream->BindCommand(&m_BallComm);
RequestInterface(pDevice,ASR_IID_FOOTBALL,m_pImageProcess);
//bind command
/*m_pImageCap->Init();
m_pImageCap->Start();
m_pImageProcess->Init();
m_pImageProcess->Start();
*/
m_pRobot->Init();
m_pRobot->Run();
//m_pMotion->SetWorkPeriod(50);
//m_pMotion->SetCallback(CBallTraceCommand::CounterProc,(LONG)this);
return true;
}
void CSduDemoDlg::DestroySystem()
{
//end the motion
if(m_pMotion)
{
//m_pMotion->Stop(WHEEL_LEFT);
//m_pMotion->Stop(WHEEL_RIGHT);
m_pMotion->End();
}
//the interfaces don't use any more
ReleaseInterface(m_pMotion);
ReleaseInterface(m_pImageCap);
ReleaseInterface(m_pImage);
ReleaseInterface(m_pImageProcess);
//ReleaseInterface(pImage);
//destroy the robot instance
if(m_pRobot)
{
m_pRobot->DestroyInstance();
m_pRobot = NULL;
}
}
void CSduDemoDlg::OnInitasr()
{
// TODO: Add your control notification handler code here
if(!InitEnv())
{
PostQuitMessage(0);
return ;
}
/*m_iRefreshCount = 3;
CRect rect;
AfxGetApp()->m_pMainWnd->GetWindowRect(&rect);
rect.SetRect(rect.left-1,rect.top,rect.right-1,rect.bottom);
AfxGetApp()->m_pMainWnd->MoveWindow(rect);*/
//SetTimer(1,500,NULL);
GetDlgItem(IDC_START)->EnableWindow(TRUE);
GetDlgItem(IDC_INITASR)->EnableWindow(false);
}
void CSduDemoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_pRobot)
{
GetDlgItem(IDC_VIDEO)->Invalidate(FALSE);
}
}
IASRMotion* CSduDemoDlg::GetMotion()
{
return m_pMotion;
}
IASRFootball* CSduDemoDlg::GetImageProcess()
{
return m_pImageProcess;
}
IASRImage* CSduDemoDlg::GetImage()
{
return m_pImage;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -