示例#1
0
        public void SetXY_ForwardValue()
        {
            // Setup
            MockSerialDevice serialDevice = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            bool correctValues  = true;
            int  input          = 100;
            int  expectedOutput = 190;
            int  actualOutput   = -1;

            chair.Start();
            // act
            chair.SetX(0);
            chair.SetY(input);
            System.Threading.Thread.Sleep(150);
            actualOutput = chair.VoltY;
            chair.End();
            string message = "Expected: ";

            message += expectedOutput;
            message += ", Actual: ";
            message += actualOutput;
            chair.Dispose();
            Assert.AreEqual(expectedOutput, actualOutput, message);
        }
示例#2
0
        public void SetXY_ValidVoltages()
        {
            // Setup
            MockSerialDevice serialDevice  = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair         = Wheelchair.Instance(serialDevice);
            bool             correctValues = true;

            int[] inputValues =
            {
                0,
                -100,
                100
            };
            int[] expectedValues = { 128, 66, 190 };
            chair.Start();
            // act
            for (int i = 0; i < 3; i++)
            {
                chair.SetX(inputValues[i]);
                chair.SetY(inputValues[i]);
                Thread.Sleep(150);
                if (chair.VoltX != expectedValues[i])
                {
                    correctValues = false;
                }
                if (chair.VoltY != expectedValues[i])
                {
                    correctValues = false;
                }
            }
            //chair.End();
            chair.Dispose();
            Assert.IsTrue(correctValues, "Voltages are not correct.");
        }
