/// <summary> /// Event function called when EmoEngine detects new mental command /// Updates current action for UI and Training Cube /// </summary> void OnMentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs args) { if (training) { cube.SetAciton(cube.ACTION_RESET); return; } //do not update during training EdkDll.IEE_MentalCommandAction_t action = args.emoState.MentalCommandGetCurrentAction(); //Move Block and Update UI text switch (action) { case EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL: cube.SetAciton(cube.ACTION_NEUTRAL); UI.UpdateCurrentActionText("Current Action: Neutral"); break; case EdkDll.IEE_MentalCommandAction_t.MC_RIGHT: cube.SetAciton(cube.ACTION_RIGHT); UI.UpdateCurrentActionText("Current Action: Right"); break; case EdkDll.IEE_MentalCommandAction_t.MC_LEFT: cube.SetAciton(cube.ACTION_LEFT); UI.UpdateCurrentActionText("Current Action: Left"); break; } }
/// <summary> /// Start traning MentalCommand action /// </summary> /// <param name="MentalCommandAction">MentalCommand Action</param> public static void StartTrainingMentalCommand(EdkDll.IEE_MentalCommandAction_t MentalCommandAction) { if (MentalCommandAction == EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL) { EmoEngine.Instance.MentalCommandSetTrainingAction((uint)EmoUserManagement.currentUser, MentalCommandAction); EmoEngine.Instance.MentalCommandSetTrainingControl((uint)EmoUserManagement.currentUser, EdkDll.IEE_MentalCommandTrainingControl_t.MC_START); } else { for (int i = 1; i < MentalCommandActionList.Length; i++) { if (MentalCommandAction == MentalCommandActionList[i]) { Debug.Log("Action compare"); if (MentalCommandActionsEnabled[i]) { Debug.Log("Action is enabled"); EmoEngine.Instance.MentalCommandSetTrainingAction((uint)EmoUserManagement.currentUser, MentalCommandAction); EmoEngine.Instance.MentalCommandSetTrainingControl((uint)EmoUserManagement.currentUser, EdkDll.IEE_MentalCommandTrainingControl_t.MC_START); } else { Debug.Log("Action is not enabled"); } } } } }
/// <summary> /// Initiates trainging of mental command, called by Left_Button, Right_Button, and Neutral_Button /// </summary> /// <param name="type">Command to be trained ("Neutral","Left","Right")</param> public void TrainAction(string type) { LoggerCSV logger = LoggerCSV.GetInstance(); trainType = type; EdkDll.IEE_MentalCommandAction_t toTrain = EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL; cube.SetAciton(cube.ACTION_RESET); switch (type) { case "Left": toTrain = EdkDll.IEE_MentalCommandAction_t.MC_LEFT; logger.AddEvent(LoggerCSV.EVENT_TRAINING_L); break; case "Right": toTrain = EdkDll.IEE_MentalCommandAction_t.MC_RIGHT; logger.AddEvent(LoggerCSV.EVENT_TRAINING_R); break; default: logger.AddEvent(LoggerCSV.EVENT_TRAINING_N); break; } StartCoroutine(UI.UpdateSlider()); EmoMentalCommand.EnableMentalCommandAction(toTrain, true); EmoMentalCommand.EnableMentalCommandActionsList(); EmoMentalCommand.StartTrainingMentalCommand(toTrain); }
/// <summary> /// Clear mental command accepted by Accept_Clear_Button, /// Clears all data if neutral is cleared /// </summary> /// <param name="type">Command to be trained ("Neutral","Left","Right")</param> public void ClearTraining() { LoggerCSV logger = LoggerCSV.GetInstance(); string statusText = "Neutral"; EdkDll.IEE_MentalCommandAction_t action = EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL; switch (trainType) { case "clear left": statusText = "Left"; action = EdkDll.IEE_MentalCommandAction_t.MC_LEFT; trainType = "clear left"; logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_L); break; case "clear right": statusText = "Right"; action = EdkDll.IEE_MentalCommandAction_t.MC_RIGHT; trainType = "clear right"; logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_R); break; default: logger.AddEvent(LoggerCSV.EVENT_TRAINING_CLEAR_N); UI.UpdateStatusText("Current Aciton: None"); trainType = "clear neutral"; Debug.Log(action); EraseAction(action); //Clear left and right if enabled //Left if (EmoMentalCommand.MentalCommandActionsEnabled[5]) { Debug.Log("left active - clear"); EraseAction(EdkDll.IEE_MentalCommandAction_t.MC_LEFT); } //Right if (EmoMentalCommand.MentalCommandActionsEnabled[6]) { Debug.Log("right active - clear"); EraseAction(EdkDll.IEE_MentalCommandAction_t.MC_LEFT); } DeactivateRL(); //Update UI and Training cube UI.UpdateStatusText("Cleared " + statusText + " Training Data"); UI.UpdateUI(trainType); cube.SetAciton(cube.ACTION_RESET); return; } EraseAction(action); //Deactivate cleared action EmoMentalCommand.EnableMentalCommandAction(action, false); EmoMentalCommand.EnableMentalCommandActionsList(); //Update UI and Training cube UI.UpdateUI(trainType); UI.ActivateButtons(true); cube.SetAciton(cube.ACTION_RESET); UI.UpdateStatusText("Cleared " + statusText + " Training Data"); }
public void SetAction(EdkDll.IEE_MentalCommandAction_t actionType, float mForce) { this.mForce = 30 * mForce; if (actionType == EdkDll.IEE_MentalCommandAction_t.MC_LIFT) { directionVector = Vector3.up; } }
//Adds a condition that is a mental command in Emotiv, to be used with ActionPairing function public bool ActionConditionEmotiv(EdkDll.IEE_MentalCommandAction_t condition) { if (EEGManager.Instance.MentalCommandCurrentAction == condition) { return(true); } return(false); }
/// <summary> /// Enable MentalCommand action in arraylist /// </summary> /// <param name="MentalCommandAction">MentalCommand Action</param> /// <param name="iBool">True = Enable/False = Disable</param> public static void EnableMentalCommandAction(EdkDll.IEE_MentalCommandAction_t MentalCommandAction, Boolean iBool) { for (int i = 1; i < MentalCommandActionList.Length; i++) { if (MentalCommandAction == MentalCommandActionList[i]) { MentalCommandActionsEnabled[i] = iBool; Debug.Log("MentalCommandEnabledList has changed"); } } }
//Another overload to accept mental power too public bool ActionConditionEmotiv(EdkDll.IEE_MentalCommandAction_t condition, int ticks, int mistakes, float mentalPower) { if (EEGManager.Instance.MentalCommandCurrentAction == condition && emoStateTicks >= ticks && mentalPower >= EEGManager.Instance.MentalCommandCurrentActionPower) { emoStateTicks = 0; return(true); } else if (mistakes <= emoStateTicksMistakes && currentCommand == condition) { emoStateTicks = 0; } return(false); }
public override IEmotivState AttemptRead(long time) { UpdateBatteryLevel(); UpdateWirelessSigmalStrength(); //EdkDll.IEE_EEG_ContactQuality_t[] Quality; //EdkDll.IS_GetContactQualityFromAllChannels(this.eState, out Quality); //ContactQuality = new int[Quality.Length]; /*for (int i = 0; i < Quality.Length; i++) * { * //ContactQuality[i] = (int)Quality[i]; * * //Debug.Write(Quality[i]+ ", "); * }*/ //Debug.WriteLine(""); int state = EdkDll.IEE_EngineGetNextEvent(eEvent); if (state == EdkDll.EDK_OK) { var eventType = EdkDll.IEE_EmoEngineEventGetType(eEvent); //EdkDll.IEE_EmoEngineEventGetUserId(eEvent, engineUserID); //Debug.WriteLine(engineUserID); if (eventType == EdkDll.IEE_Event_t.IEE_EmoStateUpdated) { /* for (int i = 0; i < Quality.Length; i++) * { * //ContactQuality[i] = (int)Quality[i]; * * Debug.Write((int)Quality[i] + ", "); * } * * Debug.WriteLine("");*/ int newState = EdkDll.IEE_EmoEngineEventGetEmoState(eEvent, eState); var act = EdkDll.IS_GetWirelessSignalStatus(eState); EdkDll.IEE_MentalCommandAction_t currentAction = EdkDll.IS_MentalCommandGetCurrentAction(eState); float currentPower = EdkDll.IS_MentalCommandGetCurrentActionPower(eState); return(new EmotivState((EmotivCommandType)currentAction, currentPower, time)); } } return(new EmotivState(EmotivCommandType.NULL, 0f, time)); }
public void engine_MentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs e) { EmoState es = e.emoState; Single timeFromStart = es.GetTimeFromStart(); EdkDll.IEE_MentalCommandAction_t cogAction = es.MentalCommandGetCurrentAction(); Single power = es.MentalCommandGetCurrentActionPower(); Boolean isActive = es.MentalCommandIsActive(); _eventModel.CogAction = (int)cogAction; _eventModel.CogPower = power; Console.WriteLine("{0},{1},{2},{3}", timeFromStart, cogAction, power, isActive); }
static void engine_MentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs e) { EmoState es = e.emoState; Single timeFromStart = es.GetTimeFromStart(); EdkDll.IEE_MentalCommandAction_t cogAction = es.MentalCommandGetCurrentAction(); Single power = es.MentalCommandGetCurrentActionPower(); Boolean isActive = es.MentalCommandIsActive(); cogLog.WriteLine( "{0},{1},{2},{3}", timeFromStart, cogAction, power, isActive); cogLog.Flush(); }
void onMentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs args) { if (training) { return; } EdkDll.IEE_MentalCommandAction_t action = args.emoState.MentalCommandGetCurrentAction(); Debug.Log("current action: " + action.ToString()); switch (action) { case EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL: cube.action = 0; status.text = "CurrentAction: Neutral"; break; case EdkDll.IEE_MentalCommandAction_t.MC_PUSH: cube.action = 1; status.text = "CurrentAction: Pushing"; break; } }
static void engine_MentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs e) { isNotResponding = false; EmoState es = e.emoState; EdkDll.IEE_MentalCommandAction_t cogAction = es.MentalCommandGetCurrentAction(); float power = (float)es.MentalCommandGetCurrentActionPower(); for (int i = 1; i < MentalCommandActionList.Length; i++) { if (cogAction == MentalCommandActionList[i]) { MentalCommandActionPower[i] = power; } else { MentalCommandActionPower[i] = 0; } } }
public void FireMentalCommand(EdkDll.IEE_MentalCommandAction_t command, float power) { foreach (var item in new[] { new { cmd = EdkDll.IEE_MentalCommandAction_t.MC_LEFT, state = commandStateLeft }, new { cmd = EdkDll.IEE_MentalCommandAction_t.MC_RIGHT, state = commandStateRight }, new { cmd = EdkDll.IEE_MentalCommandAction_t.MC_PUSH, state = commandStateTurn }, new { cmd = EdkDll.IEE_MentalCommandAction_t.MC_PULL, state = commandStateDrop } }) { item.state.FireEvents(command == item.cmd ? power : 0f); } foreach (var item in new[] { new { bar = barPwrLeft, state = commandStateLeft }, new { bar = barPwrRight, state = commandStateRight }, new { bar = barPwrTurn, state = commandStateTurn }, new { bar = barPwrDrop, state = commandStateDrop } }) { item.bar.Value = item.state.PwrInt; } }
/// <summary> /// Event function called when EmoEngine detects new mental command /// Updates current action for UI and moves current block /// </summary> void OnMentalCommandEmoStateUpdated(object sender, EmoStateUpdatedEventArgs args) { Debug.Log("Main " + transform.tag + ": State Updated"); EdkDll.IEE_MentalCommandAction_t action = args.emoState.MentalCommandGetCurrentAction(); switch (action) { case EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL: mentalAction = 0; Debug.Log("Mental Command: Neutral"); break; case EdkDll.IEE_MentalCommandAction_t.MC_RIGHT: mentalAction = 1; Debug.Log("Mental Command: right"); break; case EdkDll.IEE_MentalCommandAction_t.MC_LEFT: mentalAction = 2; Debug.Log("Mental Command: left"); break; } }
/* * Several methods for handling the EmoEngine events. * They are self explanatory. */ public void SetTraining(EdkDll.IEE_MentalCommandAction_t training) { engine.MentalCommandSetTrainingAction((uint)engineUserID, training); //engine.MentalCommandSetTrainingControl((uint)engineUserID, EdkDll.IEE_MentalCommandTrainingControl_t.MC_START); }
public void AddActiveCommand(EdkDll.IEE_MentalCommandAction_t command) { EdkDll.IEE_MentalCommandSetActiveActions((uint)engineUserID, (ulong)command); //GetActiveActions(); }
public static void StartTraining(EdkDll.IEE_MentalCommandAction_t command) { EmoEngine.Instance.MentalCommandSetTrainingAction(userID, command); EmoEngine.Instance.MentalCommandSetTrainingControl(userID, EdkDll.IEE_MentalCommandTrainingControl_t.MC_START); }
public void ResetTraining(EdkDll.IEE_MentalCommandAction_t command) { EdkDll.IEE_MentalCommandSetTrainingAction((uint)engineUserID, command); EdkDll.IEE_MentalCommandSetTrainingControl((uint)engineUserID, EdkDll.IEE_MentalCommandTrainingControl_t.MC_RESET); }
/// <summary> /// Erases ment command training data /// </summary> /// <param name="action">Action to be erased</param> void EraseAction(EdkDll.IEE_MentalCommandAction_t action) { EdkDll.IEE_MentalCommandSetTrainingAction((uint)EmoUserManagement.currentUser, action); EdkDll.IEE_MentalCommandSetTrainingControl((uint)EmoUserManagement.currentUser, EdkDll.IEE_MentalCommandTrainingControl_t.MC_ERASE); }
//This function is called every time the emo state is updated. The tickTimer is there so that the functions are not all called every single update, but rather only // after a fixed amount of time. If the ticks are used, it means that each fixed amount of second (1 by defaul, setted by the endTime variable) the current emo state // is compared with the previous one, if it's the same, a emoStateTick is added, if it's different, it resets to 0. So, for example, if you keep the same emo state for // four seconds, you would get four emoStateTicks. // Then, using the overloaded version of ActionConditionEmotiv with the ticks parameter, you can set how many ticks you want the action to be triggered. //Say, for example, you set the PUSH command to trigger an action with 2 ticks, so for said action to be triggered the user needs to be focused for 2 seconds on // the same mental command. Then you can use the PULL command to trigger an action with 4 ticks for example, to completely avoid any unwanted triggering of the function. // //The ticks update very second, but this time is a float value, you can lower (or increase) this as much as you want. At endTime 0.5f for example, you could use 5 ticks so that // the mental command needs to be active for 2.5 seconds. // //In order to allow for mistakes caused either by lack of concentration, distractions or equipment, a emoStateTicksMistake counter is set. If, for example, the user needs 4 ticks with the // Push command, has 3 ticks and when the 4º arrives the mental command is Lift, the emoStateTick will not reset nor rise, but the emoStateTickMistake will be reduced. So if in the next // tick the user goes back to Push, it'll trigger the fourth tick, otherwise the mistake counter will continue to rise until it reaches the amount specified in the ActiveConditionEmotiv function, // in which case no more mistakes are allowed and the tick counter resets. The mistake counter is reseted once a new command intention is detected public void EmoStateUpdate() { //Debug.Log(EEGManager.Instance.mentalCommand); float elapsedTime = Time.unscaledTime - startTime; tickTimer = endTime - elapsedTime; if (tickTimer <= 0f) { if (EEGManager.Instance.MentalCommandCurrentAction == previousCommand) { if (emoStateTicks == 0) { //new mental command intention detected //If this new command is neutral, it's not stored as current (as it should not have any actions attached) if (EEGManager.Instance.MentalCommandCurrentAction != EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL) { currentCommand = EEGManager.Instance.MentalCommandCurrentAction; emoStateTicks++; emoStateTicksMistakes = 0; emoStateNeutralTicking = 0; } } else if (EEGManager.Instance.MentalCommandCurrentAction == currentCommand) { emoStateTicks++; } else { emoStateTicksMistakes++; if (EEGManager.Instance.MentalCommandCurrentAction == EdkDll.IEE_MentalCommandAction_t.MC_NEUTRAL) { //This "if" exist only as a precaution. The reset condition for the tick variable exist only in the ActionConditionEmotiv function. If by any reason there is a // mental command that IS being detected but it has NOT been included into an ActionConditionEmotiv function, it will trigger an infinite loop that would prevent // any new mental commands to be triggered. To avoid any such case, the neutral command is used to reset the tick counter, regardless of the active action. emoStateNeutralTicking++; if (emoStateNeutralTicking > 6) { emoStateNeutralTicking = 0; emoStateTicks = 0; emoStateTicksMistakes = 0; } } } } else { if (EEGManager.Instance.MentalCommandCurrentAction == currentCommand) { emoStateTicks++; } else { emoStateTicksMistakes++; } } foreach (var function in updateActionsEmotivInsight) { function(); } previousCommand = EEGManager.Instance.MentalCommandCurrentAction; startTime = Time.unscaledTime; tickTimer = endTime; } }