private static void startMov1(object source, System.Timers.ElapsedEventArgs e) { DynaLinkHS.CmdTransparentControl(0.2f, 0.2f, 1.0f, 1.0f, 10.0f, 10.0f, 10.0f, 10.0f); DynaLinkHS.CmdServoOff(); SetYaml.LoadTaskInfo();// load .yaml file print("初始化完成,实验开始"); // first block set RunFSM.currState = RunFSM.GameState_Enum.STATE_BLOCKSET; }
public static void Break() { string blockName = SetYaml.taskNames[blockNum]; //save sEMG string fileNamesemg = SetYaml.subjectName + "_" + blockName + "_" + GlobalVar.sEMGCSVNAME + "_" + Convert.ToString(trials) + ".csv"; string csvfullemg = System.Environment.CurrentDirectory + "\\" + GlobalVar.expFolderName + "\\" + fileNamesemg; if (RunFSM.EMG.IsConnected()) { if (isEMGRecording == false) { RunFSM.EMG.StopRecording(csvfullemg); isEMGRecording = true; } } if (trials >= SetYaml.trialNum) { timeLine += Time.deltaTime; csvContent.AppendLine((float)timeLine + "," + trials + "," + "TrialBreak" + "," + DynaLinkHS.StatusRobot.PositionDataJoint1 + "," + DynaLinkHS.StatusRobot.PositionDataJoint2); //save kinematics string fileName = SetYaml.subjectName + "_" + blockName + "_" + GlobalVar.CSVNAME + ".csv"; string csvfullfilename = System.Environment.CurrentDirectory + "\\" + GlobalVar.expFolderName + "\\" + fileName; File.WriteAllText(csvfullfilename, "Time,Trial,State,PositionX,PositionY\n"); File.AppendAllText(csvfullfilename, csvContent.ToString()); // finish 4 blocks if (blockNum >= 3) { Application.Quit(); } else { RunFSM.currState = RunFSM.GameState_Enum.STATE_BLOCKSET; blockTimer = 5f; } } else { timeLine += Time.deltaTime; csvContent.AppendLine((float)timeLine + "," + trials + "," + "TrialBreak" + "," + DynaLinkHS.StatusRobot.PositionDataJoint1 + "," + DynaLinkHS.StatusRobot.PositionDataJoint2); breakTimer -= Time.deltaTime; // break timer -- if (breakTimer <= 0f) { DynaLinkHS.CmdServoOff(); DynaLinkHS.CmdTransparentControl(0.2f, 0.2f, 1.0f, 1.0f, 10.0f, 10.0f, 10.0f, 10.0f); // next trial set isCollisionOn = false; isCollisionOff = false; m2MoveTimer = 5f; RunFSM.currState = RunFSM.GameState_Enum.STATE_CMD2ROBOT; } } }
// Use this for initialization void Start() { DynaLinkHS.CmdTransparentControl(5f, 5f, 10f, 10f, 10f, 10f, 10f, 10f); //DynaLinkHS.CmdServoOff(); ///* // Initiate Hand Effector Position ///* screenSize = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)); // 尺寸的一半 print(screenSize); // screen size float M2_SIZE_X = (M2_AXIS_X[1] - M2_AXIS_X[0]) / 2; float M2_SIZE_Y = (M2_AXIS_Y[1] - M2_AXIS_Y[0]) / 2; xOffset = (screenSize.x) / M2_SIZE_X; yOffset = (screenSize.y) / M2_SIZE_Y; DynaLinkHS.CmdPassiveMovementControl((M2_AXIS_X[1] + M2_AXIS_X[0]) / 2, (M2_AXIS_Y[1] + M2_AXIS_Y[0]) / 2, (float)0.05); ///* // Initiate Control Mode(mass/damping/spring) /// for M2, the parameters are /// - origin/target position x [原始/目标位置 x 轴] (type : float, unit : m, range : ) /// - origin/target position y [原始/目标位置 y 轴] (type : float, unit : m, range : ) /// - M (mass) x [模拟质量 x 轴] (type : float, unit : kg, range : ) /// - M (mass) y [模拟质量 y 轴] (type : float, unit : kg, range : ) /// - B (damping) x [模拟阻尼 x 轴] (type : float, unit : N/(m/s), range : ) /// - B (damping) y [模拟阻尼 y 轴] (type : float, unit : N/(m/s), range : ) /// - K (spring) x [模拟弹簧 x 轴] (type : float, unit : N/m, range : ) /// - K (spring) y [模拟弹簧 y 轴] (type : float, unit : N/m, range : ) ///* ///* /// Renew/Load .yaml ///* //SetYaml.IniTaskInfo();// initiate .yaml SetYaml.LoadTaskInfo();// load .yaml timerStart = new Timer(); timerStart.Interval = 10000; //Wait for 10 seconds timerStart.Elapsed += GameStart; //Hook up the elapsed event for the timer timerStart.AutoReset = false; //Have the timer fire repeated events(true is the default) timerStart.Enabled = false; timerStart.Start(); }