fstarcmd.cpp

来自「手柄驱动DEMO程序源码」· C++ 代码 · 共 2,455 行 · 第 1/4 页

CPP
2,455
字号
	{
		//PlaySound("LCD_error.wav",GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);//VIA自检
		Sleep(2000);
	}
	
	pCmd->demo_io_flag=SELFDETECT;
	pCmd->detect_flag=0x71;
	if (pCmd->bToEndDetect)
	{
		return 1L;
	}
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,0,(UCHAR)0x05,NULL);			//模块卡自检检查
	Sleep(5000);
	if (pCmd->detect_flag==0x71)
	{
		//PlaySound("multi_error.wav",GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);//VIA自检
		Sleep(2000);
	}
	
	
	//pCmd->demo_us_flag=USDETECTION;
	pCmd->detect_flag=0x53;
	if (pCmd->bToEndDetect)
	{
		return 1L;
	}
	pCmd->m_GenerateSendBuffer((UCHAR)0x53,0,0,(UCHAR)0x01,NULL);			//超声板自检
	pCmd->m_GenerateSendBuffer((UCHAR)0x53,0,0,(UCHAR)0x01,NULL);			//超声板自检
	Sleep(5000);
	if (pCmd->detect_flag==0x53)
	{
		//PlaySound("us_error.wav",GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);//VIA自检
	}
	return 0L;
}
UINT CFstarCmd::DanceThread(LPVOID pParam)
{
	CFstarCmd * pCmd=(CFstarCmd * )pParam;
	//PlaySound("taiji.wav",GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
	Sleep(1000);
	UCHAR action1[12]={0x5a,0x04,0x9D,0x5a,0x5a,0x94,0xa8,0x15,0x5a,0x5a,0x9d,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action1);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	
	Sleep(3000);
	UCHAR action2[12]={0x5a,106,136,0x5a,0x5a,0x8f,0x39,0x14,0x5a,0x5a,0x9b,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action2);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	pCmd->SetBothMotorsSpeed(1000,-1000);
	pCmd->LasorOn(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action3[12]={0x5a,0x4d,0x9d,0x5a,0x5a,0x96,0x66,0x14,0x5a,0x5a,0x99,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action3);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);
	pCmd->SetBothMotorsSpeed(-1000,1000);
	pCmd->TurnOnLgt(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action4[12]={0x8d,0x29,0x7f,0x77,0x94,0x97,0x52,0x1b,0x20,0x5a,0x9b,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action4);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	pCmd->SetBothMotorsSpeed(1000,-1000);
	pCmd->LasorOn(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action5[12]={0x52,0x6d,0x92,0x92,0x5a,0x97,0x72,0x1b,0x0b,0x5a,0x9b,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action5);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);
	pCmd->SetBothMotorsSpeed(-1000,1000);
	pCmd->TurnOnLgt(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action6[12]={0x24,0xb4,0x70,0x57,0x94,0x97,0x9d,0x19,0x3d,0x5a,0x9b,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action6);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);
	pCmd->SetBothMotorsSpeed(1000,-1000);
	pCmd->LasorOn(3);
	
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action7[12]={120,40,157,106,146,150,69,26,37,91,146,90};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action7);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);
	pCmd->SetBothMotorsSpeed(-1000,1000);
	pCmd->TurnOnLgt(3);
	
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action8[12]={80,98,159,136,146,150,120,56,56,67,148,90};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action8);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	pCmd->SetBothMotorsSpeed(1000,-1000);
	pCmd->LasorOn(3);
	
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action9[12]={90,122,137,142,122,140,62,33,29,27,150,90};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action9);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	pCmd->SetBothMotorsSpeed(-1000,1000);
	pCmd->TurnOnLgt(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action10[12]={90,30,137,142,122,140,144,33,29,27,150,90};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action10);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	pCmd->SetBothMotorsSpeed(1000,-1000);
	pCmd->LasorOn(3);
	
	Sleep(3000);
	pCmd->stop();
	UCHAR action12[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
	if (pCmd->bToEndDance)
	{
		//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
		return 1L;
	}
	pCmd->CopyArray(action12);
	pCmd->m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,pCmd->serveData);	
	Sleep(3000);
	pCmd->stop();
	pCmd->stop();
	return 0L;
}

