Esempio n. 1
0
		void engine_EmoStateUpdated(object sender, EmoStateUpdatedEventArgs e)
		{
			es = e.emoState;
			elapsed = es.GetTimeFromStart();
			UpdateSensorContactQuality(es);

			SignalStatus = es.GetWirelessSignalStatus().ToString();
            MainUptime.Content = ConvertToTime(es.GetTimeFromStart());
			Uptime.Content = ConvertToTime(es.GetTimeFromStart());
			es.GetBatteryChargeLevel(out BatteryLevel, out MaxBatteryLevel);
			SamplingRate.Content = samplingRate.ToString();
			BufferSize.Content = bufferSize.ToString();
			EdkDll.EE_DataGetBufferSizeInSec(out bufferSize);
			EdkDll.EE_DataGetSamplingRate(userID, out samplingRate);

			EdkDll.EE_ExpressivAlgo_t lowerFaceAction, upperFaceAction;
			bool expressivIsBlink, expressivIsEyesOpen, expressivIsLeftWink, expressivIsLookingDown, expressivIsLookingLeft, expressivIsLookingRight, expressivIsLookingUp, expressivIsRightWink;
			float lowerFaceActionPower, upperFaceActionPower;
			float leftEye, rightEye;

			#region Expressiv

			#region Lower Face Action

			lowerFaceAction = es.ExpressivGetLowerFaceAction();
			lowerFaceActionPower = es.ExpressivGetLowerFaceActionPower();

			switch (lowerFaceAction)
			{
				case EdkDll.EE_ExpressivAlgo_t.EXP_CLENCH:
					ClearExpressivLowerFaceCircles();
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_LAUGH:
					ClearExpressivLowerFaceCircles();
					LaughRect.Fill = Brushes.Green;
					LaughRect1.Fill = Brushes.Green;
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_NEUTRAL:
					ClearExpressivLowerFaceCircles();
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_SMILE:
					ClearExpressivLowerFaceCircles();
					SmileRect.Fill = Brushes.Green;
					SmileRect1.Fill = Brushes.Green;
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_LEFT:
					ClearExpressivLowerFaceCircles();
					SmirkLeftRect.Fill = Brushes.Green;
					SmirkLeftRect1.Fill = Brushes.Green;
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_RIGHT:
					ClearExpressivLowerFaceCircles();
					SmirkRightRect.Fill = Brushes.Green;
					SmirkRightRect1.Fill = Brushes.Green;
					break;
				default:
					break;
			}

			#region Clench Extent

			float clenchExtent = es.ExpressivGetClenchExtent();
			Clench.Content = toPercentString(clenchExtent);
			Clench1.Content = toPercentString(clenchExtent);

			if (clenchExtent < 0.20)
			{
				ClenchRect.Fill = Brushes.Black;
			}
			else if (clenchExtent < 0.40)
			{
				ClenchRect.Fill = Brushes.Red;
			}
			else if (clenchExtent < 0.60)
			{
				ClenchRect.Fill = Brushes.Orange;
			}
			else if (clenchExtent < 0.80)
			{
				ClenchRect.Fill = Brushes.Yellow;
			}
			else
			{
				ClenchRect.Fill = Brushes.Green;
			}

			#endregion Clench Extent

			#region Smile Extent

			float smileExtent = es.ExpressivGetSmileExtent();
			Smile.Content = toPercentString(smileExtent);
			Smile1.Content = toPercentString(smileExtent);

			if (smileExtent < 0.20)
			{
				SmileRect.Fill = Brushes.Black;
			}
			else if (smileExtent < 0.40)
			{
				SmileRect.Fill = Brushes.Red;
			}
			else if (smileExtent < 0.60)
			{
				SmileRect.Fill = Brushes.Orange;
			}
			else if (smileExtent < 0.80)
			{
				SmileRect.Fill = Brushes.Yellow;
			}
			else
			{
				SmileRect.Fill = Brushes.Green;
			}

			#endregion Smile Extent

			//LowerFaceAction.Content = lowerFaceAction.ToString();

			#endregion Lower Face Action

			#region Middle Face Action

			es.ExpressivGetEyelidState(out leftEye, out rightEye);
			expressivIsBlink = es.ExpressivIsBlink();
			if (expressivIsBlink)
			{
				ClearExpressivUpperFaceCircles();
				BlinkRect.Fill = Brushes.Green;
				BlinkRect1.Fill = Brushes.Green;
			}
			expressivIsEyesOpen = es.ExpressivIsEyesOpen();
			if (expressivIsEyesOpen)
			{
				//MiddleFaceAction.Content = "Eyes Open";
				BlinkRect.Fill = Brushes.Black;
				BlinkRect1.Fill = Brushes.Black;
			}
			else
			{
				BlinkRect.Fill = Brushes.Green;
				BlinkRect1.Fill = Brushes.Green;
				//MiddleFaceAction.Content = "Eyes Closed";
			}
			expressivIsLeftWink = es.ExpressivIsLeftWink();
			if (expressivIsLeftWink)
			{
				ClearExpressivUpperFaceCircles();
				WinkLeftRect.Fill = Brushes.Green;
				WinkLeftRect1.Fill = Brushes.Green;
			}
			expressivIsRightWink = es.ExpressivIsRightWink();
			if (expressivIsRightWink)
			{
				ClearExpressivUpperFaceCircles();
				WinkRightRect.Fill = Brushes.Green;
				WinkRightRect1.Fill = Brushes.Green;
			}
			expressivIsLookingDown = es.ExpressivIsLookingDown();
			if (expressivIsLookingDown)
			{
				//MessageBox.Show("I am looking down");
			}
			expressivIsLookingLeft = es.ExpressivIsLookingLeft();
			if (expressivIsLookingLeft)
			{
				//MessageBox.Show("I am looking left"); // Emotiv SDK is wrong
			}
			expressivIsLookingRight = es.ExpressivIsLookingRight();
			if (expressivIsLookingRight)
			{
				//MessageBox.Show("I am looking right"); // Emotiv SDK is wrong
			}
			expressivIsLookingUp = es.ExpressivIsLookingUp();
			if (expressivIsLookingUp)
			{
				//MessageBox.Show("I am looking up");
			}
			float eyeXCoordinate, eyeYCoordinate;
			es.ExpressivGetEyeLocation(out eyeXCoordinate, out eyeYCoordinate);
			if (eyeXCoordinate > 0)
			{
				//MessageBox.Show("Looking Right");
			}
			else if (eyeXCoordinate<0)
			{
				//MessageBox.Show("Looking Left"); // sometimes it works
			}
			if (eyeYCoordinate > 0)
			{
				MessageBox.Show("Looking Up"); // not working
			}
			else if (eyeYCoordinate < 0)
			{
				MessageBox.Show("Looking Down"); // not working
			}

			#endregion Middle Face Action

			#region Upper Face Action

			upperFaceAction = es.ExpressivGetUpperFaceAction();
			upperFaceActionPower = es.ExpressivGetUpperFaceActionPower();

			switch (upperFaceAction)
			{
				case EdkDll.EE_ExpressivAlgo_t.EXP_EYEBROW:
					ClearExpressivUpperFaceCircles();
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_FURROW:
					ClearExpressivUpperFaceCircles();
					FurrowRect.Fill = Brushes.Green;
					FurrowRect1.Fill = Brushes.Green;
					break;
				case EdkDll.EE_ExpressivAlgo_t.EXP_NEUTRAL:
					ClearExpressivUpperFaceCircles();
					break;
				default:
					break;
			}

			#region Eyebrow Extent

			float eyebrowExtent = es.ExpressivGetEyebrowExtent();
			Eyebrow.Content = toPercentString(eyebrowExtent);
			Eyebrow1.Content = toPercentString(eyebrowExtent);

			if (eyebrowExtent < 0.20)
			{
				EyebrowRect.Fill = Brushes.Black;
				EyebrowRect1.Fill = Brushes.Black;
			}
			else if (eyebrowExtent < 0.40)
			{
				EyebrowRect.Fill = Brushes.Red;
				EyebrowRect1.Fill = Brushes.Red;
			}
			else if (eyebrowExtent < 0.60)
			{
				EyebrowRect.Fill = Brushes.Orange;
				EyebrowRect1.Fill = Brushes.Orange;
			}
			else if (eyebrowExtent < 0.80)
			{
				EyebrowRect.Fill = Brushes.Yellow;
				EyebrowRect1.Fill = Brushes.Yellow;
			}
			else
			{
				EyebrowRect.Fill = Brushes.Green;
				EyebrowRect1.Fill = Brushes.Green;
			}

			#endregion Eyebrow Extent
						
			//UpperFaceAction.Content = upperFaceAction.ToString();

			#endregion Upper Face Action

			// Must be removed
			#region Robots

			#region OWI535 Robotic Arm

			//if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_CLENCH)
			//{
			//    OWI535RoboticArm.GrippersClose(1000);
			//}
			//else if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_LEFT)
			//{
			//    OWI535RoboticArm.ArmRotateLeft(1000);
			//}
			//else if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_RIGHT)
			//{
			//    OWI535RoboticArm.ArmRotateRight(1000);
			//}

			//else if (es.ExpressivGetEyebrowExtent() > 0.10)
			//{
			//    OWI535RoboticArm.ArmStop();
			//}
			//else if (es.ExpressivIsRightWink())
			//{
			//    OWI535RoboticArm.GrippersOpen(1000);
			//}

			#endregion OWI535 Robotic Arm

			#region R2D2

			if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_CLENCH)
			{
				//R2D2.MoveForward();
                int iRobotVelocity = getiRobotVelocity();
                iRobotMoveForward(iRobotVelocity);
                
			}
			else if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_LEFT)
			{
				//R2D2.MoveLeft();
                int iRobotVelocity = getiRobotVelocity();
                iRobotTurnLeft(iRobotVelocity);
			}
			else if (lowerFaceAction == EdkDll.EE_ExpressivAlgo_t.EXP_SMIRK_RIGHT)
			{
				//R2D2.MoveRight();
                int iRobotVelocity = getiRobotVelocity();
                iRobotTurnRight(iRobotVelocity);
			}
			else if (es.ExpressivGetEyebrowExtent() > 0.10)
			{
				//R2D2.Stop();
                iRobotStop();
			}
			
			#endregion R2D2

			#endregion Robots

			#endregion Expressiv

			#region Affectiv
			
			AffectiveEngagementBoredom = es.AffectivGetEngagementBoredomScore();    // Get Engagement/Boredom Score.
			AffectivExcitementLong = es.AffectivGetExcitementLongTermScore();       // Get Excitement Long Term Score.
			AffectivExcitementShort = es.AffectivGetExcitementShortTermScore();     // Get Excitement Short Term Score.
			AffectivFrustration = es.AffectivGetFrustrationScore();                 // Get Frustration Score.
			AffectivMeditation = es.AffectivGetMeditationScore();                   // Get Meditation Score.

			#endregion Affectiv

			#region Cognitiv

			EdkDll.EE_CognitivAction_t EEGAction;
			EEGAction = es.CognitivGetCurrentAction();
			double cognitivpower = es.CognitivGetCurrentActionPower();
			double cognitivpowerPercent = cognitivpower * 100;
			UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(CognitivPowerProgressBar.SetValue);
			Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, cognitivpowerPercent });

			cognitivPower.Content = (Convert.ToInt32(cognitivpowerPercent)).ToString() + " %";
			bool cognitivIsNoisy;
			cognitivIsNoisy = es.CognitivIsActive();
			if (cognitivIsNoisy)
			{
				cognitivIsActive.Content = "Noisy";
			}
			else
			{
				cognitivIsActive.Content = "Ok";
			}

			// Get Cognitiv Action
			switch (EEGAction)
			{
				case EdkDll.EE_CognitivAction_t.COG_DISAPPEAR:
					cognitivIsState.Content = "Dissapear";
					break;
				case EdkDll.EE_CognitivAction_t.COG_DROP:
					MessageBox.Show("Drop");
					cognitivIsState.Content = "Drop";
					break;
				case EdkDll.EE_CognitivAction_t.COG_LEFT:
					cognitivIsState.Content = "Left";
					break;
				case EdkDll.EE_CognitivAction_t.COG_LIFT:
					cognitivIsState.Content = "Lift";
					break;
				case EdkDll.EE_CognitivAction_t.COG_NEUTRAL:
					cognitivIsState.Content = "Neutral";
					break;
				case EdkDll.EE_CognitivAction_t.COG_PULL:
					cognitivIsState.Content = "Pull";
					break;
				case EdkDll.EE_CognitivAction_t.COG_PUSH:
					cognitivIsState.Content = "Push";
					if (cognitivpower > 0.2)
					{
						//R2D2.MoveBack();
                        int iRobotVelocity = getiRobotVelocity();
                        iRobotMoveForward(iRobotVelocity);
						//OWI535RoboticArm.Handshake();
					}
					break;
				case EdkDll.EE_CognitivAction_t.COG_RIGHT:
					cognitivIsState.Content = "Right";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_CLOCKWISE:
					cognitivIsState.Content = "Rotate Clockwise";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_COUNTER_CLOCKWISE:
					cognitivIsState.Content = "Rotate Counter Clockwise";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_FORWARDS:
					cognitivIsState.Content = "Rotate Forwards";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_LEFT:
					cognitivIsState.Content = "Rotate Left";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_REVERSE:
					cognitivIsState.Content = "Rotate Reverse";
					break;
				case EdkDll.EE_CognitivAction_t.COG_ROTATE_RIGHT:
					cognitivIsState.Content = "Rotate Right";
					break;
				default:
					break;
			}

			#endregion Cognitiv

		}