示例#3
0
        public void Start_InvalidPortName_ShouldThrowArgumentException()
        {
            MockSerialDevice serialDevice = new MockSerialDevice("Con3", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Invalid Port Name. Argument Exception was not thrown.");
        }
示例#4
0
        public void Start_InvalidComPort_ShouldThrowIOException()
        {
            MockSerialDevice serialDevice = new MockSerialDevice("COM7", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Invalid COM Port. IO Exception was not thrown.");
        }
示例#5
0
        public void Start_PortInUse_ShouldThrowUnauthorizedEx()
        {
            // Setup
            MockSerialDevice serialDevice = new MockSerialDevice("COM5", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Unauthorized Access Exception was not thrown.");
        }
示例#6
0
        public void Start_InvalidBaudRate_ShouldThrowOutOfRange()
        {
            bool caught = false;

            try
            {
                MockSerialDevice serialDevice = new MockSerialDevice("COM3", 0);
                Wheelchair       chair        = Wheelchair.Instance(serialDevice);
            }
            catch (ArgumentOutOfRangeException e)
            {
                caught = true;
                Assert.AreEqual("BaudRate", e.ParamName);
            }
            if (!caught)
            {
                Assert.Fail("ArgumentOutOfRangeException was not thrown.");
            }
        }
示例#7
0
        public void SetSpeedAndDirection_Inputs()
        {
            //int[] directions = {0, 45, 90, 180, 270};
            Vector[]         directions    = { new Vector(0, 0), new Vector(0, 1), new Vector(1, 0), new Vector(0, -1), new Vector(-1, 0) };
            int[]            expected_x    = { 128, 172, 190, 128, 66 };
            int[]            expected_y    = { 190, 172, 128, 66, 128 };
            string           message       = "";
            bool             correctValues = true;
            MockSerialDevice serialDevice  = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair         = Wheelchair.Instance(serialDevice);

            chair.Start();
            for (int i = 0; i < 5; i++)
            {
                chair.SetSpeedAndDirection(100, directions[i]);
                Thread.Sleep(100);
                if (chair.VoltX != expected_x[i])
                {
                    correctValues = false;
                    message      += "Direction[" + directions[i];
                    message      += "] was incorrect (X Voltage). Expected:";
                    message      += expected_x[i] + ", Actual:";
                    message      += chair.VoltX;
                    break;
                }
                if (chair.VoltY != expected_y[i])
                {
                    correctValues = false;
                    message      += "Direction[" + directions[i];
                    message      += "] was incorrect (Y Voltage). Expected:";
                    message      += expected_y[i] + ", Actual:";
                    message      += chair.VoltY;
                    break;
                }
            }
            chair.Dispose();
            Assert.IsTrue(correctValues, message);
        }
        /// <summary>
        /// Because currently Entity does not like working with this many linking tables, we have to manually overwrite the data.
        /// </summary>
        /// <param name="wheelchair">Old wheelchair with data inside it</param>
        /// <returns>
        /// New wheelchair with the data of the old wheelchair
        /// </returns>
        private Wheelchair OverwriteWheelchairData(Wheelchair wheelchair)
        {
            Wheelchair newWheelchair = new Wheelchair();

            newWheelchair.Addition   = wheelchair.Addition;
            newWheelchair.AdditionId = wheelchair.AdditionId;
            List <WheelchairArticle>        newArticles    = new List <WheelchairArticle>();
            List <WheelchairFrontwheel>     newFrontwheels = new List <WheelchairFrontwheel>();
            List <WheelchairHoop>           newHoops       = new List <WheelchairHoop>();
            List <WheelchairTire>           newTires       = new List <WheelchairTire>();
            List <WheelchairWheel>          newWheels      = new List <WheelchairWheel>();
            List <WheelchairWheelprotector> newWP          = new List <WheelchairWheelprotector>();

            foreach (var item in wheelchair.Articles)
            {
                newArticles.Add(new WheelchairArticle()
                {
                    Addition   = item.Addition,
                    AdditionId = item.AdditionId,
                    ArticleId  = item.ArticleId
                });
            }
            foreach (var item in wheelchair.Frontwheels)
            {
                newFrontwheels.Add(new WheelchairFrontwheel()
                {
                    Addition     = item.Addition,
                    AdditionId   = item.AdditionId,
                    FrontWheelId = item.FrontWheelId
                });
            }
            foreach (var item in wheelchair.Hoops)
            {
                newHoops.Add(new WheelchairHoop()
                {
                    Addition   = item.Addition,
                    AdditionId = item.AdditionId,
                    HoopId     = item.HoopId
                });
            }
            foreach (var item in wheelchair.Tires)
            {
                newTires.Add(new WheelchairTire()
                {
                    Addition   = item.Addition,
                    AdditionId = item.AdditionId,
                    TireId     = item.TireId
                });
            }
            foreach (var item in wheelchair.Wheels)
            {
                newWheels.Add(new WheelchairWheel()
                {
                    Addition   = item.Addition,
                    AdditionId = item.AdditionId,
                    WheelId    = item.WheelId
                });
            }
            foreach (var item in wheelchair.Wheelprotectors)
            {
                newWP.Add(new WheelchairWheelprotector()
                {
                    Addition         = item.Addition,
                    AdditionId       = item.AdditionId,
                    WheelprotectorId = item.WheelprotectorId
                });
            }

            newWheelchair.Articles          = newArticles;
            newWheelchair.BackrestHeight    = wheelchair.BackrestHeight;
            newWheelchair.BalancePoint      = wheelchair.BalancePoint;
            newWheelchair.Color             = wheelchair.Color;
            newWheelchair.CustomerId        = wheelchair.CustomerId;
            newWheelchair.DateOfMeasurement = wheelchair.DateOfMeasurement;
            newWheelchair.Dealer            = wheelchair.Dealer;
            newWheelchair.FootplateWidth    = wheelchair.FootplateWidth;
            newWheelchair.FrameLength       = wheelchair.FrameLength;
            newWheelchair.Frontwheels       = wheelchair.Frontwheels;
            newWheelchair.Hoops             = newHoops;
            newWheelchair.LowerLegWidth     = wheelchair.LowerLegWidth;
            newWheelchair.OrderDate         = wheelchair.OrderDate;
            newWheelchair.RalId             = wheelchair.RalId;
            newWheelchair.SeatDepth         = wheelchair.SeatDepth;
            newWheelchair.SeatHeightBack    = wheelchair.SeatHeightBack;
            newWheelchair.SeatHeightFront   = wheelchair.SeatHeightFront;
            newWheelchair.SeatWidth         = wheelchair.SeatWidth;
            newWheelchair.SerialNumber      = wheelchair.SerialNumber;
            newWheelchair.Tires             = newTires;
            newWheelchair.User            = wheelchair.User;
            newWheelchair.UserId          = wheelchair.UserId;
            newWheelchair.Wheelprotectors = newWP;
            newWheelchair.Wheels          = newWheels;

            return(newWheelchair);
        }
        public IHttpActionResult EditWheelchair([FromBody] Wheelchair wheelchair)
        {
            Wheelchair newWheelchair = new Wheelchair();

            User user = new User();
            int  authorizedMessage = (int)AuthorizationService.CheckIfAuthorized(ref user, ref _database, Request.Headers, AccessLevel.Admin);

            if (authorizedMessage == 1 || authorizedMessage == 2)
            {
                return(Content(HttpStatusCode.Forbidden, "User not logged in."));
            }
            if (authorizedMessage == 3)
            {
                return(Content(HttpStatusCode.Unauthorized, "User has no permission."));
            }
            if (authorizedMessage == 4)
            {
                return(Content(HttpStatusCode.Forbidden, "User account is disabled."));
            }

            if (wheelchair.FootplateWidth == 0 || wheelchair.FrameLength == 0 || wheelchair.LowerLegWidth == 0 || wheelchair.SeatDepth == 0 ||
                wheelchair.SeatHeightBack == 0 || wheelchair.SeatHeightFront == 0 || wheelchair.SeatWidth == 0)
            {
                return(BadRequest("Incorrect wheelchair sizes!"));
            }

            if (wheelchair.Articles == null)
            {
                return(BadRequest("Wheelchair must have atleast one article!"));
            }

            if (wheelchair.CustomerId == 0)
            {
                return(BadRequest("Wheelchair must have a customer bound!"));
            }

            if (wheelchair.Frontwheels == null)
            {
                return(BadRequest("Wheelchair must have atleast one frontwheel set!"));
            }

            if (wheelchair.Hoops == null)
            {
                return(BadRequest("Wheelchair must have atleast one hoop set!"));
            }

            if (wheelchair.Tires == null)
            {
                return(BadRequest("Wheelchair must have atleast one tire set!"));
            }

            if (wheelchair.Wheels == null)
            {
                return(BadRequest("Wheelchair must have atleast one wheel set!"));
            }

            if (wheelchair.Color == null)
            {
                return(BadRequest("Wheelchair must have a color!"));
            }

            if (wheelchair.OldId == 0)
            {
                wheelchair.DateOfMeasurement = DateTime.Now;
                wheelchair.Dealer            = "TNS Rijen";
                wheelchair.UserId            = user.Id;

                _database.Wheelchairs.Add(wheelchair);
            }
            else
            {
                wheelchair.User   = user;
                wheelchair.UserId = user.Id;
                wheelchair.RalId  = wheelchair.Color.Id;

                var articles    = _database.WheelchairArticles.Where(x => x.WheelchairId == wheelchair.OldId);
                var frontwheels = _database.WheelchairFrontwheels.Where(x => x.WheelchairId == wheelchair.OldId);
                var hoops       = _database.WheelchairHoops.Where(x => x.WheelchairId == wheelchair.OldId);
                var tires       = _database.WheelchairTires.Where(x => x.WheelchairId == wheelchair.OldId);
                var wps         = _database.WheelchairWheelprotectors.Where(x => x.WheelchairId == wheelchair.OldId);
                var wheels      = _database.WheelchairWheels.Where(x => x.WheelchairId == wheelchair.OldId);
                if (articles != null)
                {
                    _database.WheelchairArticles.RemoveRange(articles);
                }
                if (frontwheels != null)
                {
                    _database.WheelchairFrontwheels.RemoveRange(frontwheels);
                }
                if (hoops != null)
                {
                    _database.WheelchairHoops.RemoveRange(hoops);
                }
                if (tires != null)
                {
                    _database.WheelchairTires.RemoveRange(tires);
                }
                if (wps != null)
                {
                    _database.WheelchairWheelprotectors.RemoveRange(wps);
                }
                if (wheels != null)
                {
                    _database.WheelchairWheels.RemoveRange(wheels);
                }

                foreach (var item in wheelchair.Articles)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                foreach (var item in wheelchair.Frontwheels)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                foreach (var item in wheelchair.Hoops)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                foreach (var item in wheelchair.Tires)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                foreach (var item in wheelchair.Wheelprotectors)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                foreach (var item in wheelchair.Wheels)
                {
                    _database.Context.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    item.WheelchairId = 0;
                }
                _database.Context.SaveChanges();

                _database.Wheelchairs.Remove(_database.Wheelchairs.Where(x => x.Id == wheelchair.OldId).FirstOrDefault());
                _database.Context.SaveChanges();
                newWheelchair = OverwriteWheelchairData(wheelchair);

                _database.Wheelchairs.Add(newWheelchair);
            }

            _database.Context.SaveChanges();

            if (newWheelchair.Id == 0)
            {
                return(Ok(wheelchair));
            }
            else
            {
                return(Ok(newWheelchair));
            }
        }
示例#10
0
        static void Main()
        {
            //change the test file xml here and make sure it is in bin.
            string startingXMLFile = "ETRL_03_07.xml";
            //string startingXMLFile = "FloorPlanTest.xml";
            //string startingOpenFile = "Sloan46_FINAL.xml";
            double compassToMapOffset = 72.0;

            // List of all the objects we'll be initializing.
            // Default to null, as some of them will only
            // be initialized conditionally e.g.
            // vehicle is only initialized if
            // there is a vehicle connected.
            SerialPort        sp               = null;
            IVehicle          vehicle          = null;
            IImageStream      depthStream      = null;
            IImageStream      videoStream      = null;
            IObstacleDetector obstacleDetector = null;
            ICartographer     cartographer     = null;
            IOdometer         odometer         = null;
            IInputDevice      input            = KeyboardInput.Instance;
            ObstacleMap       obstacleMap      = null;
            INavigator        navigator        = null;
            MainWindow        mainWindow       = null;

            Driver.Driver            driver           = null;
            VisualInputGridPresenter uiInputPresenter = null;
            ObstacleGridPresenter    uiGridPresenter  = null;
            PositioningSystem        ips             = null;
            OverlayRenderer          overlayRenderer = null;
            SensorArray       sensorArray            = null;
            Pose              pose              = null;
            IDoorDetector     doorDetector      = null;
            ObstacleLocalizer obstacleLocalizer = null;
            SonarDetector     sonarDetector     = null;

            Config.Initialize();

            Devices.Initialize();
            //string wheelchair_com_port = Devices.IsWheelchairConnected();
            string wheelchair_com_port = "COM3";//Devices.FindComPort("Arduino Uno");
            bool   WheelChairConnected = false;

            if (wheelchair_com_port != "")
            {
                WheelChairConnected = true;
            }
            //bool WheelChairConnected = true;
            bool EyeTribeConnected   = true; // Devices.IsEyeTribeConnected();
            bool ControllerConnected = true; //Devices.IsControllerConnected();
            bool KinectConnected     = true; //Devices.IsKinectConnected();

            //Console.WriteLine("Kinect Connected: {0}", KinectConnected.ToString());
            //Console.WriteLine("Eyetribe Connected: {0}", EyeTribeConnected.ToString());
            //Console.WriteLine("Wheelchair Connected: {0}", WheelChairConnected.ToString());
            //Console.WriteLine("Controller Connected: {0}", ControllerConnected.ToString());

            // Initialize vehicle and serial connection if
            // there is a vehicle connected.

            if (WheelChairConnected)
            {
                //sp = new SerialPort(wheelchair_com_port, 9600);
                vehicle = Wheelchair.Instance(wheelchair_com_port);
                vehicle.initializeOffset(Properties.Settings.Default.CalibrationOffset);
            }
            else
            {
                vehicle = new MockVehicle();

                MockVehicleWindow mockDisplay = new MockVehicleWindow((MockVehicle)vehicle);
                mockDisplay.Show();
            }

            //initalize IPS here

            IByteReader sensorReader = null;

            try
            {
                //sensorReader = new SerialByteReader("Arduino Mega");
                sensorReader = new SerialByteReader("COM4");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            if (sensorReader != null)
            {
                ILogger logger = new NullLogger();
                sensorArray   = new SensorArray(sensorReader, logger);
                sonarDetector = new SonarDetector();
            }
            else
            {
                sensorReader = new NullByteReader();

                ILogger logger = new NullLogger();
                sensorArray = new SensorArray(sensorReader, logger);
            }

            IByteReader byteReader = null;

            try
            {
                //byteReader = new SerialByteReader(Devices.FindComPort("STMicroelectronics"));
                byteReader = new SerialByteReader("COM3");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            if (byteReader != null)
            {
                ILogger logger = new NullLogger();
                ips = new MarvelMind(byteReader, logger);
            }
            else
            {
                //Setup Mock IPS

                //IByteReader mockByteReader = new FileByteReader(@"C:\Users\Dana\Documents\Visual Studio 2013\Projects\UITests\UITests\Mock_IPS_Data.txt");
                //IByteReader mockByteReader = new XLineFixedYByteReader(800, 100, 200);
                IByteReader mockByteReader = new RandomByteReader(300, 299);
                ILogger     mockLogger     = new NullLogger();
                ips = new MarvelMind(mockByteReader, mockLogger);
            }

            //wait for an iteration of the IPS system that way
            //we can get the starting location
            while (false == ips.XUpdated && false == ips.YUpdated)
            {
                continue;
            }

            //Tuple<double, double> t = new Tuple<double, double>((double)ips.X, (double)ips.Y);
            Tuple <double, double> t    = new Tuple <double, double>((double)ips.Y, (double)ips.X);
            mPoint startingLocationInXY = new mPoint(t);

            // UI, input, object detection, navigation, and driver are initialized always,
            // as they are not directly dependent on external hardware.
            obstacleMap = new ObstacleMap();
            //cartographer = new Cartographer(Directory.GetCurrentDirectory() + @"\FloorPlanTest.xml", ips);

            // might need to be changed later. If the location is not in the starting room. add staring room.
            //cartographer = new Cartographer(Directory.GetCurrentDirectory() + @"\FloorPlanTest.xml", startingLocationInXY);

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "XML | *.xml";
            ofd.Title  = "Open Map";
            if (ofd.ShowDialog() == true)
            {
                startingXMLFile = ofd.FileName;
                Console.WriteLine(startingXMLFile);
            }

            cartographer = new Cartographer(startingXMLFile, startingLocationInXY);
            pose         = new Pose(ips, cartographer.GetStartingRoom(), sensorArray.CompassDevice, compassToMapOffset);

            overlayRenderer = new OverlayRenderer();

            if (KinectConnected)
            {
                depthStream = DepthStream.Instance;
                videoStream = VideoStream.Instance;

                // Initialize depthstream if kinect is connected.
                obstacleDetector = new ObstacleDetector(depthStream, false);
                obstacleDetector.Start();

                obstacleLocalizer = new ObstacleLocalizer(pose);

                ObstaclesOverlay obstaclesOverlay = new ObstaclesOverlay(obstacleDetector);
                overlayRenderer.Overlays.Add(obstaclesOverlay);

                doorDetector = new DepthBasedDoorDetector();
                doorDetector.RunAsync(depthStream);

                try
                {
                    sonarDetector.RunAsync(sensorArray);
                }
                catch (Exception e)
                {
                }
            }

            // Obstacle detector and driver are only run
            // if both the vehicle and kinect are connected.
            if (vehicle != null && KinectConnected)
            {
                Vector startPoint    = new Vector(7 / 0.75f, 43 / 0.75f);
                Vector startRotation = new Vector(-7, -43);
                startRotation.Normalize();
                odometer = new Odometer();

                navigator = new Navigator(obstacleMap, obstacleDetector, obstacleLocalizer, cartographer, doorDetector, pose, sonarDetector, sensorArray);
                driver    = new Driver.Driver(input, vehicle, navigator);
                driver.Start();
            }

            mainWindow       = new MainWindow(pose, obstacleMap, cartographer, navigator, doorDetector, overlayRenderer, EyeTribeConnected, ControllerConnected, sensorArray);
            uiInputPresenter = new VisualInputGridPresenter(mainWindow.visualInputGrid);

            //This starts the program.
            Application app = new Application();

            app.ShutdownMode = ShutdownMode.OnMainWindowClose;
            app.MainWindow   = mainWindow;
            app.MainWindow.Show();
            app.Run();
        }