public async void ScannerTask() { /* Initialize UltraSonic Distance Sensor */ Library.Sensor.UltrasonicDistanceSensor DistanceSensor = new Library.Sensor.UltrasonicDistanceSensor(Library.Sensor.UltrasonicDistanceSensor.AvailableGpioPin.GpioPin_22, Library.Sensor.UltrasonicDistanceSensor.AvailableGpioPin.GpioPin_27); /* * 'CurrentRotation' Holds the current rotation * ============|===========================|=========== * Description | Actual Data Feed To Servo | Assumption * ============|===========================|=========== * Left Most | 0 | -70 * Center | 70 | 0 * Right Most | 140 | +70 */ byte CurrentRotation = 70; // << HOLDS ACTUAL DATA TO BE FEED TO SERVO /* * Holds direction to move +1 means scanner should move right * -1 means scanner should move left */ int Direction = 1; double Distance; byte Temp; /* Scan infinitely */ while (true) { /* * Take multiple sample of the distance in current sight * Higher the sampling, accurate the result but will cause slower scanning. */ Distance = 0; // Reset Distance for (int i = 0; i < NumberOfSample; i++) { Distance += DistanceSensor.GetDistance(); // Add distance await Task.Delay(1); // Wait for a ms } Distance /= NumberOfSample; // Calculate average /* * Send current angle to Gateway to set servo * This project was developed to map object distances between -70 to +70 degree * Thus servo will move between: 00 - 70 - 140 (Actual Angle) * -70 - 0 - +70 (Assumed Angle) */ Temp = (byte)((140 - CurrentRotation > 0) ? 140 - CurrentRotation : 0); /* Send angle to the gateway in a byte */ /* A dummy byte will be returned from the function */ Temp = Library.Communication.ArduinoGateway.MoveServo(Temp).Result[0]; /* * If right direction is fully mapped, change scanning direction to left. * Or else if left is fully scanned, change direction to right. */ if (CurrentRotation > 140) { Direction = -1; CurrentRotation = (byte)(CurrentRotation + Direction); } else if (CurrentRotation == 0) { Direction = 1; CurrentRotation = (byte)(CurrentRotation + Direction); } /* Update current rotation with direction */ CurrentRotation = (byte)(CurrentRotation + Direction); /* * Update UI * Dispatcher will helps to update UI components acquired by Main thread. (Because we're on another thread) */ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { /* Convert current rotation from 0 to 140 into -70 to +70 */ ScannerLine.Angle = CurrentRotation - 70; /* If all available angles has been scanned for a direction, clean LiDAR map */ if (ScannerLine.Angle == -70 || ScannerLine.Angle == 70) { Grid_Mapper.Children.Clear(); } /* Do not plot object > 500 cm */ if (Distance > 500) { Distance = 0; } /* LiDAR map developed for this project is only for up-to 300 cm. Thus eliminate higher distances. */ if (Distance > 299) { Distance = 299; } /* Plot distance into LiDAR map */ Grid_Mapper.Children.Add(DistanceMapper.GetMapper(ScannerLine.Angle, (int)Distance)); }); /* Hold for 5ms to take breath entire system */ await Task.Delay(5); } }
public static void CreateRenderables() { RedSea.Singleton.SetMapper(RedSea.Display.CP_TRACKING, mapperCP); RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_CORES, mapperPathCore); RedSea.Singleton.SetMapper(RedSea.Display.MEMBER_COMPARISON, mapperComparison); RedSea.Singleton.SetMapper(RedSea.Display.OKUBO_WEISS, mapperOW); //mapperFlowMap = new FlowMapMapper(new LoaderNCF.SliceRange[] { ensembleU, ensembleV }, redSea, velocity); //RedSea.Singleton.SetMapper(RedSea.Display.FLOW_MAP_UNCERTAIN, mapperFlowMap); //mapperPathLength = new PathlineLengthMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_LENGTH, mapperPathLength); //mapperCutDiffusion = new DiffusionMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.CUT_DIFFUSION_MAP, mapperCutDiffusion); //mapperLocalDiffusion = new LocalDiffusionMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.LOCAL_DIFFUSION_MAP, mapperLocalDiffusion); //DataMapper pathlines = new PathlineRadius(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_RADIUS, pathlines); //SubstepViewer substep = new SubstepViewer(redSea); //RedSea.Singleton.SetMapper(RedSea.Display.SUBSTEP_VIEWER, substep); //DataMapper lineStatistics = new LineStatisticsMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.LINE_STATISTICS, lineStatistics); DataMapper coreDistance = new CoreDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CORE_DISTANCE, coreDistance); DataMapper predCoreDistance = new PredictedCoreDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.PREDICTOR_CORE_ANGLE, predCoreDistance); DataMapper circleCoreDistance = new ConcentricDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CONCENTRIC_DISTANCE, circleCoreDistance); DataMapper circleCoreTube = new ConcentricTubeMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CONCENTRIC_TUBE, circleCoreTube); DataMapper ftle = new MapperFTLE(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.FTLE_CONCENTRIC, ftle); DataMapper pathDist = new DistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_DISTANCE, pathDist); DataMapper donut = new DonutAnalyzer(redSea); RedSea.Singleton.SetMapper(RedSea.Display.DONUT_ANALYSIS, donut); if (mapperOW != null) RedSea.Singleton.SetMapper(RedSea.Display.OKUBO_WEISS, mapperOW); RedSea.Singleton.SetMapper(RedSea.Display.PLAYGROUND, new PlaygroundMapper(redSea)); //FieldAnalysis.AlphaStableFFF = 0; //var f = new VectorField(velocity, FieldAnalysis.StableFFF, 3, true); //Renderer.Singleton.AddRenderable(new FieldPlane(redSea, f.GetSlice(0), FieldPlane.RenderEffect.LIC)); //Random rnd = new Random(); //SquareMatrix x = new SquareMatrix(2); //x.m00 = /*(float)rnd.NextDouble();//*/0.8f; //x.m10 = /*(float)rnd.NextDouble();//*/-0.8f; //x.m01 = /*(float)rnd.NextDouble();//*/-0.3f; //x.m11 = /*(float)rnd.NextDouble();//*/1.6f; //SquareMatrix xT = x.Transposed(); //SquareMatrix cauchy = xT* x; //SquareMatrix e, lambda; //cauchy.Eigenanalysis(out lambda, out e); //Vector lambda2 = cauchy.EigenvaluesReal(); }
public static void CreateRenderables() { RedSea.Singleton.SetMapper(RedSea.Display.CP_TRACKING, mapperCP); RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_CORES, mapperPathCore); RedSea.Singleton.SetMapper(RedSea.Display.MEMBER_COMPARISON, mapperComparison); RedSea.Singleton.SetMapper(RedSea.Display.OKUBO_WEISS, mapperOW); //mapperFlowMap = new FlowMapMapper(new LoaderNCF.SliceRange[] { ensembleU, ensembleV }, redSea, velocity); //RedSea.Singleton.SetMapper(RedSea.Display.FLOW_MAP_UNCERTAIN, mapperFlowMap); //mapperPathLength = new PathlineLengthMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_LENGTH, mapperPathLength); //mapperCutDiffusion = new DiffusionMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.CUT_DIFFUSION_MAP, mapperCutDiffusion); //mapperLocalDiffusion = new LocalDiffusionMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.LOCAL_DIFFUSION_MAP, mapperLocalDiffusion); //DataMapper pathlines = new PathlineRadius(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_RADIUS, pathlines); //SubstepViewer substep = new SubstepViewer(redSea); //RedSea.Singleton.SetMapper(RedSea.Display.SUBSTEP_VIEWER, substep); //DataMapper lineStatistics = new LineStatisticsMapper(velocity, redSea); //RedSea.Singleton.SetMapper(RedSea.Display.LINE_STATISTICS, lineStatistics); DataMapper coreDistance = new CoreDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CORE_DISTANCE, coreDistance); DataMapper predCoreDistance = new PredictedCoreDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.PREDICTOR_CORE_ANGLE, predCoreDistance); DataMapper circleCoreDistance = new ConcentricDistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CONCENTRIC_DISTANCE, circleCoreDistance); DataMapper circleCoreTube = new ConcentricTubeMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.CONCENTRIC_TUBE, circleCoreTube); DataMapper ftle = new MapperFTLE(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.FTLE_CONCENTRIC, ftle); DataMapper coreOkubo = new CoreOkuboMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.OKUBO_CONCENTRIC, coreOkubo); DataMapper pathDist = new DistanceMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.PATHLINE_DISTANCE, pathDist); DataMapper donut = new DonutAnalyzer(redSea); RedSea.Singleton.SetMapper(RedSea.Display.DONUT_ANALYSIS, donut); if (mapperOW != null) { RedSea.Singleton.SetMapper(RedSea.Display.OKUBO_WEISS, mapperOW); } RedSea.Singleton.SetMapper(RedSea.Display.PLAYGROUND, new PlaygroundMapper(redSea)); DataMapper editor = new ConcentricEditorMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.AREA_EDITOR, editor); DataMapper coherency = new CoherencyMapper(12, redSea); RedSea.Singleton.SetMapper(RedSea.Display.COHERENCY, coherency); }