public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION) { if (message.Message.Equals("target reached")) { LaserProjector projector = scanStation.label.GetComponentInChildren <LaserProjector>(); if (projector != null) { projector.setController(controller); projector.startScan(); } //RobotArms arms = controller.GetComponentInChildren<RobotArms>(); //arms.dropTarget(); } else if (message.Message.Equals("target scanned")) { List <Goal> goals = new List <Goal>(); goals.Add(new Goal(GoalEnum.Offense, 10f)); RobotArms arms = controller.GetComponentInChildren <RobotArms>(); Label target = arms.getTarget(); if (target.GetComponent <Player>() != null) { controller.addEndeavour(new ElectrocuteAction(controller, goals, target)); } } } }
public APIResult Add([FromBody] AddArgsModel args) { try { if (string.IsNullOrEmpty(args.Question)) { throw new ArgumentNullException("Question"); } var isExit = wechatCoreDb.QueryRobotMessage() .Where(m => m.Question == args.Question) .Where(m => !m.IsDel) .Count() > 0; if (isExit) { throw new Exception("问题已经存在"); } var model = new RobotMessage() { Question = args.Question, QuestionType = args.QuestionType, Answer = args.Answer, Status = RobotMessageStatus.正常 }; wechatCoreDb.AddToRobotMessage(model); wechatCoreDb.SaveChanges(); return(Success()); } catch (Exception ex) { return(Error(ex.Message)); } }
public override void onMessage(RobotMessage message) { if(message.Type == RobotMessage.MessageType.ACTION && message.Message.Equals(AbstractArms.TARGET_CAPTURED_MESSAGE)) { HoverJet jet = controller.getRobotComponent<HoverJet>(); jet.stop(); } }
public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION && message.Message.Equals(HoverJet.TARGET_REACHED)) { getController().getRobotComponent<SentrySpawner>().dropSentry(); sentryPoint.getLabelHandle().addTag(new Tag(TagEnum.Occupied, 0, sentryPoint.getLabelHandle())); } }
public void Ev3TCPServer_UnitTest_6() { RobotMessage message = new RobotMessage(); Assert.IsNotNull(message); Assert.AreEqual(Sender.Undefined, message.Sender); }
public override void onMessage(RobotMessage message) { if(message.Type == RobotMessage.MessageType.ACTION) { if(message.Target == parent) { completed = true; controller.enqueueMessage(new RobotMessage(RobotMessage.MessageType.TARGET_LOST, "target lost", parent, parent.getPosition(), null)); } } }
public override void onMessage(RobotMessage message) { if (message.Message.Equals("target reached")) { RobotArms arms = controller.GetComponentInChildren <RobotArms> (); arms.dropTarget(); } }
private void sendRobotMessage(RobotAction action, String message) { // Format the message string robotMessage = RobotMessage.FormatRobotMessage((int)action, message); // Send the Bluetooth data BluetoothConnection.Write(robotMessage); }
public override void onMessage(RobotMessage message) { if(message.Type == RobotMessage.MessageType.ACTION) { if(message.Message.Equals("target scanned")) { List<Goal> goals = new List<Goal>(); goals.Add(new Goal(GoalEnum.Offense, 10f)); controller.addEndeavour(new ElectrocuteAction(controller, goals, target)); } } }
public override void onMessage(RobotMessage message) { if(message.Type == RobotMessage.MessageType.ACTION) { if(message.Target == sound.getLabelHandle()) { completed = true; controller.enqueueMessage(new RobotMessage(RobotMessage.MessageType.TARGET_LOST, "target lost", sound.getLabelHandle(), sound.getLabelHandle().getPosition(), null)); } } }
// Update is called once per frame void Update() { //Leave this here, very useful!! //#if UNITY_EDITOR // if(debug) { // /* // * Draw tracked targets // */ // foreach(GameObject obj in trackedObjects) { // Destroy(obj); // } // trackedObjects.Clear(); // foreach(LabelHandle handle in trackedTargets) { // GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule); // capsule.transform.position = handle.getPosition(); // capsule.GetComponent<MeshRenderer>().material.color = Color.yellow; // capsule.transform.localScale = new Vector3(.2f, .2f, .2f); // Destroy(capsule.GetComponent<Rigidbody>()); // Destroy(capsule.GetComponent<CapsuleCollider>()); // trackedObjects.Add(capsule); // } // } //#endif while (messageQueue.Count > 0) { RobotMessage message = messageQueue.Dequeue(); if (message.Type == RobotMessage.MessageType.TARGET_SIGHTED) { if (targetSightedSound != null && message.Target.getName().Equals("Player") && (!getMentalModel().knowsTarget(message.Target) || (System.DateTime.Now - getMentalModel().getLastSightingTime(message.Target).Value).Seconds > timeoutSeconds)) { soundEmitter.PlayOneShot(targetSightedSound); } sightingFound(message.Target, message.TargetPos, message.TargetVelocity); trackTarget(message.Target); //evaluateActions(); } else if (message.Type == RobotMessage.MessageType.TARGET_LOST) { sightingLost(message.Target, message.TargetPos, message.TargetVelocity); trackedTargets.Remove(message.Target); //evaluateActions(); } else if (message.Type == RobotMessage.MessageType.ACTION) { foreach (Endeavour action in currentEndeavours) { action.onMessage(message); } } } if (dirty) { evaluateActions(); } }
/// <summary>Analyses the robots message when robot message type is RobotMessage. /// <para>Value for RobotMessage is 20.</para> /// <para>Package length is 61 bytes.</para> /// </summary> /// <param name="data">Byte array received on the socket stream.</param> private void RobotMessage(byte[] data) { double timeStamp = data[count + 1] * Math.Pow(2, 8 * 7) + data[count + 2] * Math.Pow(2, 8 * 6) + data[count + 3] * Math.Pow(2, 8 * 5) + data[count + 4] * Math.Pow(2, 8 * 4) + data[count + 5] * Math.Pow(2, 8 * 3) + data[count + 6] * Math.Pow(2, 8 * 2) + data[count + 7] * Math.Pow(2, 8 * 1) + data[count + 8]; count = count + 8; //Console.WriteLine("Timestamp: " + timeStamp); int source = data[count + 1]; //Console.WriteLine("Source: " + data[count + 1]); count++; int robotMsgVersion = data[count + 1]; //Console.WriteLine("ROBOT_MESSAGE_VERSION: " + data[count + 1]); count++; //Console.WriteLine("Project name size: " + data[count + 1]); int projectNameSize = data[count + 1]; count++; byte[] projectNameArray = new byte[projectNameSize]; Array.Copy(data, count + 1, projectNameArray, 0, projectNameSize); count = count + projectNameSize; string projectName = new string(Encoding.ASCII.GetString(projectNameArray).ToCharArray()); //Console.WriteLine("Project name: " + projectName); int majorVersion = data[count + 1]; //Console.WriteLine("Major version: " + data[count + 1]); count++; int minorVersion = data[count + 1]; //Console.WriteLine("Minor version: " + data[count + 1]); count++; byte[] svnRevisionArray = new byte[] { data[count + 1], data[count + 2], data[count + 3], data[count + 4] }; if (BitConverter.IsLittleEndian) { Array.Reverse(svnRevisionArray); } int svnRevision = BitConverter.ToInt32(svnRevisionArray, 0); count = count + 4; //Console.WriteLine("SVN Revision: " + svnRevision); int buildDateSize = numberOfBytes - 1 - count; char[] buildDateArray = new char[buildDateSize]; Array.Copy(data, count + 1, buildDateArray, 0, buildDateSize); count = count + buildDateSize; string buildDate = new string(buildDateArray); //Console.WriteLine("Build date: " + buildDate); RobotMessage robMsg = new RobotMessage(projectName, majorVersion, minorVersion, svnRevision, buildDate); //RobotMessage robMsg = new RobotMessage(timeStamp, source, robotMsgVersion, projectName, majorVersion, minorVersion, svnRevision, buildDate); //events.NewRobotMessage(robMsg); if (OnRobotMessage != null) { OnRobotMessage(robMsg); } }
public void ConnectedRobot_UnitTest_7() { SpecialRobot_2 robot = new SpecialRobot_2(theAddress: localAddress); Assert.IsNotNull(robot); Assert.AreEqual(localAddress, robot.IPAddress); Assert.AreEqual(false, robot.IsServerRunning); Assert.AreEqual(false, robot.okIHaveReceivedAMessage); // Starts the server and checks IPEndPoint remoteEP = new IPEndPoint(localAddress, 11000); robot.Start(); Thread.Sleep(100); Assert.AreEqual(true, robot.IsServerRunning); // Connects to the server and check Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(remoteEP); Assert.AreEqual(client.Connected, true); // Create a message to send RobotMessage sentMessage = new RobotMessage(); sentMessage.Sender = Sender.FromClient; string encodedMessage = RobotMessage.Serialize(theMessage: sentMessage); // Send the message int bytesSent = client.Send(Encoding.ASCII.GetBytes(encodedMessage)); Assert.AreNotEqual(0, bytesSent); // Wait for answer byte[] buffer = new byte[4096]; client.Receive(buffer); string receivedString = Encoding.ASCII.GetString(buffer); SpecialMessage receivedMessage = (SpecialMessage)RobotMessage.DeSerialize(receivedString, typeof(SpecialMessage)); Assert.AreEqual(Sender.FromRobot, receivedMessage.Sender); Assert.AreEqual(150, receivedMessage.testField); // Checks message received Thread.Sleep(100); Assert.AreEqual(true, robot.okIHaveReceivedAMessage); // Disconnects from the server and check client.Disconnect(false); Assert.AreEqual(client.Connected, false); // Stops the server and checks robot.Stop(); Thread.Sleep(100); Assert.AreEqual(false, robot.IsServerRunning); }
public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION) { if (message.Target == parent) { completed = true; controller.enqueueMessage(new RobotMessage(RobotMessage.MessageType.TARGET_LOST, "target lost", parent, parent.getPosition(), null)); } } }
public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION) { if (message.Message.Equals("target scanned")) { List <Goal> goals = new List <Goal>(); goals.Add(new Goal(GoalEnum.Offense, 10f)); controller.addEndeavour(new ElectrocuteAction(controller, goals, target)); } } }
/// <summary>Runs a test based on the test unit. Test result is given in the OnTestCompleted event.</summary> /// <param name="testUnit">Test unit that needs to be tested.</param> public void Test(Unit testUnit) { this.testUnit = testUnit; AnalyseURData.OnRobotMessage -= new AnalyseURData.RobotMessageEventHandler(robotMsgReceived); AnalyseURData.OnRobotMessage += new AnalyseURData.RobotMessageEventHandler(robotMsgReceived); Connection.OnConnectionCompleted -= new Connection.ConnectionCompletedEventHandler(ConnectionCompleted); Connection.OnConnectionCompleted += new Connection.ConnectionCompletedEventHandler(ConnectionCompleted); testRobMsg = new RobotMessage(testUnit.projectName, testUnit.majorversion, testUnit.minorversion, testUnit.svnRevision, testUnit.buildDate); logic.SelectUnit(testUnit); // Set the unit in logic that needs testing logic.EstablishConnection(); // Establish a temporary connection to the new unit }
// Update is called once per frame void Update() { //Leave this here, very useful!! //#if UNITY_EDITOR // if(debug) { // /* // * Draw tracked targets // */ // foreach(GameObject obj in trackedObjects) { // Destroy(obj); // } // trackedObjects.Clear(); // foreach(LabelHandle handle in trackedTargets) { // GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule); // capsule.transform.position = handle.getPosition(); // capsule.GetComponent<MeshRenderer>().material.color = Color.yellow; // capsule.transform.localScale = new Vector3(.2f, .2f, .2f); // Destroy(capsule.GetComponent<Rigidbody>()); // Destroy(capsule.GetComponent<CapsuleCollider>()); // trackedObjects.Add(capsule); // } // } //#endif while (messageQueue.Count > 0) { RobotMessage message = messageQueue.Dequeue(); if (message.Type == RobotMessage.MessageType.TARGET_SIGHTED) { sightingFound(message.Target, message.TargetPos, message.TargetVelocity); trackTarget(message.Target); evaluateActions(); } else if (message.Type == RobotMessage.MessageType.TARGET_LOST) { sightingLost(message.Target, message.TargetPos, message.TargetVelocity); trackedTargets.Remove(message.Target); evaluateActions(); } else if (message.Type == RobotMessage.MessageType.ACTION) { foreach (Endeavour action in currentEndeavours) { action.onMessage(message); } } } if (dirty) { evaluateActions(); } }
public void Ev3TCPServer_UnitTest_13() { // Server Ip Address and server initialization Ev3TCPServer server = new Ev3TCPServer(withIPAddress: localAddress); IPEndPoint remoteEP = new IPEndPoint(localAddress, 11000); bool propertyChangedEventFired = false; server.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { propertyChangedEventFired = true; }; // Starts the server and checks server.Start(); Thread.Sleep(100); Assert.AreEqual(server.IsRunning, true); // Connects to the server and check Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(remoteEP); Assert.AreEqual(client.Connected, true); // Create a message to send RobotMessage sentMessage = new RobotMessage(); sentMessage.Sender = Sender.FromClient; string encodedMessage = RobotMessage.Serialize(theMessage: sentMessage); // Send the message int bytesSent = client.Send(Encoding.ASCII.GetBytes(encodedMessage)); Assert.AreNotEqual(0, bytesSent); // Checks message received Thread.Sleep(100); Assert.IsNotNull(server.LastMessage); Assert.AreNotEqual(string.Empty, server.LastMessage); Assert.AreEqual(sentMessage.Sender, RobotMessage.DeSerialize(server.LastMessage, typeof(RobotMessage)).Sender); // Checks event fired Assert.AreEqual(true, propertyChangedEventFired); // Disconnects from the server and check client.Disconnect(false); Assert.AreEqual(client.Connected, false); // Stops the server and checks server.Stop(); Thread.Sleep(100); Assert.AreEqual(server.IsRunning, false); }
public void Send(string url, RobotMessage message) { try { string json = JsonConvert.SerializeObject(message, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); var result = _client.PostAsync(url, new StringContent(json)).Result; } catch (Exception ex) { _logger.WriteEntry(ex.ToString()); } }
public void Ev3TCPServer_UnitTest_10() { RobotMessage sentMessage = new RobotMessage(); sentMessage.Sender = Sender.Undefined; string messageSerialized = RobotMessage.Serialize(theMessage: sentMessage); Assert.IsNotNull(messageSerialized); Assert.AreNotEqual(string.Empty, messageSerialized); RobotMessage receivedMessage = RobotMessage.DeSerialize(data: messageSerialized, type: typeof(RobotMessage)); Assert.AreEqual(sentMessage.Sender, receivedMessage.Sender); }
public void Ev3TCPServer_UnitTest_7() { RobotMessage message = new RobotMessage(); Assert.IsNotNull(message); Assert.AreEqual(Sender.Undefined, message.Sender); message.Sender = Sender.FromClient; Assert.AreEqual(Sender.FromClient, message.Sender); message.Sender = Sender.FromRobot; Assert.AreEqual(Sender.FromRobot, message.Sender); message.Sender = Sender.Undefined; Assert.AreEqual(Sender.Undefined, message.Sender); }
protected override void ProcessLastReceivedMessage() { base.ProcessLastReceivedMessage(); okIHaveReceivedAMessage = true; // Sends a message back SpecialMessage message = new SpecialMessage(); message.Sender = Sender.FromRobot; message.testField = 150; string encodedMessage = RobotMessage.Serialize(theMessage: message); // Send the message Ev3TCPServer.Send(encodedMessage); }
public void Ev3TCPServer_UnitTest_11() { OtherRobotMessage sentMessage = new OtherRobotMessage(); sentMessage.Sender = Sender.FromRobot; sentMessage.testField = 58; string messageSerialized = RobotMessage.Serialize(theMessage: sentMessage); Assert.IsNotNull(messageSerialized); Assert.AreNotEqual(string.Empty, messageSerialized); OtherRobotMessage receivedMessage = (OtherRobotMessage)RobotMessage.DeSerialize(data: messageSerialized, type: typeof(OtherRobotMessage)); Assert.AreEqual(sentMessage.Sender, receivedMessage.Sender); Assert.AreEqual(sentMessage.testField, receivedMessage.testField); }
public override void onMessage(RobotMessage message) { if (message.Message.Equals ("target reached")) { HoverJet jet = controller.GetComponentInChildren<HoverJet> (); if (jet != null && routePoints[currentDestination] == message.Target) { ++currentDestination; if (currentDestination == routePoints.Count) { currentDestination = 0; } if(routePoints[currentDestination] == null) { Debug.LogWarning("Robot '" + controller.name + "' has detected a missing patrol route point. "); Debug.LogWarning("Robot '" + controller.name + "' halted. "); } else { jet.setTarget(routePoints[currentDestination], false); } } } }
public void Ev3TCPServer_UnitTest_12() { // Server Ip Address and server initialization // IPAddress ipTest = new IPAddress(new byte[4] { 192, 168, 1, 170 }); Ev3TCPServer server = new Ev3TCPServer(withIPAddress: localAddress); IPEndPoint remoteEP = new IPEndPoint(localAddress, 11000); // Starts the server and checks server.Start(); Thread.Sleep(100); Assert.AreEqual(server.IsRunning, true); // Connects to the server and check Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(remoteEP); Assert.AreEqual(client.Connected, true); // Create a message to send RobotMessage sentMessage = new RobotMessage(); sentMessage.Sender = Sender.FromClient; string encodedMessage = RobotMessage.Serialize(theMessage: sentMessage); // Send the message int bytesSent = client.Send(Encoding.ASCII.GetBytes(encodedMessage)); Assert.AreNotEqual(0, bytesSent); // Checks message received Thread.Sleep(100); Assert.IsNotNull(server.LastMessage); Assert.AreNotEqual(string.Empty, server.LastMessage); Assert.AreEqual(sentMessage.Sender, RobotMessage.DeSerialize(server.LastMessage, typeof(RobotMessage)).Sender); // Disconnects from the server and check client.Disconnect(false); Assert.AreEqual(client.Connected, false); // Stops the server and checks server.Stop(); Thread.Sleep(100); Assert.AreEqual(server.IsRunning, false); }
public override bool Equals(object obj) { RobotMessage testObj = obj as RobotMessage; if (testObj == null) { return(false); } else if (testObj.BuildDate.Equals(buildDate) && testObj.MajorVersion.Equals(majorVersion) && testObj.MinorVersion.Equals(minorVersion) && testObj.ProjectName.Equals(projectName) && testObj.SvnRevision.Equals(svnRevision)) { return(true); } else { return(false); } }
public override void onMessage(RobotMessage message) { if(message.Type == RobotMessage.MessageType.ACTION) { if(message.Message.Equals("target reached")) { LaserProjector projector = scanStation.label.GetComponentInChildren<LaserProjector>(); if(projector != null) { projector.setController(controller); projector.startScan(); } //RobotArms arms = controller.GetComponentInChildren<RobotArms>(); //arms.dropTarget(); } else if(message.Message.Equals("target scanned")) { List<Goal> goals = new List<Goal>(); goals.Add(new Goal(GoalEnum.Offense, 10f)); RobotArms arms = controller.GetComponentInChildren<RobotArms>(); Label target = arms.getTarget(); if(target.GetComponent<Player>() != null) { controller.addEndeavour(new ElectrocuteAction(controller, goals, target)); } } } }
public override void onMessage(RobotMessage message) { if (message.Message.Equals("target reached")) { HoverJet jet = controller.GetComponentInChildren <HoverJet> (); if (jet != null && routePoints[currentDestination] == message.Target) { ++currentDestination; if (currentDestination == routePoints.Count) { currentDestination = 0; } if (routePoints[currentDestination] == null) { Debug.LogWarning("Robot '" + controller.name + "' has detected a missing patrol route point. "); Debug.LogWarning("Robot '" + controller.name + "' halted. "); } else { jet.setTarget(routePoints[currentDestination]); } } } }
public override void onMessage(RobotMessage message) { }
public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION && message.Message == HoverJet.TARGET_REACHED) { lastSeen = Time.time; } }
public override void onMessage(RobotMessage message) { if (message.Message.Equals ("target reached")) { RobotArms arms = controller.GetComponentInChildren<RobotArms> (); arms.dropTarget(); } }
/// <summary>Sets the local variable of robot message.</summary> private void robotMsgReceived(RobotMessage robMsg) { this.robMsg = robMsg; }
public override void onMessage(RobotMessage message) { if (message.Type == RobotMessage.MessageType.ACTION && message.Message == HoverJet.TARGET_REACHED) { spawner.active = true; } }
public abstract void onMessage(RobotMessage message);
public void enqueueMessage(RobotMessage message) { messageQueue.Enqueue(message); }
public void enqueueMessage(RobotMessage message) { messageQueue.Enqueue (message); }
private void SteerRobot(ServoDirection servoDirection, int turnValue) { // If moving FORWARD then ... if (servoDirection == ServoDirection.Forward) { // If turning LEFT if (turnValue < -150) { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.CounterMaxSpeed - 30; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.StopSpeed; } // If turning RIGHT else if (turnValue > 150) { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.StopSpeed; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.ClockwiseMaxSpeed + 60; } else { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.CounterMaxSpeed - 30; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.ClockwiseMaxSpeed + 60; } } // If moving BACKWARD then ... if (servoDirection == ServoDirection.Backward) { // If turning LEFT if (turnValue < -150) { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.StopSpeed; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.CounterMaxSpeed; } // If turning RIGHT else if (turnValue > 150) { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.ClockwiseMaxSpeed; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.StopSpeed; } else { RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.ClockwiseMaxSpeed; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.CounterMaxSpeed; } } // If STOPPING then ... if (servoDirection == ServoDirection.Stop) { // If turning LEFT RobotParameters.ServoA.CurrentRotationPosition = RobotParameters.StopSpeed; RobotParameters.ServoB.CurrentRotationPosition = RobotParameters.StopSpeed; } // Display the final speed _potisionTextView.Text += $"\r\nA:{RobotParameters.ServoA.CurrentRotationPosition} B:{RobotParameters.ServoB.CurrentRotationPosition}"; // Send the Message to the Robot string message = RobotMessage.FormatSteerMessage(RobotParameters.ServoA, RobotParameters.ServoB); sendRobotMessage(RobotAction.Steer, message); }