Esempio n. 1
0
void UUIActionCommand::PopulateClock( Clock* inClock, int index )
{
  clock = inClock;

  // Recall cooldown's time from the action object (model object)
  // Set the cooldown's time at Populate time. Too early to do in ctor 
  // (UClass data may not have loaded)
  cooldown.TotalTime = GetCooldownTotalTime();
  
  // attach Action's Click() function to clicking on the clock.
  UUICmdActionIndex = index; // index inside the array that hosts the Counters.
  clock->SetTexture( GetIcon() );
  
  // Set the cooldown amount to being the cooldown of the particular action
  clock->SetFillFraction( cooldown.Fraction() );
  
  //info( FS( "Populating clock `%s` with cooldown=%f/%f",
  //  *clock->Name, cooldown.Time, cooldown.TotalTime ) );
  clock->Show();

  // Invoke I'th action of the object
  clock->OnMouseDownLeft = [this]( FVector2D mouse ) -> EventCode { 
    Click();
    info( FS( "Clicked Action %s", *GetName() ) );
    return Consumed;
  };
  
  clock->OnHover = [this]( FVector2D mouse ) -> EventCode {
    Hover();
    return NotConsumed;
  };
}
Esempio n. 2
0
UIElement * UserInterface::Hover(Vector2i xy, bool allUi)
{
	return Hover(xy.x, xy.y, allUi);
}
Esempio n. 3
0
// Autonomous drone control
void AutoAdjustPosition(int key) {
	// Only auto-correct if user is not controlling drone and not in absolute control mode
	if (key < 0 && !absoluteControl) {

		// Switch variable
		int patternSwitch = 0;

		//// Check if there is no pattern visible, but there was one store previously
		//if (visiblePattern == 0 && lastVisiblePattern != 0) {
		//	// If so, execute action of last pattern
		//	patternSwitch = lastVisiblePattern;
		//// Else, execute current action
		//} else patternSwitch = visiblePattern;
		patternSwitch = visiblePattern;

		switch (patternSwitch) {

		case 4:
			PitchBackwards(false);
			RollRight(false);
			break;

		case 5:
			PitchBackwards(false);
			break;

		case 6:
			PitchBackwards(false);
			RollLeft(false);
			break;

		case 7:
			RollLeft(false);
			break;

		case 8:
			PitchForwards(false);
			RollLeft(false);
			break;

		case 9:
			PitchForwards(false);
			break;

		case 10:
			PitchForwards(false);
			RollRight(false);
			break;

		case 11:
			RollRight(false);
			break;

		case 1:
		case 2:
		case 3:
			Hover();
			break;
		}

		//cout << "last visible " << lastVisiblePattern << endl;
	}
}
Esempio n. 4
0
void KeyControls(int key) {

	// Quit if ESC key
	if (key == 0x1b) quitProgram = true;

	// Start/Stop the game
	// p key
	if (key == 'p') {
		if (gameOn) gameOn = false;
		else {
			gameOn = true;
			// reset points
			points = 0;
			// reset timer
			gameTimeStart = cvGetTickCount();
			// reset crate/people pickup
			cratePicked = false;
			peoplePicked = false;
		}
	}

	// Change camera - C key
	static int mode = 0;
	if (key == 'c') ardrone.setCamera(++mode % 4);

	// Take off / Landing - SPACE key
	if (key == ' ') {
		ardrone.setFlatTrim();
		if (ardrone.onGround()) ardrone.takeoff();
		else                    ardrone.landing();
	}

	// Emergency stop
	// x key
	if (key == 'x') ardrone.emergency();

	// Start hovering
	// h key
	if (key == 'h') Hover();

	// Movement
	// r key
	// Gain altitude
	if (key == 'r')
		if (!IsTooHigh())
			GainAltitude();

	// Down arrow
	// f key
	// Loose altitude
	if (key == 'f')
		if (!IsTooLow())
			LooseAltitude();

	// q key
	// Yaw c-clockwise
	if (key == 'q')
		YawCClockwise();

	// e key
	// Yaw clockwise
	if (key == 'e')
		YawClockwise();

	// Game controls - need to be within bounds to opperate
	// Left arrow / a key
	// Roll left
	if (key == 0x250000 || key == 'a')
		if (IsWithinLeftBounds())
			RollLeft(true);
		else RollRight(false);

		// Right arrow / d key
		// Roll right
		if (key == 0x270000 || key == 'd')
			if (IsWithinRightBounds())
				RollRight(true);
			else RollLeft(false);

			// Up arrow // w key
			// Pitch forwards
			if (key == 0x260000 || key == 'w')
				if (IsWithinUpperBounds())
					PitchForwards(true);

			// Down arrow / s key
			// Pitch backwards
			if (key == 0x280000 || key == 's')
				if (IsWithinLowerBounds())
					PitchBackwards(true);

			// Toggle absolute control
			// o key
			if (key == 'o') {
				if (absoluteControl) absoluteControl = false;
				else absoluteControl = true;
			}
}
Esempio n. 5
0
// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description  : This is the entry point of the program.
// Return value : SUCCESS:0  ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char **argv) {

	// Initialize
	// If drone is not connected, initialise webcam
	if (!ardrone.open()) {
		printf("Drone failed to connect.\n");
		isDroneConnected = false;
	}
	else isDroneConnected = true;

	//// DEBUGGING
	//isDroneConnected = false;


	quitProgram = false;
	int patternCount = 0;
	visiblePattern = 0;
	//lastVisiblePattern = 0;
	absoluteControl = false;
	vx = 0.0, vy = 0.0, vz = 0.0, vr = 0.0;
	points = 0, pSaved = 0, cSaved = 0;
	peoplePicked = false, cratePicked = false;
	gameTimeStart = cvGetTickCount();
	gameTimeLeft = 0;
	gameOn = false;


	// Loading patterns
	LoadPattern(filename1, patternLibrary, patternCount);
	LoadPattern(filename2, patternLibrary, patternCount);
	LoadPattern(filename3, patternLibrary, patternCount);
	LoadPattern(filename4, patternLibrary, patternCount);
	LoadPattern(filename5, patternLibrary, patternCount);
	LoadPattern(filename6, patternLibrary, patternCount);
	LoadPattern(filename7, patternLibrary, patternCount);
	LoadPattern(filename8, patternLibrary, patternCount);
	LoadPattern(filename9, patternLibrary, patternCount);
	LoadPattern(filename10, patternLibrary, patternCount);
	LoadPattern(filename11, patternLibrary, patternCount);

	cout << patternCount << " patterns are loaded." << endl;


	// Pattern detector arguments
	int norm_pattern_size = PAT_SIZE;
	double fixed_thresh = 40;
	double adapt_thresh = 5;//non-used with FIXED_THRESHOLD mode
	int adapt_block_size = 45;//non-used with FIXED_THRESHOLD mode
	double confidenceThreshold = 0.35;
	int mode = 2;//1:FIXED_THRESHOLD, 2: ADAPTIVE_THRESHOLD

	// Set to vertical drone camera
	ardrone.setCamera(1);

	// Initialise PatternDetector
	PatternDetector myDetector(fixed_thresh, adapt_thresh, adapt_block_size, confidenceThreshold, norm_pattern_size, mode);

	vector<Point2f> coordinates;
	Point2f point;
	coordinates.push_back(point);
	coordinates.push_back(point);
	coordinates.push_back(point);
	coordinates.push_back(point);
	coordinates.push_back(point);
	for (int i = 0; i <= patternCount; i++) {
		// Initialise each pattern coordinates
		patternsCoordinates.push_back(coordinates);

		//// Initialise each pattern timer
		//int timer;
		//timers.push_back(timer);
	}


	// Start main loop
	while (1) {

		// check to terminate program
		if (quitProgram) break;

		// Update
		if (!ardrone.update()) break;

		// OpenCV image
		IplImage *img;

		// Check which image source to feed to OpenCV
		if (isDroneConnected) {
			// Get drone image
			img = ardrone.getImage();
		}
		else {
			// Capture webcam feed
			webcamCapture = cvCaptureFromCAM(0);

			// Get webcam image
			img = cvQueryFrame(webcamCapture);
		}



		// Create image matrix
		Mat imgMat = Mat(img);

		// Render the HUD
		Mat result;
		if (isDroneConnected)
			result = HUD(imgMat, WIDTH, HEIGHT);
		else
			result = HUD(imgMat, WIDTH, WEBCAM_HEIGHT);

		// Create a buffer of the image
		Mat buffer;
		result.copyTo(buffer);

		// Run the detector
		myDetector.detect(imgMat, cameraMatrix, distortions, patternLibrary, detectedPattern);

		// Augment the input frame (and print out the properties of pattern if you want)
		if (detectedPattern.size()) {
			for (unsigned int i = 0; i < detectedPattern.size(); i++) {

				// Get pattern id
				int id = detectedPattern[i].id;

				//// Start current pattern seen timer
				//int now = cvGetTickCount();
				//int passedSinceSeen = ((now - timers[detectedPattern[i].id]) / (cvGetTickFrequency() * 1000)) / 1000;

				//// Only set visible pattern if detected a pattern for more than 1 second 
				//if (passedSinceSeen > SEEN_TIMER) SetVisiblePattern(detectedPattern[i].id);
				SetVisiblePattern(id);


				// Drawing
				detectedPattern.at(i).draw(buffer, cameraMatrix, distortions);


				// Get pattern corner and centre coordinates
				Point2f ul, ur, lr, ll, centre;
				detectedPattern.at(i).getCoordinates(ul, ur, lr, ll, centre, cameraMatrix, distortions);

				// Store coordinates
				patternsCoordinates[id][0] = ul;
				patternsCoordinates[id][1] = ur;
				patternsCoordinates[id][2] = lr;
				patternsCoordinates[id][3] = ll;
				patternsCoordinates[id][4] = centre;


				if (isDroneConnected)
					CheckGamePatterns(WIDTH, HEIGHT, id);
				else CheckGamePatterns(WIDTH, WEBCAM_HEIGHT, id);
			}
		}
		else {
			//for (int i = 0; i < patternCount; i++) {
			//	// reset pattern timers
			//	timers[i] = cvGetTickCount();
			//}

			// Reset visible pattern
			visiblePattern = 0;
		}

		//// Get elapsed time since last saw pattern
		//lastVPElapsed = cvGetTickCount();
		//int elapsedTime = ((lastVPElapsed - lastVPStart) / (cvGetTickFrequency() * 1000)) / 1000;

		//// Check if reset timer limit passed and reset last visible pattern
		//if (elapsedTime < 300)
		//	if (RESET_TIMER - elapsedTime < 0) lastVisiblePattern = 0;



		// Get key input
		int key = cvWaitKey(33);

		// Providing key controls
		KeyControls(key);


		// Autonomous drone control
		KeepGoodAltitude();
		AutoAdjustPosition(key);

		// Always go back to hovering if no user input, no pattern visible and too old last visible pattern (0)
		if (absoluteControl && key < 0) Hover();
		else if (key < 0 && visiblePattern == 0/* && lastVisiblePattern == 0*/) Hover();

		// Drone movement
		ardrone.move3D(vx, vy, vz, vr);


		// Check game over
		if (gameTimeLeft < 0) {
			gameOn = false;
			peoplePicked = false;
			cratePicked = false;
		}


		// Combine buffer with original image + opacity
		double opacity = 0.4;
		addWeighted(buffer, opacity, result, 1 - opacity, 0, result);


		// Initialise window with OpenGL support
		namedWindow("AR.Drone", WINDOW_OPENGL);
		// Show the OpenCV image in a new window AR.Drone
		imshow("AR.Drone", result);


		// Give HighGUI time to process the draw requests
		cvWaitKey(1);


		// Clear pattern for next tick
		detectedPattern.clear();
	}

	// Stop processes before quitting
	Stop();
	return 0;
}