void CFstarCmd::Furl()
{
	UCHAR action[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
	CopyArray(action);
	m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
	
}
UINT CFstarCmd::ActionDemo(LPVOID pParam)
{
	CFstarCmd * pCmd=(CFstarCmd * )pParam;
	switch(pCmd->demoIndex)
	{
	case 1:
		break;
	case 2:
		break;
	case 3:
		break;
	default:
		break;
	}
	return 0L;
}

void CFstarCmd::StartAction()
{
	//	AfxBeginThread(ActionDemo,(LPVOID)this,THREAD_PRIORITY_TIME_CRITICAL);
	//PlaySound("bkv.wav",GetModuleHandle(NULL),SND_FILENAME|SND_ASYNC);
	UCHAR i = 2;
	while (i--)
	{
		UCHAR action1[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action1);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			AfxMessageBox("");
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action2[12]={90,15,131,155,80,150,160,36,16,89,150,0x5a};
		CopyArray(action2);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action3[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action3);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action4[12]={90,15,131,155,80,150,160,36,16,89,150,0x5a};
		CopyArray(action4);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action5[12]={60,8,113,95,80,150,151,30,7,89,151,0x5a};//头左转
		CopyArray(action5);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		LasorOn(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		UCHAR action6[12]={120,8,154,155,5,150,142,48,91,89,151,0x5a};//tou youzhuan
		CopyArray(action6);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		LasorOn(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		UCHAR action7[12]={60,8,113,95,80,150,151,30,7,89,151,0x5a};
		CopyArray(action7);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		LasorOn(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action8[12]={120,8,154,155,5,150,142,48,91,89,151,0x5a};
		CopyArray(action8);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		LasorOff(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		SetBothMotorsSpeed(-1000,1000);
		TurnOnLgt(3);
		UCHAR action9[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action9);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		SetBothMotorsSpeed(1000,-1000);
		TurnOffLgt(3);
		LasorOn(3);
		UCHAR action10[12]={120,115,131,155,80,118,140,33,38,89,118,0x5a};
		CopyArray(action10);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		TurnOnLgt(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		SetBothMotorsSpeed(-1000,1000);
		TurnOffLgt(3);
		UCHAR action11[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action11);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		TurnOnLgt(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOn(3);
		SetBothMotorsSpeed(1000,-1000);
		TurnOffLgt(3);
		UCHAR action12[12]={120,115,131,155,80,118,140,33,38,89,118,0x5a};
		CopyArray(action12);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		TurnOnLgt(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		SetBothMotorsSpeed(-1000,1000);
		TurnOffLgt(3);
		UCHAR action13[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action13);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		TurnOnLgt(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		SetBothMotorsSpeed(1000,-1000);
		TurnOffLgt(3);
		UCHAR action14[12]={120,115,131,155,80,118,140,33,38,89,118,0x5a};
		CopyArray(action14);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		TurnOnLgt(3);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		//here
		Sleep(3000);
		stop();
		TurnOffLgt(3);
		UCHAR action15[12]={60,22,129,107,80,118,147,25,25,92,118,0x5a};
		CopyArray(action15);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action16[12]={90,15,131,155,80,150,160,36,16,89,150,0x5a};
		CopyArray(action16);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		UCHAR action17[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action17);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOn(3);
		UCHAR action18[12]={45,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action18);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		LasorOn(3);
		UCHAR action19[12]={135,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action19);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		SetBothMotorsSpeed(-1000,1000);
		LasorOn(3);
		UCHAR action20[12]={60,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action20);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		LasorOff(3);
		SetBothMotorsSpeed(1000,-1000);
		LasorOn(3);
		UCHAR action21[12]={120,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action19);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		TurnOnLgt(3);
		UCHAR action22[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
		CopyArray(action1);
		m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);
		TurnOffLgt(3);
		TurnOnLgt(3);	
		SetBothMotorsSpeed(1000,1000);
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		
		Sleep(3000);
		SetBothMotorsSpeed(-1000,-1000);
		TurnOffLgt(3);
		TurnOnLgt(3);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		Sleep(3000);
		SetBothMotorsSpeed(-1000,1000);
		TurnOffLgt(3);
		TurnOnLgt(3);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		Sleep(3000);
		SetBothMotorsSpeed(1000,-1000);
		TurnOffLgt(3);
		TurnOnLgt(3);	
		
		if (bAct1End)
		{
			EndAction();
			return;
		}
		Sleep(3000);
	}
			
	stop();
	LasorOff(3);
	TurnOffLgt(3);
}

void CFstarCmd::EndAction()
{
	//PlaySound(NULL,GetModuleHandle(NULL),SND_ASYNC|SND_FILENAME);
	UCHAR action1[12]={0x5a,115,131,155,80,118,62,36,16,89,118,0x5a};
	CopyArray(action1);
	m_GenerateSendBuffer((UCHAR)0x71,0,24,(UCHAR)0x01,serveData);	
	stop();
	LasorOff(3);
	TurnOffLgt(3);
}




    void CFstarCmd::goline(long distance,int speed)
{
    ULONG time;
	time=(ULONG)((distance*60*64)/(0.001*3.1415926*wheel_diameter*speed));
    SetBothMotorsSpeed(speed, speed);
    Sleep(time);
	Brake(1);
	//WORD lrspeed = m_CalculateSpeed(speed);
	//UCHAR bothspeed[4];	
	
	//bothspeed[0]=0;
	//bothspeed[1]=0;
	
	//bothspeed[2]=(UCHAR)((lrspeed >> 8) & 0x00ff);
	//bothspeed[3]=(UCHAR)(lrspeed & 0x00ff);	
	
	//m_GenerateSendBuffer((UCHAR)0x01,0,4,(UCHAR)0x2C,bothspeed);


	 //Sleep(300);
	 //Brake(1);
	}
    
	
	
	//void CFstarCmd::turn(int angle,int speed)
	//{
    //TurnByGyro(angle,speed);
	
	//}
    
	
	void CFstarCmd::goarc(UINT dir,int angle,long radius,int speed)  //dir=0左转,dir=1右转
	{
    int lspeed,rspeed,temp;
	ULONG time;
	lspeed=(int)(speed*(radius-wheel_distance/2)/radius);
    rspeed=(int)(speed*(radius+wheel_distance/2)/radius);
	if(dir)
	{
	temp=lspeed;
	lspeed=rspeed;
	rspeed=temp;
	}
    time=(ULONG)(1000*3.1415926*2*radius*angle/(360*(speed*3.1415926*wheel_diameter/(60*64))));
	 m_iLspeed = lspeed;
	 m_iRspeed = rspeed;
    SetBothMotorsSpeed(lspeed, rspeed);
	Sleep(time);
	Brake(1);
	}


    void CFstarCmd::lockdir(long distance,int speed)
{
    ULONG time;
	time=(ULONG)((distance*60*64)/(3.1415926*wheel_diameter*speed/1000));
    LockDirection(speed);
    Sleep(time);
	Brake(1);
}

⌨️ 快捷键说明

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