Пример #1
0
float Cylinder::contributionD(float angle, float k_angle) const
{
	float alpha = dFi(dFi(angle, getrT()), k_angle) * ISIGMAD;

	/*Area of the curve computation*/
	return doLeft(alpha + 0.5) - doLeft(alpha - 0.5);
}
Пример #2
0
void GameScene::onTouchEnded(Touch* touch, Event* event)
{
    Point pos = touch->getLocation();
    SimpleGestures rtn = recognizer->endPoint(pos);
    switch (rtn) {
        case SimpleGesturesLeft:
            doLeft();
            doCheck();
            setScore(score);
            break;
        case SimpleGesturesRight:
            doRight();
            doCheck();
            setScore(score);
            break;
        case SimpleGesturesUp:
            doUp();
            doCheck();
            setScore(score);
            break; 
        case SimpleGesturesDown:
            doDown();
            doCheck();
            setScore(score);
            break;
        case SimpleGesturesNotSupport:
        case SimpleGesturesError:
            log("not support or error touch,use geometricRecognizer!!");
            break;
        default:
            break; 
    } 
} 
void BlockEdgeSimilarDetector::Run()
{
#ifdef BED_OUTPUT_DEBUG_INFO
	drowDebugResult = image.clone();
	if (drowDebugResult.channels() == 1)
		cv::cvtColor(drowDebugResult, drowDebugResult, CV_GRAY2BGR);
	doUp();
	doDown(); 
	doLeft();
	doRight();
#else
	thread t1 = thread(std::mem_fn(&BlockEdgeSimilarDetector::doUp), this);
	thread t2 = thread(std::mem_fn(&BlockEdgeSimilarDetector::doDown), this);
	thread t3 = thread(std::mem_fn(&BlockEdgeSimilarDetector::doLeft), this);
	thread t4 = thread(std::mem_fn(&BlockEdgeSimilarDetector::doRight), this);
	t1.join();
	t2.join();
	t3.join();
	t4.join();
#endif


	//double maxdiff = (maxdiff_X > maxdiff_Y) ? maxdiff_X : maxdiff_Y;
	//int maxDeep = (maxDeep_X > maxDeep_Y) ? maxDeep_X : maxDeep_Y;
	//stringstream ss;
	//ss << "BED定标消息:最大不相似度=" << maxdiff << ",缺陷最大深度 = " << maxDeep << "pix" << endl;
	//MFCConsole::Output(ss.str());
}
Пример #4
0
void BlockEdgeLineDetector::Run()
{
#ifdef BELD_OUTPUT_DEBUG_INFO
	drowDebugResult = image.clone();
	if (drowDebugResult.channels() == 1)
		cv::cvtColor(drowDebugResult, drowDebugResult, CV_GRAY2BGR);
	doUp();
	doDown(); 
	doLeft();
	doRight();
#else
	thread t1 = thread(std::mem_fn(&BlockEdgeLineDetector::doUp), this);
	thread t2 = thread(std::mem_fn(&BlockEdgeLineDetector::doDown), this);
	thread t3 = thread(std::mem_fn(&BlockEdgeLineDetector::doLeft), this);
	thread t4 = thread(std::mem_fn(&BlockEdgeLineDetector::doRight), this);
	t1.join();
	t2.join();
	t3.join();
	t4.join();
#endif

	minLengthPix = minLengthPix == 9999 ? 0 : minLengthPix;
	minDeepPix = minDeepPix == 9999 ? 0 : minDeepPix;
	stringstream ss;
	ss << "BLED定标消息:最大崩边长度=" << maxLengthPix << "pix,最大深度 = " << maxDeepPix << "pix" << endl;
	ss << "BLED定标消息:最小崩边长度=" << minLengthPix << "pix,最小深度 = " << minDeepPix << "pix" << endl;
	MFCConsole::Output(ss.str());
}
Пример #5
0
void GameScene::onTouchEnded(Touch *touch, Event *unused_event){
    Point pos = touch->getLocation();
    SimpleGestures gesture = recognizer->endPoint(pos);
    
    switch (gesture) {
        case SimpleGesturesLeft:
            doLeft();
            log("left");
            break;
        case SimpleGesturesRight:
            doRight();
            log("right");
            break;
        case SimpleGesturesUp:
            doUp();
            log("up");
            break;
        case SimpleGesturesDown:
            doDown();
            log("dowm");
            break;
            
        default:
            break;
    }
    
    createCardNumber(true);
    
}
Пример #6
0
//事件监听回调:触摸结束
void HelloWorld::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *unused_event)
{
	//获取X轴和Y轴的移动范围
	Point touchPoint=touch->getLocation(); //获取OpenGL坐标(即cocos2d-x坐标,原点在左下角)
	endX=firstX - touchPoint.x;
	endY=firstY - touchPoint.y;

	//判断X轴和Y轴的移动距离,如果X轴的绝对值大,则向左右滑动,如果Y轴的绝对值大,则向上下滑动
	if(abs(endX) > abs(endY))
	{
		//手势向左右
		//判断向左还是向右
		if(endX+5>0)
		{
			//向左
			doLeft();
		//判断游戏是否还能继续  
         doCheckGameOver(); 
		}
		else
		{
			//向右
			doRight();
			//判断游戏是否还能继续  
         doCheckGameOver(); 
		}
	}
	else
	{
		//手势向上下
		//判断手势向上还是向下
		if(endY+5>0)
		{
			//向下
			doDown();
			//判断游戏是否还能继续  
         doCheckGameOver(); 
		}
		else
		{
			//向上
			doUp();
			//判断游戏是否还能继续  
         doCheckGameOver(); 
		}

	}
}
Пример #7
0
void GameScene::onTouchEnded(Touch* touch, Event* event)
{
	//得到触摸结束时坐标
	Point endTouch = touch->getLocation();  //获取OpenGL坐标,以左下角为原点
	//计算手指在X,Y移动的距离
	endX = beginX - endTouch.x;
	endY = beginY - endTouch.y;
	if (abs(endX) > abs(endY))
	{
		//如果X轴移动的距离大于Y轴,则是左右移动
		if (endX + 5 > 0)
		{
			//向左移动
			doLeft();
			createCardNumber();
			doCheck();
			setScore(score);
		}
		else
		{
			//向右移动
			doRight();
			createCardNumber();
			doCheck();
			setScore(score);
		}
	}
	else //否则是上下移动
	{
		if (endY + 5 > 0)
		{
			//向下移动
			doDown();
			createCardNumber();
			doCheck();
			setScore(score);
		}
		else
		{
			//向上移动
			doUp();
			createCardNumber();
			doCheck();
			setScore(score);
		}
	}
}
Пример #8
0
void BlockEdgeDetectorT::Run()
{
#ifdef BED_OUTPUT_DEBUG_INFO
	drowDebugResult = image.clone();
	if (drowDebugResult.channels() == 1)
		cv::cvtColor(drowDebugResult, drowDebugResult, CV_GRAY2BGR);
	//doUp();
	//doDown();
	doLeft();
	//doLeft();
	//doRight();
#else
	thread t1 = thread(std::mem_fn(&BlockEdgeDetectorT::doUp), this);
	thread t2 = thread(std::mem_fn(&BlockEdgeDetectorT::doDown), this);
	thread t3 = thread(std::mem_fn(&BlockEdgeDetectorT::doLeft), this);
	thread t4 = thread(std::mem_fn(&BlockEdgeDetectorT::doRight), this);
	t1.join();
	t2.join();
	t3.join();
	t4.join();
#endif
}
Пример #9
0
void HelloWorld::onTouchEnded(Touch *touch, Event *unused_event){
	Point touchPo = touch->getLocation();
	endX = firstX - touchPo.x;
	endY = firstY - touchPo.y;

	if (abs(endX) > abs(endY)){//绝对值
		//左右
		if (endX+5>0){
			//左边
			if (doLeft()){
				autoCreateCardNumber();
				doCheckGameOver();
			}
		}else{
			//右边
			if (doRight()){
				autoCreateCardNumber();
				doCheckGameOver();
			}
		}
	}else{
		//上下
		if (endY + 5 < 0){
			//上
			if (doUp()){
				autoCreateCardNumber();
				doCheckGameOver();
			}
		}else{
			//下
			if (doDown()){
				autoCreateCardNumber();
				doCheckGameOver();
			}
		}
	}
}
task main ()
{
	ubyte type;
	ubyte ID;
	ubyte state;
	ubyte value;
	string dataString;
	string tmpString;

	// initialise the port, etc
	RS485initLib();

	StartTask(updateScreen);

	// Disconnect if already connected
	N2WDisconnect();
	N2WchillOut();
	wait1Msec(1000);
  if (!N2WCustomExist())
  {
    StopTask(updateScreen);
    wait1Msec(50);
    eraseDisplay();
    PlaySound(soundException);
    nxtDisplayCenteredBigTextLine(1, "ERROR");
    nxtDisplayTextLine(3, "No custom profile");
    nxtDisplayTextLine(4, "configured!!");
    while(true) EndTimeSlice();
  }

  N2WLoad();

	wait1Msec(100);

	N2WConnect(true);
	connStatus = "connecting";

	while (!N2WConnected()) wait1Msec(100);
	wait1Msec(1000);

	connStatus = "connected";
	PlaySound(soundBeepBeep);

	wait1Msec(3000);
	N2WgetIP(IPaddress);

	wait1Msec(1000);
	//                123456789012345
	dataStrings[0] = "Tch | Snr | Clr";
	//                on  | 011 |   1"
	while (true)
	{
		if (N2WreadWS(type, ID, state, value))
		{
			writeDebugStreamLine("btn: %d, state: %d", ID, state);
			switch (ID)
			{
			case 1: doStraight(state); break;
			case 3: doRight(state); break;
			case 4: doStop(state); break;
			case 5: doLeft(state); break;
			case 7: doReverse(state); break;
			case 9: doAction(state); break;
			case 11: handleColour(state); break;
			default: break;
			}
		}

		// All values are only updated when they've changed.
		// This cuts backs drastically on the number of messages
		// that have to be sent to the NXT2WIFI

		// Fetch the state of the Touch Sensor
		// This value is displayed by field 0 (in0) on the page
		currTouchState = SensorBoolean[TOUCH];
		if (currTouchState != prevTouchState)
		{
		  memset(data, 0, sizeof(data));
			data[0] = (currTouchState) ? '1' : '0';
			N2WwriteWS(1, 0, data, 2);
			prevTouchState = currTouchState;
			N2WchillOut();
		}

		// Fetch the currently detected colour.
		// This value is displayed by field 1 (in1) on the page
		currDetectedColour = SensorValue[COLOUR];
		if (currDetectedColour != prevDetectedColour)
		{
			sprintf(dataString, "%d", currDetectedColour);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 1, data, strlen(dataString));
			prevDetectedColour = currDetectedColour;
			N2WchillOut();
		}

		// Fetch the distance detected by the sonar sensor
		// This value is displayed by field 2 (in2) on the page
		currSonarDistance = SensorValue[SONAR];
		if (currSonarDistance != prevSonarDistance)
		{
			sprintf(dataString, "%d", currSonarDistance);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 2, data, strlen(dataString));
			prevSonarDistance = currSonarDistance;
			N2WchillOut();
		}

		// Fetch the tacho count for motor A
		// This value is displayed by field 3 (in3) on the page
		currEncMotorA = nMotorEncoder[MOT_ACTION];
		if (currEncMotorA != prevEncMotorA)
		{
			sprintf(dataString, "%d", currEncMotorA);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 3, data, strlen(dataString));
			prevEncMotorA = currEncMotorA;
			N2WchillOut();
		}

		// Fetch the tacho count for motor B
		// This value is displayed by field 4 (in4) on the page
		//currEncMotorB = nMotorEncoder[MOT_LEFT];
		if (currEncMotorB != prevEncMotorB)
		{
			sprintf(dataString, "%d", currEncMotorB);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 4, data, strlen(dataString));
			prevEncMotorB = currEncMotorB;
			N2WchillOut();
		}

		// Fetch the tacho count for motor C
		// This value is displayed by field 5 (in5) on the page
		currEncMotorC = nMotorEncoder[MOT_RIGHT];
		if (currEncMotorC != prevEncMotorC)
		{
			sprintf(dataString, "%d", currEncMotorC);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 5, data, strlen(dataString));
			prevEncMotorC = currEncMotorC;
			N2WchillOut();
		}

		// Fetch the current voltage level.  The average one
		// works best, the other one jumps around too much.
		// This value is displayed by field 6 (in6) on the page

		currBatteryLevel = nAvgBatteryLevel;
		if (currBatteryLevel != prevBatteryLevel)
		{
			sprintf(dataString, "%d", currBatteryLevel);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 6, data, strlen(dataString));
			prevBatteryLevel = currBatteryLevel;
			N2WchillOut();
		}

		sprintf(dataStrings[2], "A: %d", currEncMotorA);
		sprintf(dataStrings[3], "B: %d", currEncMotorB);
		sprintf(dataStrings[4], "C: %d", currEncMotorC);
	  sprintf(tmpString, "%s | %3d", (currTouchState == 0) ? "off" : "on ", currSonarDistance);
		sprintf(dataStrings[1], "%s | %3d", tmpString, currDetectedColour);
	}
}
task main ()
{
	ubyte type;
	ubyte ID;
	ubyte state;
	ubyte value;
	string dataString;
	string tmpString;

	// initialise the port, etc
	RS485initLib();

	StartTask(updateScreen);

	// Disconnect if already connected
	N2WDisconnect();
	N2WchillOut();
	wait1Msec(1000);
	// enable DHCP
	N2WsetDHCP(true);
	wait1Msec(100);
	// Disable adhoc
	N2WsetAdHoc(false);
	wait1Msec(100);

	// Network Configuration
	N2WsetMask("255.255.255.0");
	wait1Msec(100);
	N2WsetGateway("10.0.0.138");
	wait1Msec(100);
	N2WsetDNS1("8.8.8.8");
	wait1Msec(100);
	N2WsetDNS2("8.8.4.4");
	wait1Msec(100);
	N2WsetNetbiosName("NXT2WIFI1");
	wait1Msec(100);

	// SSID to connect to
	N2WsetSSID("test");
	wait1Msec(100);
	// The passphrase to use
	N2WSecurityWPA2Passphrase("pwasde08");
	wait1Msec(100);
	// Save this profile to the custom profile
	N2WSave();
	wait1Msec(500);
	// Load the custom profile
	N2WLoad();
	wait1Msec(100);

	N2WConnect(true);
	connStatus = "connecting";

	while (!N2WConnected()) wait1Msec(100);
	wait1Msec(1000);

	connStatus = "connected";
	PlaySound(soundBeepBeep);

	wait1Msec(3000);
	N2WgetIP(IPaddress);

	wait1Msec(1000);
	//                123456789012345
	dataStrings[0] = "Tch | Snr | Clr";
	//                on  | 011 |   1"
	while (true)
	{
		if (N2WreadWS(type, ID, state, value))
		{
			writeDebugStreamLine("btn: %d, state: %d", ID, state);
			switch (ID)
			{
			case 1: doStraight(state); break;
			case 3: doRight(state); break;
			case 4: doStop(state); break;
			case 5: doLeft(state); break;
			case 7: doReverse(state); break;
			case 9: doAction(state); break;
			case 11: handleColour(state); break;
			default: break;
			}
		}

		// All values are only updated when they've changed.
		// This cuts backs drastically on the number of messages
		// that have to be sent to the NXT2WIFI

		// Fetch the state of the Touch Sensor
		// This value is displayed by field 0 (in0) on the page
		currTouchState = SensorValue[TOUCH];
		if (currTouchState != prevTouchState)
		{
			sprintf(dataString, "%d", currTouchState);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 0, data, strlen(&data));
			prevTouchState = currTouchState;
			N2WchillOut();
		}

		// Fetch the currently detected colour.
		// This value is displayed by field 1 (in1) on the page
		currDetectedColour = SensorValue[COLOUR];
		if (currDetectedColour != prevDetectedColour)
		{
			sprintf(dataString, "%d", currDetectedColour);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 1, data, strlen(dataString));
			prevDetectedColour = currDetectedColour;
			N2WchillOut();
		}

		// Fetch the distance detected by the sonar sensor
		// This value is displayed by field 2 (in2) on the page
		currSonarDistance = SensorValue[SONAR];
		if (currSonarDistance != prevSonarDistance)
		{
			sprintf(dataString, "%d", currSonarDistance);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 2, data, strlen(dataString));
			prevSonarDistance = currSonarDistance;
			N2WchillOut();
		}

		// Fetch the tacho count for motor A
		// This value is displayed by field 3 (in3) on the page
		currEncMotorA = nMotorEncoder[MOT_ACTION];
		if (currEncMotorA != prevEncMotorA)
		{
			sprintf(dataString, "%d", currEncMotorA);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 3, data, strlen(dataString));
			prevEncMotorA = currEncMotorA;
			N2WchillOut();
		}

		// Fetch the tacho count for motor B
		// This value is displayed by field 4 (in4) on the page
		currEncMotorB = nMotorEncoder[MOT_LEFT];
		if (currEncMotorB != prevEncMotorB)
		{
			sprintf(dataString, "%d", currEncMotorB);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 4, data, strlen(dataString));
			prevEncMotorB = currEncMotorB;
			N2WchillOut();
		}

		// Fetch the tacho count for motor C
		// This value is displayed by field 5 (in5) on the page
		currEncMotorC = nMotorEncoder[MOT_RIGHT];
		if (currEncMotorC != prevEncMotorC)
		{
			sprintf(dataString, "%d", currEncMotorC);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 5, data, strlen(dataString));
			prevEncMotorC = currEncMotorC;
			N2WchillOut();
		}

		// Fetch the current voltage level.  The average one
		// works best, the other one jumps around too much.
		// This value is displayed by field 6 (in6) on the page

		currBatteryLevel = nAvgBatteryLevel;
		if (currBatteryLevel != prevBatteryLevel)
		{
			sprintf(dataString, "%d", currBatteryLevel);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 6, data, strlen(dataString));
			prevBatteryLevel = currBatteryLevel;
			N2WchillOut();
		}

		sprintf(dataStrings[2], "A: %d", currEncMotorA);
		sprintf(dataStrings[3], "B: %d", currEncMotorB);
		sprintf(dataStrings[4], "C: %d", currEncMotorC);
	sprintf(tmpString, "%s | %3d", (currTouchState == 0) ? "off" : "on ", currSonarDistance);
		sprintf(dataStrings[1], "%s | %3d", tmpString, currDetectedColour);
	}
}