public override void Simulate(MowayModel mowayModel) { mowayModel.Lights.UpdateLights(GetLightsState(this.frontLight), GetLightsState(this.brakeLight), GetLightsState(this.topGreenLight), GetLightsState(this.topRedLight)); if (this.frontLight == LightState.Blink) { mowayModel.Lights.UpdateLights(DigitalState.On, DigitalState.NoChange, DigitalState.NoChange, DigitalState.NoChange); System.Threading.Thread.Sleep(250); mowayModel.Lights.UpdateLights(DigitalState.Off, DigitalState.NoChange, DigitalState.NoChange, DigitalState.NoChange); System.Threading.Thread.Sleep(250); } if (this.brakeLight == LightState.Blink) { mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.On, DigitalState.NoChange, DigitalState.NoChange); System.Threading.Thread.Sleep(250); mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.Off, DigitalState.NoChange, DigitalState.NoChange); System.Threading.Thread.Sleep(250); } if (this.topGreenLight == LightState.Blink) { mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.NoChange, DigitalState.On, DigitalState.NoChange); System.Threading.Thread.Sleep(250); mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.NoChange, DigitalState.Off, DigitalState.NoChange); System.Threading.Thread.Sleep(250); } if (this.topRedLight == LightState.Blink) { mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.NoChange, DigitalState.NoChange, DigitalState.On); System.Threading.Thread.Sleep(250); mowayModel.Lights.UpdateLights(DigitalState.NoChange, DigitalState.NoChange, DigitalState.NoChange, DigitalState.Off); System.Threading.Thread.Sleep(250); } }
public override void Simulate(MowayModel mowayModel) { // Value of the frequency if (frequencyVariable == null) { mowayModel.Sound.UpdateSound(DigitalState.On, frecuencyValue); } else { mowayModel.Sound.UpdateSound(DigitalState.On, mowayModel.GetRegister(frequencyVariable.Name).Value); } // Execution time if (flowchartControl != FlowchartControl.Continuously) { if (timeVariable == null) { System.Threading.Thread.Sleep((int)(this.timeValue * 1000)); } else { System.Threading.Thread.Sleep((int)(mowayModel.GetRegister(this.timeVariable.Name).Value * 1000)); } // Stop sound after run time mowayModel.Sound.UpdateSound(DigitalState.Off, 0); } else if (flowchartControl == FlowchartControl.Continuously) { } }
/// <summary> /// Disables the simulator by deleting the project information /// </summary> public void DeactivateSimulator() { //If the simulator is running, it stops if (this.state == SimState.Running) { this.stopSimulate = true; this.simulatorThread.Join(); this.state = SimState.Pause; if (this.StateChanged != null) { this.StateChanged(this, new EventArgs()); } } //All simulation layers are hidden from all functions foreach (GraphDiagram function in this.functions.Values) { function.SimulatorLayer.Visible = false; } //The stroke indicator of the current function is removed this.presentFunction.SimulatorLayer.Remove(this.graphTrace); this.presentFunction.SimulatorLayer.UpdateSurface(); //The Simulator status is updated this.state = SimState.Inactive; if (this.StateChanged != null) { this.StateChanged(this, new EventArgs()); } //Project information is deleted to simulate this.mainFunction = null; this.functions.Clear(); this.variables = null; //The simulated model of the Moway is eliminated this.mowayModel = null; }
/// <summary> /// Builder /// </summary> /// <param name="mowayModel">Simulation Model of the mOway</param> internal CommunicationPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Logs the event of sent message this.mowayModel.Communication.MessageSend += new MessageEventHandler(Communication_MessageSend); }
public override bool Simulate(MowayModel mowayModel) { Moway.Simulator.Communications.Message rxedMessage = null; if (mowayModel.Communication.MessageReceived()) { rxedMessage = mowayModel.Communication.GetMessage(); if (this.direction != null) { mowayModel.GetRegister(this.direction.Name).Value = rxedMessage.Direction; } for (int simCont = 0; simCont < 8; simCont++) { if (this.dataVariable[simCont] != null) { mowayModel.GetRegister(this.dataVariable[simCont].Name).Value = rxedMessage.Data[simCont]; } } return(true); } else { return(false); } }
public override void Simulate(MowayModel mowayModel) { if (this.resetDistance == true) { mowayModel.Movement.ResetDistance(); mowayModel.Movement.ResetAngle(); } }
/// <summary> /// Builder /// </summary> /// <param name="mowayModel">Simulation model of the MOway</param> internal EnviromentPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Updates the values of the sensors this.nudBrightness.Value = mowayModel.Brightness; this.nudTemperature.Value = mowayModel.Temperature; this.nudNoise.Value = mowayModel.NoiseLevel; }
/// <summary> /// Builder /// </summary> /// <param name="mowayModel">Simulation Model of the mOway</param> internal AccelerometerPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Updates the values of the sensors this.nudXAxis.Value = mowayModel.Accelerometer.XAxisValue; this.nudYAxis.Value = mowayModel.Accelerometer.YAxisValue; this.nudZAxis.Value = mowayModel.Accelerometer.ZAxisValue; }
/// <summary> /// Builder of the panel of output devices /// </summary> /// <param name="mowayModel"></param> public OutputsPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Events are recorded this.mowayModel.Movement.DistanceChanged += new EventHandler(Movement_DistanceChanged); this.mowayModel.Movement.MovementChanged += new EventHandler(Movement_MovementChanged); this.mowayModel.Lights.LightsChanged += new EventHandler(Lights_LightsChanged); this.mowayModel.Sound.SoundChanged += new EventHandler(Sound_SoundChanged); }
public override void Simulate(MowayModel mowayModel) { if (this.lineSensor == Side.Right) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.LineSensors.RightSensor; } else if (this.lineSensor == Side.Left) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.LineSensors.LeftSensor; } }
public override bool Simulate(MowayModel mowayModel) { if (mowayModel.NoiseLevel >= MowayModel.MIN_NOISE) { return(true); } else { return(false); } }
public override void Simulate(MowayModel mowayModel) { if (this.variable == null) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)this.value; } else { mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.GetRegister(this.variable.Name).Value; } }
public override void Simulate(MowayModel mowayModel) { if (this.timeVariable == null) { System.Threading.Thread.Sleep((int)(this.timeValue * 1000)); } else { System.Threading.Thread.Sleep((int)(mowayModel.GetRegister(this.timeVariable.Name).Value * 1000)); } }
public override void Simulate(MowayModel mowayModel) { if (this.wheel == Side.Left) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.Movement.LeftWheelSpeed; } else if (this.wheel == Side.Right) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.Movement.RightWheelSpeed; } }
public override bool Simulate(MowayModel mowayModel) { if ((mowayModel.Accelerometer.XAxisValue <= -(MowayModel.MIN_TAP)) || (mowayModel.Accelerometer.XAxisValue >= MowayModel.MIN_TAP) || (mowayModel.Accelerometer.YAxisValue <= -(MowayModel.MIN_TAP)) || (mowayModel.Accelerometer.YAxisValue >= MowayModel.MIN_TAP) || (mowayModel.Accelerometer.ZAxisValue <= -(MowayModel.MIN_TAP)) || (mowayModel.Accelerometer.ZAxisValue >= MowayModel.MIN_TAP)) { return(true); } else { return(false); } }
public override bool Simulate(MowayModel mowayModel) { bool leftCondition = false; bool rightCondition = false; // Check left sensor condition if ((leftSensor == LineState.Black) && (mowayModel.LineSensors.LeftSensor >= MowayModel.MIN_LINE_BLACK) || (leftSensor == LineState.White) && (mowayModel.LineSensors.LeftSensor <= MowayModel.MAX_LINE_WHITE)) { leftCondition = true; } else { leftCondition = false; } // Check right sensor condition if ((rightSensor == LineState.Black) && (mowayModel.LineSensors.RightSensor >= MowayModel.MIN_LINE_BLACK) || (rightSensor == LineState.White) && (mowayModel.LineSensors.RightSensor <= MowayModel.MAX_LINE_WHITE)) { rightCondition = true; } else { rightCondition = false; } // In case "detection inactive" is selected if ((leftSensor == LineState.Inactive) && (rightSensor == LineState.Inactive)) { return(true); } else if (leftSensor == LineState.Inactive) { return(rightCondition); } else if (rightSensor == LineState.Inactive) { return(leftCondition); } // Check logic operation (AND/OR) if both senors are active if (operation == LogicOp.And) { return(leftCondition && rightCondition); } else { return(leftCondition || rightCondition); } }
/// <summary> /// Builder /// </summary> /// <param name="mowayModel">Simulation model of the MOway</param> internal SensorsPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Updates the values of the sensors and the images this.nudLineLeftSensor.Value = this.mowayModel.LineSensors.LeftSensor; this.nudLineRightSensor.Value = this.mowayModel.LineSensors.RightSensor; this.nudObstacleLeftCentralSensor.Value = this.mowayModel.ObstacleSensors.LeftCentralSensor; this.nudObstacleLeftSideSensor.Value = this.mowayModel.ObstacleSensors.LeftSideSensor; this.nudObstacleRightCentralSensor.Value = this.mowayModel.ObstacleSensors.RightCentralSensor; this.nudObstacleRightSideSensor.Value = this.mowayModel.ObstacleSensors.RightSideSensor; this.pbLineLeft.Image = SensorsGraphics.leftWhite; this.pbLineRight.Image = SensorsGraphics.rightWhite; }
/// <summary> /// Builder of the register panel of the mOway simulated /// </summary> /// <param name="mowayModel">Model of the mOway simulated</param> internal RegistersPanel(MowayModel mowayModel) : base(mowayModel) { InitializeComponent(); //Registers events are logged mowayModel.RegisterAdded += new RegisterEventHandler(MowayModel_RegisterAdded); mowayModel.RegisterRemoved += new RegisterEventHandler(MowayModel_RegisterRemoved); //All registers of the simulated MOway are included in the list of registers foreach (Register register in mowayModel.Registers) { AddRegisterItem(register); } //The items in the register list are updated this.UpdateItems(); }
public override void Simulate(MowayModel mowayModel) { byte tempDistance; decimal tempTimes; if (mowayModel.Movement.Distance > 255) { tempTimes = mowayModel.Movement.Distance / 255; tempDistance = (byte)(mowayModel.Movement.Distance - (255 * System.Math.Floor(tempTimes))); } else { tempDistance = (byte)mowayModel.Movement.Distance; } mowayModel.GetRegister(this.assignVariable.Name).Value = tempDistance; }
public override bool Simulate(MowayModel mowayModel) { byte[] dataSimAux = { 0, 0, 0, 0, 0, 0, 0, 0 }; for (int simCont = 0; simCont < 8; simCont++) { if (dataVariable[simCont] == null) { dataSimAux[simCont] = (byte)this.dataValue[simCont]; } else { dataSimAux[simCont] = (byte)mowayModel.GetRegister(this.dataVariable[simCont].Name).Value; } } mowayModel.Communication.SendMessage((byte)this.direction, dataSimAux); return(true); }
public override void Simulate(MowayModel mowayModel) { switch (this.obstacleSensor) { case ObstacleSensor.Left: mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.ObstacleSensors.LeftSideSensor; break; case ObstacleSensor.Right: mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.ObstacleSensors.RightSideSensor; break; case ObstacleSensor.UpperLeft: mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.ObstacleSensors.LeftCentralSensor; break; case ObstacleSensor.UpperRight: mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.ObstacleSensors.RightCentralSensor; break; } }
public override void Simulate(MowayModel mowayModel) { byte mathValueAux = 0; // Save value to compare with if (this.variable == null) { mathValueAux = (byte)this.value; } else { mathValueAux = mowayModel.GetRegister(this.variable.Name).Value; } if (this.operation == ArithmeticOp.Add) { mowayModel.GetRegister(this.resultVariable.Name).Value += mathValueAux; } else if (this.operation == ArithmeticOp.Sub) { mowayModel.GetRegister(this.resultVariable.Name).Value -= mathValueAux; } }
public override void Simulate(MowayModel mowayModel) { if (this.axis == AccelerometerAxis.X) { if (mowayModel.Accelerometer.XAxisValue == -2) { mowayModel.GetRegister(this.assignVariable.Name).Value = 0; } else { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)((mowayModel.Accelerometer.XAxisValue * 64) + 127); } } else if (this.axis == AccelerometerAxis.Y) { if (mowayModel.Accelerometer.YAxisValue == -2) { mowayModel.GetRegister(this.assignVariable.Name).Value = 0; } else { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)((mowayModel.Accelerometer.YAxisValue * 64) + 127); } } else { if (mowayModel.Accelerometer.ZAxisValue == -2) { mowayModel.GetRegister(this.assignVariable.Name).Value = 0; } else { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)((mowayModel.Accelerometer.ZAxisValue * 64) + 127); } } }
/// <summary> /// Activates the simulator by loading the necessary information from the project to simulate /// </summary> /// <param name="mainFunction"></param> /// <param name="functions"></param> /// <param name="variables"></param> public void ActivateSimulator(GraphDiagram mainFunction, List <GraphDiagram> functions, List <Variable> variables) { //The simulator state is changed this.state = SimState.Pause; if (this.StateChanged != null) { this.StateChanged(this, new EventArgs()); } //The project information is saved to simulate this.mainFunction = mainFunction; //The functions are saved and the simulation layers are visible foreach (GraphDiagram function in functions) { function.SimulatorLayer.Visible = true; this.functions.Add(function.Name, function); } this.variables = variables; //A simulated Moway model is loaded this.mowayModel = new MowayModel(); //Records are loaded to the MOway model List <Register> registers = new List <Register>(); foreach (Variable variable in this.variables) { registers.Add(new Register(variable.Name, variable.InitValue)); } this.mowayModel.LoadRegisters(registers); //The first element to simulate is indicated this.presentFunction = this.mainFunction; this.presentElement = this.presentFunction.StartElement; //Indicates that a function validation is required this.requireValidate = true; //The simulation indicator is displayed in the current function and its position is updated this.presentFunction.SimulatorLayer.Add(this.graphTrace); this.UpdateTrace(this.mainFunction, this.mainFunction.StartElement); }
public override void Simulate(MowayModel mowayModel) { }
public override void Simulate(MowayModel mowayModel) { mowayModel.GetRegister(this.assignVariable.Name).Value = mowayModel.NoiseLevel; }
public override bool Simulate(MowayModel mowayModel) { decimal modelValueAux = 0; decimal compareValueAux = 0; // Save selected axis if (this.axis == AccelerometerAxis.X) { modelValueAux = mowayModel.Accelerometer.XAxisValue; } else if (this.axis == AccelerometerAxis.Y) { modelValueAux = mowayModel.Accelerometer.YAxisValue; } else { modelValueAux = mowayModel.Accelerometer.ZAxisValue; } // Save value to compare with if (this.compareVariable == null) { compareValueAux = this.compareValue; } else { // Convert (0, 255) to (-2, 2) compareValueAux = mowayModel.GetRegister(this.compareVariable.Name).Value; compareValueAux = (compareValueAux / 255) * 4 - 2; compareValueAux = decimal.Round(compareValueAux, 2); } switch (this.operation) { case ComparativeOp.Bigger: if (modelValueAux > compareValueAux) { return(true); } else { return(false); } case ComparativeOp.BiggerEqual: if (modelValueAux >= compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Distinct: if (modelValueAux != compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Equal: if (modelValueAux == compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Smaller: if (modelValueAux < compareValueAux) { return(true); } else { return(false); } case ComparativeOp.SmallerEqual: if (modelValueAux <= compareValueAux) { return(true); } else { return(false); } default: return(false); } }
public override bool Simulate(MowayModel mowayModel) { byte modelValueAux = 0; int compareValueAux = 0; // Save sensor model value modelValueAux = mowayModel.Brightness; // Save value to compare with if (this.compareVariable == null) { compareValueAux = this.compareValue; } else { compareValueAux = mowayModel.GetRegister(this.compareVariable.Name).Value; } switch (this.operation) { case ComparativeOp.Bigger: if (modelValueAux > compareValueAux) { return(true); } else { return(false); } case ComparativeOp.BiggerEqual: if (modelValueAux >= compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Distinct: if (modelValueAux != compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Equal: if (modelValueAux == compareValueAux) { return(true); } else { return(false); } case ComparativeOp.Smaller: if (modelValueAux < compareValueAux) { return(true); } else { return(false); } case ComparativeOp.SmallerEqual: if (modelValueAux <= compareValueAux) { return(true); } else { return(false); } default: return(false); } }
public override void Simulate(MowayModel mowayModel) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.Temperature; }
public override void Simulate(MowayModel mowayModel) { mowayModel.GetRegister(this.assignVariable.Name).Value = (byte)mowayModel.Brightness; }