Ejemplo n.º 1
0
        private RobotSpecification BuildRobotSpec()
        {
            RobotSpecification specRobot = new RobotSpecification();

            specRobot.RobotID = "R7";
            specRobot.BehaviorsPath = @"C:\Devel\EmergeStudio\BehaviorSet-R7\bin\Debug";

            SpecComm cs1 = new SpecComm() { Name = "Drive", CommunicatorType = SpecComm.CommType.Serial, HasTelemetry = true, HasRemoteControl = true };
            cs1.Parameters.Add("COMPORT", "COM25");
            cs1.Parameters.Add("BAUD", "9600");
            specRobot.CommSpecs.Add(cs1);

            specRobot.SensorSpecs.Add(new SpecSensor { Name = "DistFwd", Position = 0, RetType = typeof(int), Plot = true });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "DistR30", Position = 1, RetType = typeof(int), Plot = true });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "DistL30", Position = 2, RetType = typeof(int), Plot = true });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "DistL90", Position = 3, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "Heading", Position = 4, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "Encoder1", Position = 5, RetType = typeof(int), Plot = true });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "Encoder2", Position = 6, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "Speed", Position = 7, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "Direction", Position = 8, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "IsPower", Position = 9, RetType = typeof(bool) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "HasArrived", Position = 10, RetType = typeof(bool) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "ArmBase", Position = 11, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "ArmElbow", Position = 12, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "ArmWrist", Position = 13, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "ArmWristRot", Position = 14, RetType = typeof(int) });
            specRobot.SensorSpecs.Add(new SpecSensor { Name = "ArmGripper", Position = 15, RetType = typeof(int) });

            SpecBehavior bs = new SpecBehavior() { Name = "Blocked", Priority = 1 };
            bs.Parameters.Add("Parameter1", "abc");
            specRobot.BehaviorSpecs.Add("Blocked", bs);
            specRobot.BehaviorSpecs.Add("Avoid", new SpecBehavior() { Name = "Avoid", Priority = 2 });
            specRobot.BehaviorSpecs.Add("Cruise", new SpecBehavior() { Name = "Cruise", Priority = 3 });

            specRobot.HaltRequests.Add(new Request() { Name = "Halt/Reset", Channel = "Drive", Command = "EH" });
            specRobot.HaltRequests.Add(new Request() { Name = "Power Off", Channel = "Drive", Command = "p1" });

            specRobot.GeneralSpecs.Add("CruiseDistance", "40");

            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnPower2", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnPower3", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnFunc1", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnFunc2", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnFunc3", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidUp", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidDown", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidLeft", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidRight", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidCenter", IsEnabled = false });
            specRobot.ControlSpecs.Add(new SpecControl() { ControlName = "btnVidScan", IsEnabled = false });

            // Save it
            //            specRobot.Save("Test.xml");

            return specRobot;
        }
Ejemplo n.º 2
0
        public RobotSpecification(string filename)
        {
            BehaviorsPath = Path.GetDirectoryName(filename);

            XDocument doc = XDocument.Load(filename);

            // Robot ID
            RobotID = doc.Descendants("RobotID").First().Value;

            // Comm Specs
            var x = doc.Descendants("CommSpecs");
            var specComms = from cs in doc.Descendants("CommSpecs").Descendants("CommSpec") select cs;
            foreach (XElement elSpecComm in specComms)
            {
                SpecComm sc = new SpecComm();
                sc.Name = elSpecComm.Element("Name").Value;
                sc.CommunicatorType = (SpecComm.CommType)Enum.Parse(typeof(SpecComm.CommType), elSpecComm.Element("CommunicatorType").Value, true);
                sc.HasTelemetry = (bool)bool.Parse(elSpecComm.Element("HasTelemetry").Value);
                sc.HasRemoteControl = (bool)bool.Parse(elSpecComm.Element("HasRemoteControl").Value);

                var parameters = from parm in elSpecComm.Descendants("Parameters").Descendants("Parameter") select parm;
                foreach (XElement elParm in parameters)
                    sc.Parameters.Add(elParm.Attribute("Name").Value, elParm.Attribute("Value").Value);

                m_CommSpec.Add(sc);
            }

            // Sensor Specs
            var specSensors = from ss in doc.Descendants("SensorSpecs").Descendants("SensorSpec") select ss;
            foreach (XElement elSpecSensor in specSensors)
            {
                SpecSensor ss = new SpecSensor();
                ss.Name = elSpecSensor.Element("Name").Value;
                ss.Position = (int)int.Parse(elSpecSensor.Element("Position").Value);
                ss.RetType = Type.GetType(elSpecSensor.Element("RetType").Value);
                ss.Plot = (bool)bool.Parse(elSpecSensor.Element("Plot").Value);

                m_SensorSpecs.Add(ss);
            }

            // Behavior Specs
            var specBehaviors = from bs in doc.Descendants("BehaviorSpecs").Descendants("BehaviorSpec") select bs;
            foreach (XElement elSpecBehavior in specBehaviors)
            {
                SpecBehavior bs = new SpecBehavior();
                bs.Name = elSpecBehavior.Element("Name").Value;
                bs.Priority = (int)int.Parse(elSpecBehavior.Element("Priority").Value);

                var parameters = from parm in elSpecBehavior.Descendants("Parameters").Descendants("Parameter") select parm;
                foreach (XElement elParm in parameters)
                    bs.Parameters.Add(elParm.Attribute("Name").Value, elParm.Attribute("Value").Value);

                m_BehaviorSpecs.Add(bs.Name, bs);
            }

            // General Specs
            var specGeneral = from gs in doc.Descendants("GeneralSpecs").Descendants("GeneralSpec") select gs;
            foreach (XElement elGeneral in specGeneral)
                m_GeneralSpecs.Add(elGeneral.Attribute("Name").Value, elGeneral.Attribute("Value").Value);

            // Halt Requests
            var requestsHalt = from hr in doc.Descendants("HaltRequests").Descendants("HaltRequest") select hr;
            foreach (XElement elHaltRequest in requestsHalt)
            {
                Request req = new Request();
                req.Name = elHaltRequest.Element("Name").Value;
                req.Channel = elHaltRequest.Element("Channel").Value;
                req.Command = elHaltRequest.Element("Command").Value;

                m_HaltRequests.Add(req);
            }

            // Control Specs
            var specControls = from hr in doc.Descendants("ControlSpecs").Descendants("ControlSpec") select hr;
            foreach (XElement elSpecControl in specControls)
            {
                SpecControl cs = new SpecControl();
                cs.ControlName = elSpecControl.Element("ControlName").Value;
                cs.Text = elSpecControl.Element("Text").Value;
                cs.IsEnabled = (bool)bool.Parse(elSpecControl.Element("IsEnabled").Value);

                m_ControlSpecs.Add(cs);
            }

            // Route Specs
            var specRoute = from rs in doc.Descendants("RouteSpecs").Descendants("RouteSpec") select rs;
            foreach (XElement elSpecRoute in specRoute)
            {
                SpecRoute rs = new SpecRoute();
                rs.OperatorName = elSpecRoute.Element("OperatorName").Value;
                rs.Parameters = elSpecRoute.Element("Parameters").Value;

                m_RouteSpecs.Add(rs);
            }
        }