Advertisement
Guest User

MSO54 Demo Code

a guest
Jun 20th, 2019
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.72 KB | None | 0 0
  1. // Terrible control code.
  2. // TKA 06/2019 r0-alpha
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using Ivi.Visa;
  11. using NationalInstruments.Visa;
  12. using Thorlabs.MotionControl.DeviceManagerCLI;
  13. using Thorlabs.MotionControl.GenericMotorCLI;
  14. using Thorlabs.MotionControl.GenericMotorCLI.ControlParameters;
  15. using Thorlabs.MotionControl.GenericMotorCLI.AdvancedMotor;
  16. using Thorlabs.MotionControl.GenericMotorCLI.Settings;
  17. using Thorlabs.MotionControl.Benchtop.BrushlessMotorCLI;
  18.  
  19. namespace scopecontrol
  20. {
  21.     class Program
  22.     {
  23.        
  24.         static void Main(string[] args)
  25.         {
  26.             // Initalize the oscilloscope object
  27.            
  28.  
  29.             String stage_serial = "73878478";
  30.             Console.ReadLine();
  31.             DeviceManagerCLI.BuildDeviceList();
  32.             ScopeInterface tek_mso_54 = new ScopeInterface();
  33.             ScanConfiguration demoScan = new ScanConfiguration();
  34.             tek_mso_54.Resource = "USB0::0x0699::0x0522::C013000::INSTR";
  35.             tek_mso_54.ConnectResource();
  36.             tek_mso_54.InitalizeInterface();
  37.             demoScan.ConfigureScanStdIO();
  38.             demoScan.CalculateRunupDistance(0.75);
  39.             demoScan.GeneratePositionsForMove();
  40.             // Start Microscope Stage Bullshit Here....
  41.             StageInterface MLS203 = new StageInterface(stage_serial);
  42.             MLS203.HomeStages();
  43.             /********************
  44.               Main Scanning Loop
  45.             ********************/
  46.  
  47.             // Add the DC-Offset A+B and A-B Waveforms
  48.             tek_mso_54.SendCommand("MATH:ADDN \"MATH1\";:MATH:MATH1:DEFINE \"CH1 + CH2\"");
  49.             tek_mso_54.SendCommand("MATH:ADDN \"MATH2\";:MATH:MATH2:DEFINE \"CH1 - CH2\"");
  50.             tek_mso_54.SendCommand("DIS:GLO:MATH1:STATE 0;:DIS:GLO:MATH2:STATE 0");
  51.             //tek_mso_54.SendCommand("MATH:");
  52.             // Add the measurement badges for A+B and A-B
  53.             tek_mso_54.SendCommand("MEASU:ADDMEAS MEAN;:MEASU:MEAS1:SOU1 MATH1;:MEASU:MEAS1:LAB \"DC A+B\"" +
  54.                 ";:MEASU:MEAS1:MEASR:MIN 0.0E-3;:MEASU:MEAS1:MEASR:MAX 300.0E-3");
  55.             tek_mso_54.SendCommand("MEASU:ADDMEAS MEAN;:MEASU:MEAS2:SOU1 MATH2;:MEASU:MEAS2:LAB \"DC A-B\"" +
  56.                 ";:MEASU:MEAS2:MEASR:MIN -10.0E-3;:MEASU:MEAS2:MEASR:MAX 10.0E-3");
  57.             tek_mso_54.SendCommand("MEASU:ADDMEAS MEAN;:MEASU:MEAS3:SOU1 CH3;:MEASU:MEAS3:LAB \"DC-A\"" +
  58.                 ";:MEASU:MEAS3:MEASR:MIN 0.0E-3;:MEASU:MEAS3:MEASR:MAX 125.0E-3");
  59.             tek_mso_54.SendCommand("MEASU:ADDMEAS MEAN;:MEASU:MEAS4:SOU1 CH4;:MEASU:MEAS4:LAB \"DC-B\"" +
  60.                 ";:MEASU:MEAS4:MEASR:MIN 0.0E-3;:MEASU:MEAS4:MEASR:MAX 125.0E-3");
  61.             tek_mso_54.SendCommand("MEASU:ADDMEAS FREQUENCY;:MEASU:MEAS5:SOU1 CH1;:MEASU:MEAS5:LAB \"RF FRQ\"");
  62.             tek_mso_54.SendCommand("MEASU:ADDMEAS ACRMS;:MEASU:MEAS6:SOU1 CH1;:MEASU:MEAS6:LAB \"RF RMS\"");
  63.  
  64.  
  65.             Console.ReadLine();
  66.             for (int i = 0; i<demoScan.RequiredRows; i++)
  67.             {                
  68.                 Console.WriteLine("Line {0}: Moving to {1},{2}.", i, demoScan.TourPoints[i,0].ToString("N3"), demoScan.TourPoints[i,1].ToString("N3"));
  69.                 MLS203.MoveStage(demoScan.TourPoints[i, 0], demoScan.TourPoints[i, 1], demoScan.ScanVelocity);
  70.                 Console.WriteLine("Line {0}: Adding runup acceleration distance of {1}mm.", i, demoScan.AccelDistanceRequired.ToString("N3"));
  71.                 MLS203.MoveStage(demoScan.TourPoints[i, 0], (demoScan.TourPoints[i, 1] - demoScan.AccelDistanceRequired), demoScan.ScanVelocity);
  72.                 if(i==0)
  73.                 {
  74.                     Console.WriteLine("SCAN PREP: Align the detector so SAWs are being generated...");                    
  75.                     Console.WriteLine("SCAN PREP: Once enter is pressed, the cycle can only be aborted by hard shutdown.");
  76.                     // Setup the scope to auto-acquire so the user can tweak the alignment....
  77.                     tek_mso_54.SendCommand("ACQ:STOPA RUNST;:TRIG:A:MOD AUTO;:ACQ:STATE 1");
  78.                     Console.ReadLine();
  79.                     tek_mso_54.SendCommand("ACQ:STATE 0;:TRIG:A:MOD NORM");
  80.  
  81.                 }
  82.                 // Setup the Oscilloscope for the impending scan.
  83.                 tek_mso_54.SendCommand("ACQ:STATE 0;:ACQ:MODE SAM;:ACQ:SEQ:MOD " + demoScan.TotalPoints.ToString() +";:ACQ:STOPA SEQ;");
  84.                 tek_mso_54.SendCommand("HOR:FAST:STATE 1;:HOR:FAST:COUN " + demoScan.TotalPoints.ToString() + ";:HOR:FAST:SUMF:STATE OFF");
  85.  
  86.                 // AFG Commands to simulate photodiode trigger signal
  87.                 Console.WriteLine("AFG: Starting Function Generator. 20kHz. 0-0.750V Sine, High-Z.");
  88.                 tek_mso_54.SendCommand("AFG:OUTP:STATE 0;:AFG:FUNC SINE;:AFG:LOWL 0.0;:AFG:HIGHL 0.750;:AFG:OUTP:LOA:IMPED HIGHZ;:AFG:OUTP:STATE 1");
  89.                 tek_mso_54.SendCommand("ACQ:STATE 1");
  90.                 Console.WriteLine("Line {0}: Moving to {1},{2}. Scanning Line.", i, demoScan.TourPoints[i, 2].ToString("N3"), demoScan.TourPoints[i, 3].ToString("N3"));
  91.                 MLS203.MoveStage(demoScan.TourPoints[i, 2], demoScan.TourPoints[i, 3], demoScan.ScanVelocity);
  92.                 tek_mso_54.SendCommand("AFG:OUTP:STATE 0");
  93.                 for(int j = 0; j < demoScan.TotalPoints; j++)
  94.                 {
  95.                     tek_mso_54.SendCommand("HOR:FAST:SELECTED " + j.ToString());
  96.  
  97.                     Console.WriteLine("Dumping Curves to PC...");
  98.                     // Setup Encoding
  99.                     Console.WriteLine(tek_mso_54.SendQuery("DATA:SOURCE:AVAILABLE?"));
  100.                     Console.WriteLine("Continue?");
  101.  
  102.                     Console.ReadLine();
  103.                     tek_mso_54.SendCommand("DATA:SOURCE CH1;:DATA:START 1;:DATA:END 10;:WFMOUTPRE:ENCDG ASCII");
  104.                     tek_mso_54.SendCommand(":CURVE?");
  105.                     var theCurve = tek_mso_54.SessionHandle.RawIO.Read(1024);
  106.                     Console.WriteLine("Transfer Complete, please press Return to see data...");
  107.                     Console.ReadLine();
  108.                     Console.WriteLine(theCurve);
  109.                 }
  110.                 Console.ReadLine();
  111.             }
  112.             Console.ReadLine();
  113.            
  114.             tek_mso_54.DisconnectResource();
  115.             Console.ReadLine();
  116.  
  117.         }
  118.     }
  119.  
  120.     public class ScopeInterface
  121.     {
  122.         private String resource_id;
  123.         public bool IsConnected { get; set; }
  124.         bool verbose;
  125.         public MessageBasedSession SessionHandle = null;
  126.         public ResourceManager SessionRM = null;
  127.        
  128.         public ScopeInterface()
  129.         {
  130.             this.resource_id = "Not initialized";
  131.             this.IsConnected = false;
  132.             this.verbose = true;
  133.             return;
  134.         }
  135.  
  136.         public String Resource
  137.         {
  138.             get { return resource_id; }
  139.             set { this.resource_id = value; }
  140.         }
  141.  
  142.         public void ConnectResource()
  143.         {
  144.             if(this.verbose)
  145.             {
  146.                 Console.WriteLine("Attempting to open MessageBasedSession to " + this.resource_id);
  147.                 this.SessionRM = new ResourceManager();
  148.                 try
  149.                 {
  150.                     this.SessionHandle = (MessageBasedSession)this.SessionRM.Open(this.resource_id);
  151.                     if(this.verbose)
  152.                     {
  153.                         Console.WriteLine("Connected to: " + this.resource_id + " successfully...");
  154.                         this.IsConnected = true;
  155.                     }
  156.                 } catch (Exception exp)
  157.                 {
  158.                     Console.WriteLine(exp.Message);
  159.                 }
  160.  
  161.             }
  162.         }
  163.  
  164.         public void DisconnectResource()
  165.         {
  166.             if(verbose)
  167.             {
  168.                 Console.WriteLine("Disconnecting from resource " + this.resource_id);
  169.             }
  170.             this.SessionHandle.Dispose();
  171.             this.IsConnected = false;
  172.         }
  173.  
  174.         public void SendCommand(String _command)
  175.         {
  176.             if(IsConnected)
  177.             {
  178.                 try
  179.                 {
  180.                     this.SessionHandle.TimeoutMilliseconds = 5000;
  181.                    
  182.                     this.SessionHandle.SendEndEnabled = true;
  183.                     this.SessionHandle.TerminationCharacterEnabled = true;
  184.  
  185.                     this.SessionHandle.FormattedIO.WriteLine(_command);
  186.                     return;
  187.                 } catch (Exception exp)
  188.                 {
  189.                     Console.WriteLine(exp.Message);
  190.                     Console.ReadLine();
  191.                     return;
  192.                 }
  193.             } else
  194.             {
  195.                 Console.WriteLine("Not connected...");
  196.                 Console.ReadLine();
  197.                 return;
  198.             }
  199.         }
  200.  
  201.         public String SendQuery(String _command)
  202.         {
  203.             if (IsConnected)
  204.             {
  205.                 try
  206.                 {
  207.                     if (verbose)
  208.                     {
  209.                         Console.WriteLine("Sending " + _command + " to " + this.resource_id);
  210.                     }
  211.                     this.SessionHandle.TimeoutMilliseconds = 7500;
  212.                    
  213.                     this.SessionHandle.FormattedIO.WriteLine(_command);
  214.                     String response = this.SessionHandle.FormattedIO.ReadLine();
  215.                     return response;
  216.                 }
  217.                 catch (Exception exp)
  218.                 {
  219.                     Console.WriteLine(exp.Message);
  220.                     Console.ReadLine();
  221.                     return "-1";
  222.                 }
  223.             }
  224.             else
  225.             {
  226.                 Console.WriteLine("Not connected...");
  227.                 Console.ReadLine();
  228.                 return "-1";
  229.             }
  230.         }
  231.  
  232.         public void InitalizeInterface()
  233.         {
  234.             Console.WriteLine("******************************************");
  235.             Console.WriteLine("*        INITIALIZING OSCILLOSCOPE       *");
  236.             Console.WriteLine("*            TEK MSO54 ON USB3           *");
  237.             Console.WriteLine("*              RESOURCE ID:              *");
  238.             Console.WriteLine("*  " + this.resource_id + "  *");
  239.             Console.WriteLine("******************************************");
  240.             Console.WriteLine("\nClearing oscilloscope...");
  241.             this.SendCommand("*RST");
  242.             Console.WriteLine(this.SendQuery("*OPC?"));
  243.            
  244.             // Stop Acquisition
  245.             this.SendCommand("ACQUIRE:STATE STOP");
  246.  
  247.             // Setup Channels
  248.             this.SendCommand("DIS:GLO:CH1:STATE 1;:DIS:GLO:CH2:STATE 1;:DIS:GLO:CH3:STATE 1;:DIS:GLO:CH4:STATE 1");
  249.            
  250.             // Setup Impedances and Bandwidths
  251.             this.SendCommand("CH1:COUP AC;:CH2:COUP AC;:CH3:COUP DC;:CH4:COUP DC");
  252.             this.SendCommand("CH1:TER 1.0E+6;:CH2:TER 1.0E+6");
  253.             this.SendCommand("CH1:BAN 250E+6;:CH2:BAN 250E+6;:CH3:BAN 20E+6;:CH4:BAN 20E+6");
  254.  
  255.             // Setup Axes
  256.             this.SendCommand("CH1:SCA 100.0E-3;:CH2:SCA 500.0E-3;:CH3:SCA 40.0E-3;:CH4:SCA 40.0E-3");
  257.             this.SendCommand("HOR:MODE:SCA 20.0E-9;:HOR:POS 10");
  258.  
  259.             // Setup
  260.             // Normal Trigger Mode (aka, don't make rando triggers)
  261.             // Use the A-trigger, use Channel 2, Trigger at 800mV Rising Edge.
  262.             this.SendCommand("TRIG:A:MODE:NORM");
  263.             this.SendCommand("TRIG:A:EDGE:SOU CH2;:TRIG:A:EDGE:SLO RIS;");
  264.             this.SendCommand("TRIG:A:LEV:CH2 0.500E+0");
  265.  
  266.             // Label Axes
  267.             this.SendCommand("CH1:LAB:NAM \"SAW\";:CH2:LAB:NAM \"Optotrigger\";:CH3:LAB:NAM \"DC Offset-A\";:CH4:LAB:NAM \"DC Offset-B\"");
  268.             Console.WriteLine("********************************");
  269.             Console.WriteLine("* OSCILLOSCOPE SETUP COMPLETED *");
  270.             Console.WriteLine("********************************");
  271.             Console.WriteLine("Press Enter to continue initalizing hardware...");
  272.             Console.ReadLine();
  273.  
  274.         }
  275.     }
  276.  
  277.     public class StageInterface
  278.     {
  279.         public BenchtopBrushlessMotor StageMotor;
  280.         public BrushlessMotorChannel XAxis;
  281.         public BrushlessMotorChannel YAxis;
  282.         public MotorConfiguration XAxisConfig;
  283.         public MotorConfiguration YAxisConfig;
  284.  
  285.         public bool IsHomed;
  286.         public bool IsConnected;
  287.         public bool IsEnabled;
  288.  
  289.         public String SerialNumber;
  290.  
  291.         public int MovementTimeout = 10000;
  292.         public int PollingInterval = 100;
  293.         public decimal StageAccel { get; set; }
  294.  
  295.  
  296.         public StageInterface(String serial)
  297.         {
  298.             this.IsHomed = false;
  299.             this.IsConnected = false;
  300.             this.IsEnabled = false;
  301.             this.MovementTimeout = 15000;
  302.             this.PollingInterval = 100;
  303.             this.StageAccel = 2500.0m;
  304.             this.SerialNumber = serial;
  305.  
  306.             try
  307.             {
  308.                 Console.WriteLine("MICROSCOPE: Initalizing StageObject and AxesObjects...");
  309.                 this.StageMotor = BenchtopBrushlessMotor.CreateBenchtopBrushlessMotor(this.SerialNumber);
  310.                 Console.WriteLine("MICROSCOPE: Attempting to connect to " + this.SerialNumber + "....");
  311.                 this.StageMotor.Connect(this.SerialNumber);
  312.                 this.IsConnected = true;
  313.                 Console.WriteLine("MICROSCOPE: Connected! Assigning  and configuring X/Y axes...");
  314.                 this.XAxis = this.StageMotor.GetChannel(1);
  315.                 this.YAxis = this.StageMotor.GetChannel(2);
  316.                 if ((!this.XAxis.IsSettingsInitialized()) || (!this.YAxis.IsSettingsInitialized()))
  317.                 {
  318.                     XAxis.WaitForSettingsInitialized(this.MovementTimeout);
  319.                     YAxis.WaitForSettingsInitialized(this.MovementTimeout);
  320.                 }
  321.                 Thread.Sleep(200);
  322.  
  323.                 Console.WriteLine("MICROSCOPE: Beginning polling at " + this.PollingInterval + "ms...");
  324.                 this.XAxis.StartPolling(this.PollingInterval);
  325.                 this.YAxis.StartPolling(this.PollingInterval);
  326.  
  327.                 Console.WriteLine("MICROSCOPE: Generating X/Y Axes MotorConfigurations to enable encoder <-> mm conversions...");
  328.                 this.XAxisConfig = this.XAxis.LoadMotorConfiguration(this.XAxis.DeviceID);
  329.                 this.YAxisConfig = this.YAxis.LoadMotorConfiguration(this.YAxis.DeviceID);
  330.                 Thread.Sleep(250);
  331.                 this.XAxis.SetTriggerSwitches((byte)HardwareTriggeringSettings.TriggerOutputEnable.MaxVelocityHI);
  332.                 this.YAxis.SetTriggerSwitches((byte)HardwareTriggeringSettings.TriggerOutputEnable.MaxVelocityHI);
  333.                
  334.                 this.XAxis.EnableDevice();
  335.                 this.YAxis.EnableDevice();
  336.                 Thread.Sleep(250);
  337.  
  338.                 this.IsEnabled = true;
  339.             }
  340.             catch (Exception ex)
  341.             {
  342.                 Console.WriteLine(ex.Message);
  343.                 return;
  344.             }
  345.         }
  346.        
  347.             public void HomeStages()
  348.             {
  349.                 Console.WriteLine("MICROSCOPE: Homing X-Axis...");
  350.                 this.XAxis.Home(this.MovementTimeout);
  351.                 Console.WriteLine("MICROSCOPE: Homing Y-Axis...");
  352.                 this.YAxis.Home(this.MovementTimeout);
  353.                 return;
  354.             }
  355.  
  356.             public void MoveStage(decimal desired_x, decimal desired_y, decimal desired_v, bool _verby = false)
  357.             {
  358.                 this.XAxis.SetVelocityParams(desired_v, this.StageAccel);
  359.                 this.YAxis.SetVelocityParams(desired_v, this.StageAccel);
  360.  
  361.                 // Do the XAxis move first, the move YAxis. Kick move out to individual thread
  362.                 // so you can poll with the main thread.
  363.                 bool xMoveFinished = false;
  364.                 bool yMoveFinished = false;
  365.  
  366.                 Task xMoveWorker = Task.Factory.StartNew(() =>
  367.               {
  368.                   this.XAxis.MoveTo(desired_x, this.MovementTimeout);
  369.                   xMoveFinished = true;
  370.               });
  371.                 while (!xMoveFinished)
  372.                 {
  373.                     if (_verby)
  374.                     {
  375.                         Console.WriteLine("Moving\tX: " + this.XAxis.Position + "mm\tY: " + this.YAxis.Position + "mm");
  376.                     }
  377.                     Thread.Sleep(this.PollingInterval);
  378.                 }
  379.                 Task yMoveWorker = Task.Factory.StartNew(() =>
  380.                 {
  381.                     this.YAxis.MoveTo(desired_y, this.MovementTimeout);
  382.                     yMoveFinished = true;
  383.                 });
  384.                 while (!yMoveFinished)
  385.                 {
  386.                     if (_verby)
  387.                     {
  388.                         Console.WriteLine("Moving\tX: " + this.XAxis.Position + "mm\tY: " + this.YAxis.Position + "mm");
  389.                     }
  390.                     Thread.Sleep(this.PollingInterval);
  391.                 }
  392.             }
  393.         }
  394.  
  395.     public class ScanConfiguration
  396.     {
  397.         public decimal XOrigin { get; set; }
  398.         public decimal YOrigin { get; set; }
  399.         public decimal XDelta { get; set; }
  400.         public decimal YDelta { get; set; }
  401.         public decimal StepOver { get; set; }
  402.         public decimal ScanVelocity { get; set; }
  403.         public int LaserFrequency { get; set; }
  404.  
  405.         public decimal AccelDistanceRequired { get; set; }
  406.         public decimal StageAccelerationValue { get; set; }
  407.         public decimal PositionResolution { get; set; }
  408.  
  409.         public decimal[,] TourPoints;
  410.         public int TaintedPoints { get; set; }
  411.         public int LineLength { get; set; }
  412.         public int RequiredRows { get; set; }
  413.         public int TotalPoints { get; set; }
  414.         public int TotalScanPoints { get; set; }
  415.         public int GoodPoints { get; set; }
  416.  
  417.         public ScanConfiguration()
  418.         {
  419.             this.StepOver = 0.100m;
  420.             this.ScanVelocity = 200.0m;
  421.             this.LaserFrequency = 20000;
  422.             this.StageAccelerationValue = 2500.00m;
  423.             return;
  424.         }
  425.  
  426.         public void ConfigureScanStdIO()
  427.         {
  428.             Console.WriteLine("Enter the x-origin coordinate in mm: ");
  429.             String _xOStr = Console.ReadLine();
  430.             this.XOrigin = decimal.Parse(_xOStr);
  431.             Console.WriteLine("ScanConfiguration.XOrigin: " + this.XOrigin + "mm.");
  432.             Console.WriteLine("Enter the y-origin coordinate in mm: ");
  433.             String _yOStr = Console.ReadLine();
  434.             this.YOrigin = decimal.Parse(_yOStr);
  435.             Console.WriteLine("ScanConfiguration.YOrigin: " + this.YOrigin + "mm.");
  436.             Console.WriteLine("Enter the x-delta length in mm: ");
  437.             String _xDStr = Console.ReadLine();
  438.             this.XDelta = decimal.Parse(_xDStr);
  439.             Console.WriteLine("ScanConfiguration.XDelta: " + this.XDelta + "mm.");
  440.             Console.WriteLine("Enter the y-delta length in mm: ");
  441.             String _yDStr = Console.ReadLine();
  442.             this.YDelta = decimal.Parse(_yDStr);
  443.             Console.WriteLine("ScanConfiguration.YDelta: " + this.YDelta + "mm.");
  444.             Console.WriteLine("OTHER CONFIGURATION SETTINGS SET IN THE CLASS:");
  445.             Console.WriteLine("----------------------------------------------");
  446.             Console.WriteLine("ScanConfiguration.StepOver: " + this.StepOver + "mm.\t\tScanConfiguration.ScanVelocity: " + this.ScanVelocity + "mm/s.");
  447.             Console.WriteLine("ScanConfiguration.LaserFrequency: " + this.LaserFrequency + "Hz.\tScanConfiguration.StageAccelerationValue: " + this.StageAccelerationValue + "mm/s2.");
  448.             Console.WriteLine("Configuration completed. Scanpath can now be generated.");
  449.             Console.WriteLine("Press enter to continue...");
  450.             Console.ReadLine();
  451.             return;
  452.         }
  453.  
  454.         public void CalculateRunupDistance(double deratingFactor = 1.0)
  455.         {
  456.             decimal _baseDistance = (this.ScanVelocity / this.StageAccelerationValue);
  457.             this.AccelDistanceRequired = _baseDistance / (decimal)deratingFactor;
  458.             Console.WriteLine("SCAN CONFIG: For a={0}mm/s2, v={1}mm/s.",
  459.                 this.StageAccelerationValue.ToString("N2"), this.ScanVelocity.ToString("N2"));
  460.             Console.WriteLine("SCAN CONFIG: An additional {0}mm, minimum is required. Your derate is {1}.",
  461.                 _baseDistance.ToString("N3"), deratingFactor.ToString("N3"));
  462.             Console.WriteLine("SCAN CONFIG: Using the selected derate, {0}mm has been added to the beginning of the scan.",
  463.                 this.AccelDistanceRequired.ToString("N3"));
  464.  
  465.             this.TaintedPoints = (int)Math.Ceiling((this.AccelDistanceRequired / this.ScanVelocity) * this.LaserFrequency);
  466.             this.GoodPoints = (int)Math.Ceiling((this.XDelta / this.ScanVelocity) * this.LaserFrequency);
  467.             this.TotalPoints = this.GoodPoints + this.TaintedPoints;
  468.             Console.WriteLine("SCAN CONFIG: This will taint the first {0} points of the dataset. They will be marked as unreliable.", this.TaintedPoints);
  469.  
  470.             this.PositionResolution = this.ScanVelocity / this.LaserFrequency;
  471.             Console.WriteLine("SCAN CONFIG: A linescan will consist of {0} points, including {1} tainted, at a position resolution of {2}mm.",
  472.                 this.TotalPoints, this.TaintedPoints, this.PositionResolution.ToString("N3"));
  473.  
  474.             this.RequiredRows = (int)Math.Ceiling(this.YDelta / this.StepOver);
  475.             this.TotalPoints = (this.GoodPoints + this.TaintedPoints);
  476.             this.TotalScanPoints = this.TotalPoints * this.RequiredRows;
  477.             Console.WriteLine("SCAN CONFIG: {0} rows will be acquired. Total acquisition is {1} positions.", this.RequiredRows, this.TotalScanPoints);
  478.             Console.ReadLine();
  479.         }
  480.  
  481.         public void GeneratePositionsForMove()
  482.         {
  483.             int _totalPoints = 2 * this.RequiredRows;
  484.             this.TourPoints = new decimal[_totalPoints, 4];
  485.  
  486.             for(int i=0; i<this.RequiredRows; i++)
  487.             {
  488.                 decimal _xStart = this.XOrigin + i * this.StepOver;
  489.                 decimal _yStart = this.YOrigin;
  490.                 decimal _yEnd = this.YOrigin + this.YDelta;
  491.  
  492.                 this.TourPoints[i, 0] = _xStart;
  493.                 this.TourPoints[i, 1] = _yStart;
  494.                 this.TourPoints[i, 2] = _xStart;
  495.                 this.TourPoints[i, 3] = _yEnd;
  496.  
  497.                 Console.WriteLine("Line {0}: Start: {1},{2}\tEnd:{3},{4}", i, _xStart.ToString("N3"), _yStart.ToString("N3"),
  498.                     _xStart.ToString("N3"), _yEnd.ToString("N3"));
  499.             }
  500.         }
  501.     }
  502.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement