public override void Tick(int currentTime) { if (currentTime == timeForNextDecision) { Action action = null; if (currentTime >= goalCheckTime) { action = level.GoalCheck(currentTime, this, currentTime >= loseTime); } //No goal related action follow schedule if (action == null) { for (int i = 0, length = schedule.Length; i < length; i++) { ScheduleEntry entry = schedule[i]; if (entry.time == currentTime) { action = entry.GetAction(currentTime); break; } } } //No schedule wait if (action == null) { action = new ActionWait(currentTime, 1, currentLocation); } AddAction(action); } }
private void Update() { if (Input.GetKeyUp(KeyCode.M)) { // Create Move GameObject go = new GameObject(string.Format("{0}_Move", _actions.Count)); ActionMove a = go.AddComponent <ActionMove>(); a.Direction = Vector3.right; a.Speed = 500.0f; a.Duration = 1.0f; Add(a); go.transform.SetParent(transform); } if (Input.GetKeyUp(KeyCode.W)) { GameObject go = new GameObject(string.Format("{0}_Wait", _actions.Count)); ActionWait w = go.AddComponent <ActionWait>(); w.Duration = 1.0f; Add(w); go.transform.SetParent(transform); } }
public void AddActionWait(float waitTime) { ActionWait action = new ActionWait { waitTime = waitTime }; this.AddAction(action); }
public void AddActionWait(float waitTime) { ActionWait action = new ActionWait { m_Entity = this.m_Entity, waitTime = waitTime }; this.AddAction(action); }
private void ThreadPoolAction(object state) { //2、 //Thread.Sleep(500); //Invoke(new Action(() => //{ // DialogResult = DialogResult.OK; //})); //1、 ActionWait?.Invoke(); Thread.Sleep(1000); Invoke(new Action(() => { DialogResult = DialogResult.OK; })); }
public override bool UrgentAction(out ActorAction?ret) { ret = null; if (m_Plan.IsExpired) { return(true); // expired } if (!m_Plan.IsLegal()) { _isExpired = true; return(true); } if (m_Plan.IsRelevant(m_Actor.Location)) { ret = m_Plan.Bind(m_Actor); if (null != ret) { if (m_Plan.IsExpired) { _isExpired = true; } return(true); } ret = new ActionWait(m_Actor); // not necessarily (crowd control issues) return(true); } var goals = m_Plan.Goals(m_Actor); if (null != goals) { #if DEBUG if (goals.Contains(m_Actor.Location)) { throw new InvalidOperationException("test case"); } #endif ret = (m_Actor.Controller as ObjectiveAI).BehaviorPathTo(goals); return(null != ret); } return(false); }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { LoadLevel(currentLevel); return; // SceneManager.LoadScene( SceneManager.GetActiveScene().name ); } if (Input.GetKeyDown(KeyCode.Z)) { UndoLastAction(); } if (Input.GetKeyDown(KeyCode.R)) { Ripple(); } for (int i = 1, length = levels.Length; i <= length; i++) { if (Input.GetKeyDown(i.ToString())) { LoadLevel(levels[i - 1]); return; } } if (paradoxFound || levelComplete) { return; } if (currentTime == timeForNextDecision && Input.GetKeyDown(KeyCode.Space)) { ActionWait actionWait = new ActionWait(currentTime, 1, currentPlayer.GetCurrentLocation()); AddAction(actionWait); } Progress(); }
private List <ConstrucableTrigger> getActionTemplates() { List <ConstrucableTrigger> lst = new List <ConstrucableTrigger>(); lst.Add(new ConstrucableTriggerTemplate("Center View", () => new ActionCenterView(new WeakParser(ActionCenterView.getComponents(), ActionCenterView.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Comment", () => new ActionComment(new WeakParser(ActionComment.getComponents(), ActionComment.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Create Unit", () => new ActionCreateUnit(new WeakParser(ActionCreateUnit.getComponents(), ActionCreateUnit.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Create Unit With Properties", () => new ActionCreateUnitWithProperties(new WeakParser(ActionCreateUnitWithProperties.getComponents(), ActionCreateUnitWithProperties.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Defeat", () => new ActionDefeat(new WeakParser(ActionDefeat.getComponents(), ActionDefeat.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Display Text Message", () => new ActionDisplayTextMessage(new WeakParser(ActionDisplayTextMessage.getComponents(), ActionDisplayTextMessage.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Draw", () => new ActionDraw(new WeakParser(ActionDraw.getComponents(), ActionDraw.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Give Units To Player", () => new ActionGiveUnitsToPlayer(new WeakParser(ActionGiveUnitsToPlayer.getComponents(), ActionGiveUnitsToPlayer.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Kill Unit", () => new ActionKillUnit(new WeakParser(ActionKillUnit.getComponents(), ActionKillUnit.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Kill Unit At Location", () => new ActionKillUnitAtLocation(new WeakParser(ActionKillUnitAtLocation.getComponents(), ActionKillUnitAtLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Control At Location", () => new ActionLeaderBoardControlAtLocation(new WeakParser(ActionLeaderBoardControlAtLocation.getComponents(), ActionLeaderBoardControlAtLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Control", () => new ActionLeaderBoardControl(new WeakParser(ActionLeaderBoardControl.getComponents(), ActionLeaderBoardControl.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Deaths", () => new ActionLeaderBoardDeaths(new ActionLeaderBoardKills(new WeakParser(ActionLeaderBoardKills.getComponents(), ActionLeaderBoardKills.getTextMapping()))))); lst.Add(new ConstrucableTriggerTemplate("Leader board Greed", () => new ActionLeaderboardGreed(new WeakParser(ActionLeaderboardGreed.getComponents(), ActionLeaderboardGreed.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Kills", () => new ActionLeaderBoardKills(new WeakParser(ActionLeaderBoardKills.getComponents(), ActionLeaderBoardKills.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Points", () => new ActionLeaderBoardPoints(new WeakParser(ActionLeaderBoardPoints.getComponents(), ActionLeaderBoardPoints.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Resources", () => new ActionLeaderBoardResources(new WeakParser(ActionLeaderBoardResources.getComponents(), ActionLeaderBoardResources.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Computer Players", () => new ActionLeaderboardComputerPlayers(new WeakParser(ActionLeaderboardComputerPlayers.getComponents(), ActionLeaderboardComputerPlayers.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Goal Control At Location", () => new ActionLeaderboardGoalControlAtLocation(new WeakParser(ActionLeaderboardGoalControlAtLocation.getComponents(), ActionLeaderboardGoalControlAtLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Goal Control", () => new ActionLeaderboardGoalControl(new WeakParser(ActionLeaderboardGoalControl.getComponents(), ActionLeaderboardGoalControl.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Goal Kills", () => new ActionLeaderboardGoalKills(new WeakParser(ActionLeaderboardGoalKills.getComponents(), ActionLeaderboardGoalKills.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Goal Points", () => new ActionLeaderboardGoalPoints(new WeakParser(ActionLeaderboardGoalPoints.getComponents(), ActionLeaderboardGoalPoints.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Leader Board Goal Resources", () => new ActionLeaderboardGoalResources(new WeakParser(ActionLeaderboardGoalResources.getComponents(), ActionLeaderboardGoalResources.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Minimap Ping", () => new ActionMinimapPing(new WeakParser(ActionMinimapPing.getComponents(), ActionMinimapPing.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Modify Unit Energy", () => new ActionModifyUnitEnergy(new WeakParser(ActionModifyUnitEnergy.getComponents(), ActionModifyUnitEnergy.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Modify Unit Hanger Count", () => new ActionModifyUnitHangerCount(new WeakParser(ActionModifyUnitHangerCount.getComponents(), ActionModifyUnitHangerCount.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Modify Unit Hit Points", () => new ActionModifyUnitHitPoints(new WeakParser(ActionModifyUnitHitPoints.getComponents(), ActionModifyUnitHitPoints.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Modify Unit Resource Amount", () => new ActionModifyUnitResourceAmount(new WeakParser(ActionModifyUnitResourceAmount.getComponents(), ActionModifyUnitResourceAmount.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Modify Unit Shield Points", () => new ActionModifyUnitShieldPoints(new WeakParser(ActionModifyUnitShieldPoints.getComponents(), ActionModifyUnitShieldPoints.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Move Location", () => new ActionMoveLocation(new WeakParser(ActionMoveLocation.getComponents(), ActionMoveLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Play WAV", () => new ActionPlayWAV(new WeakParser(ActionPlayWAV.getComponents(), ActionPlayWAV.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Move Unit", () => new ActionMoveUnit(new WeakParser(ActionMoveUnit.getComponents(), ActionMoveUnit.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Mute Unit Speech", () => new ActionMuteUnitSpeech(new WeakParser(ActionMuteUnitSpeech.getComponents(), ActionMuteUnitSpeech.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Order", () => new ActionOrder(new WeakParser(ActionOrder.getComponents(), ActionOrder.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Pause Game", () => new ActionPauseGame(new WeakParser(ActionPauseGame.getComponents(), ActionPauseGame.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Pause Timer", () => new ActionPauseTimer(new WeakParser(ActionPauseTimer.getComponents(), ActionPauseTimer.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Preserve Trigger", () => new ActionPreserveTrigger(new WeakParser(ActionPreserveTrigger.getComponents(), ActionPreserveTrigger.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Remove Unit", () => new ActionRemoveUnit(new WeakParser(ActionRemoveUnit.getComponents(), ActionRemoveUnit.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Remove Unit At Location", () => new ActionRemoveUnitAtLocation(new WeakParser(ActionRemoveUnitAtLocation.getComponents(), ActionRemoveUnitAtLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Run AI Script", () => new ActionRunAIScript(new WeakParser(ActionRunAIScript.getComponents(), ActionRunAIScript.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Run AI Script At Location", () => new ActionRunAIScriptAtLocation(new WeakParser(ActionRunAIScriptAtLocation.getComponents(), ActionRunAIScriptAtLocation.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Alliance Status", () => new ActionSetAllianceStatus(new WeakParser(ActionSetAllianceStatus.getComponents(), ActionSetAllianceStatus.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Countdown Timer", () => new ActionSetCountdownTimer(new WeakParser(ActionSetCountdownTimer.getComponents(), ActionSetCountdownTimer.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Doodad State", () => new ActionSetDoodadState(new WeakParser(ActionSetDoodadState.getComponents(), ActionSetDoodadState.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Deaths", () => new ActionSetDeaths(new RawActionSetDeaths(new WeakParser(RawActionSetDeaths.getComponents(), RawActionSetDeaths.getTextMapping()))))); lst.Add(new ConstrucableTriggerTemplate("Set Invincibility", () => new ActionSetInvincibility(new WeakParser(ActionSetInvincibility.getComponents(), ActionSetInvincibility.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Mission Objectives", () => new ActionSetMissionObjectives(new WeakParser(ActionSetMissionObjectives.getComponents(), ActionSetMissionObjectives.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Next Scenario", () => new ActionSetNextScenario(new WeakParser(ActionSetNextScenario.getComponents(), ActionSetNextScenario.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Resources", () => new ActionSetResources(new WeakParser(ActionSetResources.getComponents(), ActionSetResources.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Score", () => new ActionSetScore(new WeakParser(ActionSetScore.getComponents(), ActionSetScore.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Set Switch", () => new ActionSetSwitch(new WeakParser(ActionSetSwitch.getComponents(), ActionSetSwitch.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Talking Portrait", () => new ActionTalkingPortrait(new WeakParser(ActionTalkingPortrait.getComponents(), ActionTalkingPortrait.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Transmission", () => new ActionTransmission(new WeakParser(ActionTransmission.getComponents(), ActionTransmission.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Unmute Unit Speech", () => new ActionUnmuteUnitSpeech(new WeakParser(ActionUnmuteUnitSpeech.getComponents(), ActionUnmuteUnitSpeech.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Unpause Game", () => new ActionUnpauseGame(new WeakParser(ActionUnpauseGame.getComponents(), ActionUnpauseGame.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Unpause Timer", () => new ActionUnpauseTimer(new WeakParser(ActionUnpauseTimer.getComponents(), ActionUnpauseTimer.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Victory", () => new ActionVictory(new WeakParser(ActionVictory.getComponents(), ActionVictory.getTextMapping())))); lst.Add(new ConstrucableTriggerTemplate("Wait", () => new ActionWait(new WeakParser(ActionWait.getComponents(), ActionWait.getTextMapping())))); EPDAction.fillConstructables(lst); return(lst); }
public override byte[] GetBytesForNextAction(RobotCursor cursor) { if (!cursor.ApplyNextAction(out _action)) { return(null); // cursor buffer is empty } _params = null; switch (_action.Type) { case ActionType.Translation: case ActionType.Rotation: case ActionType.Transformation: RotationVector rv = cursor.rotation.AA.ToRotationVector(); _params = new int[] { _action.Id, cursor.motionType == MotionType.Joint ? INST_MOVEJ_P : INST_MOVEL, (int)Math.Round(cursor.position.X * 0.001 * FACTOR_M), (int)Math.Round(cursor.position.Y * 0.001 * FACTOR_M), (int)Math.Round(cursor.position.Z * 0.001 * FACTOR_M), (int)Math.Round(rv.X * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(rv.Y * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(rv.Z * Geometry.TO_RADS * FACTOR_RAD) }; // Workaround to SW3.0 crash problem: https://github.com/RobotExMachina/Machina.NET/issues/7 if (ZERO_PRECISION_ON_SAME_POSITION_MOTION && cursor.precision != 0 && cursor.prevPosition != null && cursor.position.IsSimilar(cursor.prevPosition)) { Logger.Debug("Applying ZERO_PRECISION_ON_SAME_POSITION_MOTION"); _params = WrapParamsWithZeroPrecision(_params, cursor); } break; case ActionType.Axes: _params = new int[] { _action.Id, INST_MOVEJ_Q, (int)Math.Round(cursor.axes.J1 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.axes.J2 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.axes.J3 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.axes.J4 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.axes.J5 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.axes.J6 * Geometry.TO_RADS * FACTOR_RAD), }; // Another ZERO_PRECISION_ON_SAME_POSITION_MOTION check should happen here for 6th axis rotation only... break; case ActionType.Wait: ActionWait aa = _action as ActionWait; _params = new int[] { _action.Id, INST_SLEEP, (int)Math.Round(aa.millis * 0.001 * FACTOR_SEC) }; break; // Not implemented yet //case ActionType.Message: // ActionMessage am = (ActionMessage)action; // dec = string.Format(" popup(\"{0}\", title=\"Machina Message\", warning=False, error=False)", // am.message); // break; case ActionType.AttachTool: //ActionAttachTool aatt = _action as ActionAttachTool; //Tool t = aatt.tool; Tool t = cursor.tool; // can cursor.tool be null? The action would have not gone through if there wasn't a tool available for attachment, right? RotationVector trv = t.TCPOrientation.ToRotationVector(); _params = new int[] { _action.Id, INST_SET_TOOL, (int)Math.Round(t.TCPPosition.X * 0.001 * FACTOR_M), (int)Math.Round(t.TCPPosition.Y * 0.001 * FACTOR_M), (int)Math.Round(t.TCPPosition.Z * 0.001 * FACTOR_M), (int)Math.Round(trv.X * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(trv.Y * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(trv.Z * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(t.Weight * FACTOR_KG) }; break; case ActionType.DetachTool: _params = new int[] { _action.Id, INST_SET_TOOL, 0, 0, 0, 0, 0, 0, 0 }; break; case ActionType.IODigital: ActionIODigital aiod = _action as ActionIODigital; _params = new int[] { _action.Id, INST_SET_DIGITAL_OUT, aiod.pinNum, aiod.on ? 1 : 0, aiod.isToolPin ? 1 : 0 }; break; case ActionType.IOAnalog: ActionIOAnalog aioa = _action as ActionIOAnalog; _params = new int[] { _action.Id, INST_SET_ANALOG_OUT, aioa.pinNum, (int)Math.Round(aioa.value * FACTOR_VOLT) //aioa.isToolPin ? 1 : 0 // there is no analog out on the tool }; break; // ╔═╗╔═╗╔╦╗╔╦╗╦╔╗╔╔═╗╔═╗ // ╚═╗║╣ ║ ║ ║║║║║ ╦╚═╗ // ╚═╝╚═╝ ╩ ╩ ╩╝╚╝╚═╝╚═╝ // Speed is now set globally, and the driver takes care of translating that internally case ActionType.Speed: _params = new int[] { _action.Id, INST_ALL_SPEED, (int)Math.Round(cursor.speed * 0.001 * FACTOR_M) }; break; // Idem for acceleration case ActionType.Acceleration: _params = new int[] { _action.Id, INST_ALL_ACC, (int)Math.Round(cursor.acceleration * 0.001 * FACTOR_M) }; break; case ActionType.Precision: _params = new int[] { _action.Id, INST_BLEND, (int)Math.Round(cursor.precision * 0.001 * FACTOR_M) }; break; case ActionType.PushPop: ActionPushPop app = _action as ActionPushPop; if (app.push) { break; } Settings beforePop = cursor.settingsBuffer.SettingsBeforeLastPop; Dictionary <int, int> poppedSettings = new Dictionary <int, int>(); // These are the states kept in the controller as of v1.0 of the driver //if (beforePop.Speed != cursor.speed) // poppedSettings.Add(INST_TCP_SPEED, (int)Math.Round(cursor.speed * 0.001 * FACTOR_M)); //if (beforePop.Acceleration != cursor.acceleration) // poppedSettings.Add(INST_TCP_ACC, (int)Math.Round(cursor.acceleration * 0.001 * FACTOR_M)); //if (beforePop.JointSpeed != cursor.jointSpeed) // poppedSettings.Add(INST_Q_SPEED, (int)Math.Round(cursor.jointSpeed * Geometry.TO_RADS * FACTOR_RAD)); //if (beforePop.JointAcceleration != cursor.jointAcceleration) // poppedSettings.Add(INST_Q_ACC, (int)Math.Round(cursor.jointAcceleration * Geometry.TO_RADS * FACTOR_RAD)); // These are the states kept in the controller as of v1.0 of the driver if (beforePop.Speed != cursor.speed) { poppedSettings.Add(INST_ALL_SPEED, (int)Math.Round(cursor.speed * 0.001 * FACTOR_M)); } if (beforePop.Acceleration != cursor.acceleration) { poppedSettings.Add(INST_ALL_ACC, (int)Math.Round(cursor.acceleration * 0.001 * FACTOR_M)); } if (beforePop.Precision != cursor.precision) { poppedSettings.Add(INST_BLEND, (int)Math.Round(cursor.precision * 0.001 * FACTOR_M)); } // Generate a buffer with all instructions, ids of -1 except for the last one. _params = new int[3 * poppedSettings.Count]; int it = 0; foreach (var setting in poppedSettings) { _params[3 * it] = it == poppedSettings.Count - 1 ? app.Id : -1; // only attach the real id to the last instruction _params[3 * it + 1] = setting.Key; _params[3 * it + 2] = setting.Value; it++; } break; case ActionType.Coordinates: throw new NotImplementedException(); // @TODO: this should also change the WObj, but not on it yet... //// Send comma-separated integers //case ActionType.CustomCode: // ActionCustomCode acc = _action as ActionCustomCode; // int[] values; // if (Numeric.CommaSeparatedStringToInts(out values)) // { // } // else // { // Logger.Warning("Invalid CustomCode: please use a string of comma-separated integers, like \"1,); // } // break; // If the Action wasn't on the list above, it doesn't have a message representation... default: Logger.Verbose("Cannot stream action `" + _action + "`"); return(null); } if (_params == null) { return(null); } _buffer = Utilities.Conversion.Int32ArrayToByteArray(_params, false); return(_buffer); }
void Sample2() { machine = new Machine(); Parameter round = new Parameter(0); machine.SetParameter("round", round); // 基本规则 // 吃饱了运动,运动累了睡,睡醒了吃 // 1. 定义状态 // 睡觉的状态 // ActionWait会调用doFinish,所以当行为完成时,调用状态的默认的Finish行为 State stateSleep = machine.NewState(); ActionWait actionWaitSleep = stateSleep.NewAction <ActionWait>(); actionWaitSleep.seconds = 6; actionWaitSleep.owner = "Sleep"; // 吃的状态 // ActionWait会调用doFinish,所以当行为完成时,调用状态的默认的Finish行为 State stateEat = machine.NewState(); ActionWait actionWaitEatRice = stateEat.NewAction <ActionWait>(); actionWaitEatRice.seconds = 2; actionWaitEatRice.owner = "Eate.Rice"; ActionWait actionWaitEatMeat = stateEat.NewAction <ActionWait>(); actionWaitEatMeat.seconds = 6; actionWaitEatMeat.owner = "Eate.Meat"; // 走的状态 // ActionWait会调用doFinish,所以当行为完成时,调用状态的默认的Finish行为 State stateWalk = machine.NewState(); ActionWait actionWaitWalk = stateWalk.NewAction <ActionWait>(); actionWaitWalk.seconds = 3; actionWaitWalk.owner = "Walk"; stateWalk.NewAction <ActionAddRound>(); // 跑的状态 // ActionWait会调用doFinish,所以当行为完成时,调用状态的默认的Finish行为 State stateRun = machine.NewState(); ActionWait actionWaitRun = stateRun.NewAction <ActionWait>(); actionWaitRun.seconds = 1.5f; actionWaitRun.owner = "Run"; stateRun.NewAction <ActionAddRound>(); // 跳的状态 // ActionWait会调用doFinish,所以当行为完成时,调用状态的默认的Finish行为 State stateJump = machine.NewState(); ActionWait actionWaitJump = stateJump.NewAction <ActionWait>(); actionWaitJump.seconds = 3; actionWaitJump.owner = "Jump"; stateJump.NewAction <ActionAddRound>(); // 思考的状态 // ActionRand没有调用doFinish,而是执行了指定的命令,所以不会调用状态的默认的Finish行为 State stateThink = machine.NewState(); ActionRand actionRand = stateThink.NewAction <ActionRand>(); actionRand.cmd1 = machine.NewInternalCommand("Run"); actionRand.cmd2 = machine.NewInternalCommand("Walk"); actionRand.owner = "Think"; // 2. 关联状态 // stateThink中的行为执行了指定的命令,所以不需要指定默认Finish行为的状态 stateEat.finishAction.state = stateThink; actionRand.cmd1.state = stateRun; actionRand.cmd2.state = stateJump; actionRand.finishCommand.state = stateWalk; stateRun.finishAction.state = stateSleep; stateWalk.finishAction.state = stateSleep; stateJump.finishAction.state = stateSleep; stateSleep.finishAction.state = stateEat; // 3. 设置初始状态 machine.startupCommand.state = stateSleep; // 4. 运行状态机 machine.Run(); }
internal const char STR_MESSAGE_RESPONSE_CHAR = '$'; // Flags a message as a response to an information request(acknowledgments do not include it) /// <summary> /// Given an Action and a RobotCursor representing the state of the robot after application, /// return a List of strings with the messages necessary to perform this Action adhering to /// the Machina-ABB-Server protocol. /// </summary> /// <param name="action"></param> /// <param name="cursor"></param> /// <returns></returns> internal override List <string> GetActionMessages(Action action, RobotCursor cursor) { List <string> msgs = new List <string>(); switch (action.Type) { case ActionType.Translation: case ActionType.Rotation: case ActionType.Transformation: //// MoveL/J X Y Z QW QX QY QZ msgs.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1} {2} {3} {4} {5} {6} {7} {8} {9}{10}", STR_MESSAGE_ID_CHAR, action.Id, cursor.motionType == MotionType.Linear ? INST_MOVEL : INST_MOVEJ, Math.Round(cursor.position.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.position.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.position.Z, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.rotation.Q.W, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.X, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.Y, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.Z, Geometry.STRING_ROUND_DECIMALS_QUAT), STR_MESSAGE_END_CHAR)); break; case ActionType.Axes: // MoveAbsJ J1 J2 J3 J4 J5 J6 msgs.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1} {2} {3} {4} {5} {6} {7} {8}{9}", STR_MESSAGE_ID_CHAR, action.Id, INST_MOVEABSJ, Math.Round(cursor.axes.J1, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.axes.J2, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.axes.J3, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.axes.J4, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.axes.J5, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.axes.J6, Geometry.STRING_ROUND_DECIMALS_DEGS), STR_MESSAGE_END_CHAR)); break; case ActionType.Speed: // (setspeed V_TCP[V_ORI V_LEAX V_REAX]) msgs.Add(Invariant($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_SPEED} {cursor.speed}{STR_MESSAGE_END_CHAR}")); // this accepts more velocity params, but those are still not implemented in Machina... break; case ActionType.Acceleration: Logger.Debug("Acceleration not implemented in ABBCommunicationProtocol"); break; case ActionType.Precision: // (setzone FINE TCP[ORI EAX ORI LEAX REAX]) msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_ZONE} {cursor.precision}{STR_MESSAGE_END_CHAR}"); // this accepts more zone params, but those are still not implemented in Machina... break; case ActionType.Wait: // !WaitTime T ActionWait aw = (ActionWait)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_WAITTIME} {0.001 * aw.millis}{STR_MESSAGE_END_CHAR}"); break; case ActionType.Message: // !TPWrite "MSG" ActionMessage am = (ActionMessage)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_TPWRITE} \"{am.message}\"{STR_MESSAGE_END_CHAR}"); break; case ActionType.AttachTool: // !(settool X Y Z QW QX QY QZ KG CX CY CZ) //ActionAttachTool aa = (ActionAttachTool)action; //Tool t = aa.tool; Tool t = cursor.tool; // @TODO: should I just pull from the library? need to rethink the general approach: take info from cursor state (like motion actions) or action data... msgs.Add(string.Format("{0}{1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13}{14}", STR_MESSAGE_ID_CHAR, action.Id, INST_TOOL, Math.Round(t.TCPPosition.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPPosition.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPPosition.Z, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPOrientation.Q.W, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.X, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.Y, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.Z, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.Weight, Geometry.STRING_ROUND_DECIMALS_KG), Math.Round(t.CenterOfGravity.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.CenterOfGravity.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.CenterOfGravity.Z, Geometry.STRING_ROUND_DECIMALS_MM), STR_MESSAGE_END_CHAR)); break; case ActionType.DetachTool: // !(settool0) msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_NOTOOL}{STR_MESSAGE_END_CHAR}"); break; case ActionType.IODigital: // !SetDO "NAME" ON ActionIODigital aiod = (ActionIODigital)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_SETDO} \"{aiod.pinName}\" {(aiod.on ? 1 : 0)}{STR_MESSAGE_END_CHAR}"); break; case ActionType.IOAnalog: // !SetAO "NAME" V ActionIOAnalog aioa = (ActionIOAnalog)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_SETAO} \"{aioa.pinName}\" {aioa.value}{STR_MESSAGE_END_CHAR}"); break; case ActionType.PushPop: ActionPushPop app = action as ActionPushPop; if (app.push) { return(null); } else { // Only precision, speed and acceleration are states kept on the controller Settings beforePop = cursor.settingsBuffer.SettingsBeforeLastPop; if (beforePop.Speed != cursor.speed) { msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_SPEED} {cursor.speed}{STR_MESSAGE_END_CHAR}"); } if (beforePop.Acceleration != cursor.acceleration) { msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_ACCELERATION} {cursor.acceleration}{STR_MESSAGE_END_CHAR}"); } if (beforePop.Precision != cursor.precision) { msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.Id} {INST_ZONE} {cursor.precision}{STR_MESSAGE_END_CHAR}"); } } break; case ActionType.Coordinates: throw new NotImplementedException(); // @TODO: this should also change the WObj, but not on it yet... case ActionType.ExternalAxis: string msg, @params, id; ActionExternalAxis aea = action as ActionExternalAxis; // Cartesian msg if (aea.target == ExternalAxesTarget.All || aea.target == ExternalAxesTarget.Cartesian) { if (aea.target == ExternalAxesTarget.All) { id = "0"; // If will need to send two messages, only add real id to the last one. } else { id = aea.Id.ToString(); } @params = ExternalAxesToParameters(cursor.externalAxesCartesian); msg = $"{STR_MESSAGE_ID_CHAR}{id} {INST_EXT_JOINTS_ROBTARGET} {@params}{STR_MESSAGE_END_CHAR}"; msgs.Add(msg); } // Joints msg if (aea.target == ExternalAxesTarget.All || aea.target == ExternalAxesTarget.Joint) { id = aea.Id.ToString(); // now use the real id in any case @params = ExternalAxesToParameters(cursor.externalAxesJoints); msg = $"{STR_MESSAGE_ID_CHAR}{id} {INST_EXT_JOINTS_JOINTTARGET} {@params}{STR_MESSAGE_END_CHAR}"; msgs.Add(msg); } break; case ActionType.ArmAngle: // Send a request to change only the robtarget portion of the external axes for next motion. ActionArmAngle aaa = action as ActionArmAngle; msgs.Add(string.Format("{0}{1} {2} {3} 9E9 9E9 9E9 9E9 9E9{4}", STR_MESSAGE_ID_CHAR, action.Id, INST_EXT_JOINTS_ROBTARGET, Math.Round(aaa.angle, Geometry.STRING_ROUND_DECIMALS_DEGS), STR_MESSAGE_END_CHAR)); break; // When connected live, this is used as a way to stream a message directly to the robot. Unsafe, but oh well... case ActionType.CustomCode: ActionCustomCode acc = action as ActionCustomCode; msgs.Add(acc.statement); break; // If the Action wasn't on the list above, it doesn't have a message representation... default: Logger.Warning("Cannot stream action `" + action + "`"); return(null); } return(msgs); }
public override byte[] GetBytesForNextAction(RobotCursor cursor) { if (!cursor.ApplyNextAction(out _action)) { return(null); // cursor buffer is empty } _params = null; switch (_action.type) { case ActionType.Translation: case ActionType.Rotation: case ActionType.Transformation: RotationVector rv = cursor.rotation.AA.ToRotationVector(); _params = new int[] { _action.id, cursor.motionType == MotionType.Joint ? INST_MOVEJ_P : INST_MOVEL, (int)Math.Round(cursor.position.X * 0.001 * FACTOR_M), (int)Math.Round(cursor.position.Y * 0.001 * FACTOR_M), (int)Math.Round(cursor.position.Z * 0.001 * FACTOR_M), (int)Math.Round(rv.X * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(rv.Y * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(rv.Z * Geometry.TO_RADS * FACTOR_RAD) }; break; case ActionType.Axes: _params = new int[] { _action.id, INST_MOVEJ_Q, (int)Math.Round(cursor.joints.J1 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.joints.J2 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.joints.J3 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.joints.J4 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.joints.J5 * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(cursor.joints.J6 * Geometry.TO_RADS * FACTOR_RAD), }; break; case ActionType.Wait: ActionWait aa = _action as ActionWait; _params = new int[] { _action.id, INST_SLEEP, (int)Math.Round(aa.millis * 0.001 * FACTOR_SEC) }; break; // Not implemented yet //case ActionType.Message: // ActionMessage am = (ActionMessage)action; // dec = string.Format(" popup(\"{0}\", title=\"Machina Message\", warning=False, error=False)", // am.message); // break; case ActionType.Attach: ActionAttach aatt = _action as ActionAttach; Tool t = aatt.tool; RotationVector trv = t.TCPOrientation.ToRotationVector(); _params = new int[] { _action.id, INST_SET_TOOL, (int)Math.Round(t.TCPPosition.X * 0.001 * FACTOR_M), (int)Math.Round(t.TCPPosition.Y * 0.001 * FACTOR_M), (int)Math.Round(t.TCPPosition.Z * 0.001 * FACTOR_M), (int)Math.Round(trv.X * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(trv.Y * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(trv.Z * Geometry.TO_RADS * FACTOR_RAD), (int)Math.Round(t.Weight * FACTOR_M) }; break; case ActionType.Detach: _params = new int[] { _action.id, INST_SET_TOOL, 0, 0, 0, 0, 0, 0, 0 }; break; case ActionType.IODigital: ActionIODigital aiod = _action as ActionIODigital; _params = new int[] { _action.id, INST_SET_DIGITAL_OUT, aiod.pinNum, aiod.on ? 1 : 0 }; break; case ActionType.IOAnalog: ActionIOAnalog aioa = _action as ActionIOAnalog; _params = new int[] { _action.id, INST_SET_DIGITAL_OUT, aioa.pinNum, (int)Math.Round(aioa.value * FACTOR_VOLT) }; break; // ╔═╗╔═╗╔╦╗╔╦╗╦╔╗╔╔═╗╔═╗ // ╚═╗║╣ ║ ║ ║║║║║ ╦╚═╗ // ╚═╝╚═╝ ╩ ╩ ╩╝╚╝╚═╝╚═╝ case ActionType.Speed: _params = new int[] { _action.id, INST_TCP_SPEED, (int)Math.Round(cursor.speed * 0.001 * FACTOR_M) }; break; case ActionType.Acceleration: _params = new int[] { _action.id, INST_TCP_ACC, (int)Math.Round(cursor.acceleration * 0.001 * FACTOR_M) }; break; case ActionType.JointSpeed: _params = new int[] { _action.id, INST_Q_SPEED, (int)Math.Round(cursor.jointSpeed * Geometry.TO_RADS * FACTOR_RAD) }; break; case ActionType.JointAcceleration: _params = new int[] { _action.id, INST_Q_ACC, (int)Math.Round(cursor.jointAcceleration * Geometry.TO_RADS * FACTOR_RAD) }; break; case ActionType.Precision: _params = new int[] { _action.id, INST_BLEND, (int)Math.Round(cursor.precision * 0.001 * FACTOR_M) }; break; case ActionType.PushPop: ActionPushPop app = _action as ActionPushPop; if (app.push) { break; } Settings beforePop = cursor.settingsBuffer.SettingsBeforeLastPop; Dictionary <int, int> poppedSettings = new Dictionary <int, int>(); // These are the states kept in the controller as of v1.0 of the driver if (beforePop.Speed != cursor.speed) { poppedSettings.Add(INST_TCP_SPEED, (int)Math.Round(cursor.speed * 0.001 * FACTOR_M)); } if (beforePop.Acceleration != cursor.acceleration) { poppedSettings.Add(INST_TCP_ACC, (int)Math.Round(cursor.acceleration * 0.001 * FACTOR_M)); } if (beforePop.JointSpeed != cursor.jointSpeed) { poppedSettings.Add(INST_Q_SPEED, (int)Math.Round(cursor.jointSpeed * Geometry.TO_RADS * FACTOR_RAD)); } if (beforePop.JointAcceleration != cursor.jointAcceleration) { poppedSettings.Add(INST_Q_ACC, (int)Math.Round(cursor.jointAcceleration * Geometry.TO_RADS * FACTOR_RAD)); } if (beforePop.Precision != cursor.precision) { poppedSettings.Add(INST_BLEND, (int)Math.Round(cursor.precision * 0.001 * FACTOR_M)); } // Generate a buffer with all instructions, ids of -1 except for the last one. _params = new int[3 * poppedSettings.Count]; int it = 0; foreach (var setting in poppedSettings) { _params[3 * it] = it == poppedSettings.Count - 1 ? app.id : -1; // only attach the real id to the last instruction _params[3 * it + 1] = setting.Key; _params[3 * it + 2] = setting.Value; it++; } break; case ActionType.Coordinates: throw new NotImplementedException(); // @TODO: this should also change the WObj, but not on it yet... } if (_params == null) { return(null); } _buffer = Util.Int32ArrayToByteArray(_params, false); return(_buffer); }
internal const int RES_JOINTS = 22; // ">22 0 0 0 0 90 0;" // const int RES_EXTAX = 23; /// <summary> /// Given an Action and a RobotCursor representing the state of the robot after application, /// return a List of strings with the messages necessary to perform this Action adhering to /// the Machina-ABB-Server protocol. /// </summary> /// <param name="action"></param> /// <param name="cursor"></param> /// <returns></returns> internal override List <string> GetActionMessages(Action action, RobotCursor cursor) { List <string> msgs = new List <string>(); switch (action.type) { case ActionType.Translation: case ActionType.Rotation: case ActionType.Transformation: //// MoveL/J X Y Z QW QX QY QZ msgs.Add(string.Format("{0}{1} {2} {3} {4} {5} {6} {7} {8} {9}{10}", STR_MESSAGE_ID_CHAR, action.id, cursor.motionType == MotionType.Linear ? INST_MOVEL : INST_MOVEJ, Math.Round(cursor.position.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.position.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.position.Z, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(cursor.rotation.Q.W, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.X, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.Y, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(cursor.rotation.Q.Z, Geometry.STRING_ROUND_DECIMALS_QUAT), STR_MESSAGE_END_CHAR)); break; case ActionType.Axes: // MoveAbsJ J1 J2 J3 J4 J5 J6 msgs.Add(string.Format("{0}{1} {2} {3} {4} {5} {6} {7} {8}{9}", STR_MESSAGE_ID_CHAR, action.id, INST_MOVEABSJ, Math.Round(cursor.joints.J1, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.joints.J2, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.joints.J3, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.joints.J4, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.joints.J5, Geometry.STRING_ROUND_DECIMALS_DEGS), Math.Round(cursor.joints.J6, Geometry.STRING_ROUND_DECIMALS_DEGS), STR_MESSAGE_END_CHAR)); break; case ActionType.Speed: // (setspeed V_TCP[V_ORI V_LEAX V_REAX]) msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_SPEED} {cursor.speed}{STR_MESSAGE_END_CHAR}"); // this accepts more velocity params, but those are still not implemented in Machina... break; case ActionType.Precision: // (setzone FINE TCP[ORI EAX ORI LEAX REAX]) msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_ZONE} {cursor.precision}{STR_MESSAGE_END_CHAR}"); // this accepts more zone params, but those are still not implemented in Machina... break; case ActionType.Wait: // !WaitTime T ActionWait aw = (ActionWait)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_WAITTIME} {0.001 * aw.millis}{STR_MESSAGE_END_CHAR}"); break; case ActionType.Message: // !TPWrite "MSG" ActionMessage am = (ActionMessage)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_TPWRITE} \"{am.message}\"{STR_MESSAGE_END_CHAR}"); break; case ActionType.Attach: // !(settool X Y Z QW QX QY QZ KG CX CY CZ) ActionAttach aa = (ActionAttach)action; Tool t = aa.tool; msgs.Add(string.Format("{0}{1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13}{14}", STR_MESSAGE_ID_CHAR, action.id, INST_TOOL, Math.Round(t.TCPPosition.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPPosition.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPPosition.Z, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.TCPOrientation.Q.W, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.X, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.Y, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.TCPOrientation.Q.Z, Geometry.STRING_ROUND_DECIMALS_QUAT), Math.Round(t.Weight, Geometry.STRING_ROUND_DECIMALS_KG), Math.Round(t.centerOfGravity.X, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.centerOfGravity.Y, Geometry.STRING_ROUND_DECIMALS_MM), Math.Round(t.centerOfGravity.Z, Geometry.STRING_ROUND_DECIMALS_MM), STR_MESSAGE_END_CHAR)); break; case ActionType.Detach: // !(settool0) msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_NOTOOL}{STR_MESSAGE_END_CHAR}"); break; case ActionType.IODigital: // !SetDO "NAME" ON ActionIODigital aiod = (ActionIODigital)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_SETDO} \"{aiod.pinName}\" {(aiod.on ? 1 : 0)}{STR_MESSAGE_END_CHAR}"); break; case ActionType.IOAnalog: // !SetAO "NAME" V ActionIOAnalog aioa = (ActionIOAnalog)action; msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_SETAO} \"{aioa.pinName}\" {aioa.value}{STR_MESSAGE_END_CHAR}"); break; case ActionType.PushPop: ActionPushPop app = action as ActionPushPop; if (app.push) { return(null); } else { // Only precision and speed are states kept on the controller Settings beforePop = cursor.settingsBuffer.SettingsBeforeLastPop; if (beforePop.Speed != cursor.speed) { msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_SPEED} {cursor.speed}{STR_MESSAGE_END_CHAR}"); } if (beforePop.Precision != cursor.precision) { msgs.Add($"{STR_MESSAGE_ID_CHAR}{action.id} {INST_ZONE} {cursor.precision}{STR_MESSAGE_END_CHAR}"); } } break; case ActionType.Coordinates: throw new NotImplementedException(); // @TODO: this should also change the WObj, but not on it yet... case ActionType.ExternalAxis: string msg = $"{STR_MESSAGE_ID_CHAR}{action.id} {INST_EXT_JOINTS} "; for (int i = 0; i < cursor.externalAxes.Length; i++) { // RAPID's StrToVal() will parse 9E9 into a 9E+9 num value, and ignore that axis on motions msg += cursor.externalAxes[i]?.ToString() ?? "9E9"; if (i < cursor.externalAxes.Length - 1) { msg += " "; } } msg += STR_MESSAGE_END_CHAR; msgs.Add(msg); break; // CustomCode --> is non-streamable // If the Action wasn't on the list above, it doesn't have a message representation... default: return(null); } return(msgs); }
void DrawActions() { GUI.Label(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), "Actions : "); posGUI.y += fieldHeight; Location currentLocation = currentPlayer.GetCurrentLocation(); if (GUI.Button(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), "Wait")) { ActionWait actionWait = new ActionWait(currentTime, 1, currentLocation); AddAction(actionWait); } posGUI.y += fieldHeight; if (currentLocation != timeMachine) { for (int j = 0; j < currentLocation.items.Count; j++) { Item item = currentLocation.items[j]; if (item.pickup) { if (GUI.Button(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), "Pickup " + item.ToShortString())) { ActionPickup actionPickup = new ActionPickup(currentTime, item, j); AddAction(actionPickup); } posGUI.y += fieldHeight; } } //Inventory actions for (int i = 0, count = currentPlayer.inventory.Count; i < count; i++) { Item item = currentPlayer.inventory[i]; Action[] itemActions = item.GetInventoryActions(currentTime, i, currentPlayer); if (itemActions != null) { for (int j = 0, length = itemActions.Length; j < length; j++) { Action action = itemActions[j]; if (GUI.Button(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), action.name)) { AddAction(action); } posGUI.y += fieldHeight; } } } //Location items actions for (int i = 0, count = currentLocation.items.Count; i < count; i++) { Item item = currentLocation.items[i]; Action[] itemActions = item.GetLocationActions(currentTime, i, currentPlayer); if (itemActions != null) { for (int j = 0, length = itemActions.Length; j < length; j++) { Action action = itemActions[j]; if (GUI.Button(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), action.name)) { AddAction(action); } posGUI.y += fieldHeight; } } } } Action[] levelActions = currentLevel.GetLevelActions(currentTime, currentPlayer); for (int j = 0, length = levelActions.Length; j < length; j++) { Action action = levelActions[j]; if (GUI.Button(new Rect(posGUI.x, posGUI.y, fieldWidth, fieldHeight), action.name)) { AddAction(action); } posGUI.y += fieldHeight; } }
static public ActionBase Create(string ActionObjectString) { ActionBase output = null; try { output = Activator.CreateInstance("AutoRobo.Core", "AutoRobo.Core.Actions." + ActionObjectString).Unwrap() as ActionBase; } catch { //兼容老版本数据 switch (ActionObjectString) { case "BrowserClick": output = new ActionClick(); break; case "Navigate": output = new ActionNavigate(); break; case "ScriptPart": output = new ActionScriptPart(); break; case "AlertHandler": output = new ActionAlertHandler(); break; case "ActionDoubleClick": output = new ActionDoubleClick(); break; case "ActionFireEvent": output = new ActionFireEvent(); break; case "ActionKey": output = new ActionKey(); break; case "Mouse": output = new ActionMouse(); break; case "RadioButton": output = new ActionRadio(); break; case "Checkbox": output = new ActionCheckbox(); break; case "SelectList": output = new ActionSelectList(); break; case "TypeText": output = new ActionTypeText(); break; case "DirectionKey": output = new ActionDirectionKey(); break; case "Sleep": output = new ActionSleep(); break; case "Wait": output = new ActionWait(); break; case "ValidateCode": output = new ActionValidateCode(); break; case "FileUpload": output = new ActionFileDialog(); break; case "ValidateImage": output = new ActionValidateImage(); break; case "JavascriptInterpreter": output = new ActionJavascriptInterpreter(); break; case "SubmitClick": output = new ActionSubmitClick(); break; case "CloseWindow": output = new ActionCloseWindow(); break; case "WindowBack": output = new ActionBack(); break; case "WindowForward": output = new ActionForward(); break; case "WindowOpen": output = new ActionOpenWindow(); break; case "WindowRefresh": output = new ActionRefresh(); break; case "SubElementFinder": output = new ActionSubElements(); break; case "CallFunction": output = new ActionCall(); break; case "ActionForeach": output = new ActionForeach(); break; case "ActionBrowser": output = new ActionBrowser(); break; case "ActionThread": output = new ActionThread(); break; //case "AddChildrenToList": output = new AddChildrenToList(); break; } } //if (output == null) //{ // throw new ApplicationException(string.Format("{0}对应的活动未找到", ActionObjectString)); //} return(output); }