Beispiel #1
0
 private void posResetButton_Click(object sender, RoutedEventArgs e)
 {
     SerialSend("RSS");
     currentAP = new ArenaPosition(allSets.basicParas.ArmLength, 0, 0);
     posCtrlGrid.DataContext = currentAP;
     ShowPosInArena(currentAP);
 }
Beispiel #2
0
        private void loaderNextButton_Click(object sender, RoutedEventArgs e)
        {
            if (allSets.basicParas.onArmLoader)
            {
                SerialSend(CalculateLoaderSteps(1) + "f");
            }
            else if (currentOUS.preSetPosList.ContainsKey(5))
            {
                PreSetPos     psp   = (PreSetPos)currentOUS.preSetPosList[5];
                ArenaPosition fPos  = psp.aPos;
                ArenaPosition fpPos = new ArenaPosition(fPos.X, fPos.Y, 0);

                if (currentAP.X == fpPos.X && currentAP.Y == fpPos.Y)
                {
                    Go2ArenaPos(fPos);
                    SerialSend(CalculateLoaderSteps(1) + "f");
                    Go2ArenaPos(fpPos);
                }
                else
                {
                    MessageBox.Show("Please move the arm to food grabbing position first.", "Not in Position",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Beispiel #3
0
 private void InvokeGo2ArenaPos(ArenaPosition ap)
 {
     MainWindow.MWInstance.Dispatcher.Invoke((ThreadStart) delegate
     {
         Go2ArenaPos(ap);
     });
 }
Beispiel #4
0
 // Show Position in Arena with Circle
 private void ShowPosInArena(ArenaPosition ap)
 {
     MainWindow.MWInstance.Dispatcher.BeginInvoke(
         (ThreadStart) delegate()
     {
         RefreshCircles();
     });
 }
Beispiel #5
0
 public BehaviorRecord(int index, ArenaPosition a, ArenaPosition f)
 {
     trialIndex   = index;
     ap           = a;
     foodPosition = f;
     numAttempts  = 0;
     eventIndex   = 0;
 }
Beispiel #6
0
        public static Point Arena2ArenaUI(ArenaPosition ap)
        {
            MainWindow win = MainWindow.MWInstance;
            double     a   = win.allSets.basicParas.ArmLength;
            double     l   = win.allSets.basicParas.railLength;

            double top  = (1 - (ap.X + a) / (l + 2 * a)) * win.ArenaBoarderHeight;
            double left = ap.Y / a * win.ArenaBoarderWidth;

            return(new Point(top, left));
        }
Beispiel #7
0
 // To Where User Selected in the Arena
 private void Border_MouseDown_1(object sender, MouseButtonEventArgs e)
 {
     if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2 && !doingAutoFeed)
     {
         Point pt = Converter.ArenaUI2Arena(arenaPt);
         tempAP = new ArenaPosition(Math.Round(pt.X), Math.Round(pt.Y), currentAP.Z);
         if (Go2ArenaPos(tempAP))
         {
             RefreshCircles();
         }
     }
 }
Beispiel #8
0
        // Common Go to Position Method
        private bool Go2ArenaPos(ArenaPosition ap)
        {
            bool success = false;

            if (!ap.outOfRange && SerialSend(ap.Arena2RawCmd()))
            {
                currentAP = new ArenaPosition(ap.X, ap.Y, ap.Z);
                posCtrlGrid.DataContext = currentAP;
                ShowPosInArena(currentAP);
                success = true;
            }
            return(success);
        }
Beispiel #9
0
 private void DoSequentialFeed()
 {
     for (int i = 0; i < currentOUS.behaviorParas.cycNum; i++)
     {
         foreach (SeqPosition sp in seqPosList)
         {
             ArenaPosition ap = sp.ap;
             for (int j = 0; j < sp.repeat; j++)
             {
                 DoFeedCycle(ap);
             }
         }
         Thread.Sleep(TimeSpan.FromSeconds(currentOUS.behaviorParas.cycInterval));
     }
     AfterWork();
 }
Beispiel #10
0
        private Ellipse GetEllipse(ArenaPosition ap, Brush color, string tag)
        {
            Point targetPt = Converter.Arena2ArenaUI(ap);
            Ellipse circle = new Ellipse();
            circle.Stroke = Brushes.Black;
            circle.StrokeThickness = 1;
            circle.Height = 10;
            circle.Width = 10;
            circle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            circle.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            circle.Margin = new Thickness(targetPt.Y - 5, targetPt.X - 7, 0, 0);
            circle.Fill = color;

            circle.Tag = tag;
            arenaGrid.Children.Add(circle);
            return circle;
        }
Beispiel #11
0
 private void DoRandomFeed()
 {
     for (int i = 0; i < currentOUS.behaviorParas.trialNum; i++)
     {
         Random randGenerator = new Random();
         double randNum       = randGenerator.Next(0, chanceTopVal - 1);
         foreach (RandomPosition rp in randPosList)
         {
             if (rp.LieWithin(randNum))
             {
                 ArenaPosition ap = rp.ap;
                 DoFeedCycle(ap);
                 break;
             }
         }
     }
     AfterWork();
 }
Beispiel #12
0
        private void DoFeedCycle(ArenaPosition ap)
        {
            executed = false;

            currentTrialNum++;

            PreSetPos     foodPos    = (PreSetPos)currentOUS.preSetPosList[5];
            ArenaPosition preFoodPos = new ArenaPosition(allSets.basicParas.ArmLength, 0, 0);

            preFoodPos.L = foodPos.aPos.L;
            preFoodPos.H = foodPos.aPos.H;
            preFoodPos.R = foodPos.aPos.R;

            BehaviorRecord behaviorRecord = new BehaviorRecord(currentTrialNum, ap, foodPos.aPos);

            // Move to Food Loading Preparation Position
            InvokeGo2ArenaPos(preFoodPos);
            CheckExecuted();

            // Food Catching Position
            InvokeGo2ArenaPos(foodPos.aPos);
            CheckExecuted();

            // Get One New Food
            InvokeSerialSend(CalculateLoaderSteps(1) + "f");
            CheckExecuted();
            InvokeGo2ArenaPos(preFoodPos);
            CheckExecuted();

            // Waiting for Trial Begin Trigger
            if (currentOUS.behaviorParas.manualBegin)
            {
                // Note
                while (!triggered)
                {
                    Thread.Sleep(10);
                    CheckPoint();
                }
                // Remove Note
                triggered = false;
            }

            // Timing of Imaging Start
            if (currentOUS.behaviorParas.trigImg)
            {
                imgTimer = new Timer(InvokeSerialSend, "i", TimeSpan.FromMilliseconds(currentOUS.behaviorParas.imgDelay), TimeSpan.FromMilliseconds(-1));
            }

            // Move to Grabbing Position
            InvokeGo2ArenaPos(ap);
            CheckExecuted();
            InvokePrint("Trial Starts @ " + DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond / 10);

            // Timing of Cue
            if (currentOUS.behaviorParas.manualCue)
            {
                // Note
                while (!triggered)
                {
                    Thread.Sleep(10);
                    CheckPoint();
                }
                // Remove Note
                triggered = false;
            }
            else
            {
                int    halfWindow    = (int)Math.Round(currentOUS.behaviorParas.cueWindow / 2);
                Random randGenerator = new Random();
                double randCueDelay  = currentOUS.behaviorParas.cueDelay + randGenerator.Next(-halfWindow, halfWindow);
                Thread.Sleep(TimeSpan.FromMilliseconds(randCueDelay));
            }
            MainWindow.MWInstance.Dispatcher.Invoke((ThreadStart) delegate
            {
                SendCue();
            });

            // Timing of Trial End
            if (currentOUS.behaviorParas.manualEnd)
            {
                // Note
                while (!triggered)
                {
                    Thread.Sleep(10);
                    CheckPoint();
                }
                // Remove Note
                triggered = false;
            }
            else
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(currentOUS.behaviorParas.reachLimit));
            }
            InvokePrint("Trial Ends @ " + DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond / 10);

            // Cancel Timers (Even when they exceed waiting time)
            try
            {
                imgTimer.Dispose();
            }
            catch (Exception) { }


            // Move to Food Loading Preparation Position
            InvokeGo2ArenaPos(preFoodPos);
            CheckExecuted();
            InvokeSerialSend("c");


            //logCurrentSession.behaviorList.Add(behaviorRecord);
        }
Beispiel #13
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Loading all settings
            LoadAllSet();

            // Serial port configuration
            serialPort.BaudRate = 115200;
            serialPort.ReadTimeout = 500;
            serialPort.WriteTimeout = 500;

            // Startup configuration
            oneTimeCfgThread = new Thread(new ThreadStart(OneTimeConfiguration));
            oneTimeCfgThread.IsBackground = true;

            string[] portsAvailable = SerialPort.GetPortNames();
            foreach (string port in portsAvailable)
            {
                comComboBox.Items.Add(port);
                comComboBox.SelectedItem = port;
                try
                {
                    serialPort.Open();

                    serialReadThread = new Thread(new ThreadStart(SerialRead));
                    serialReadThread.IsBackground = true;
                    reading = true;
                    serialReadThread.Start();

                    SerialSend("MFZ");
                    Thread.Sleep(50);
                    if (thisDevice)
                    {
                        serialConnectButton.IsEnabled = false;
                        serialDisconButton.IsEnabled = true;
                        oneTimeCfgThread.Start();
                    }
                    else
                    {
                        reading = false;
                        serialReadThread.Join();
                        serialPort.Close();
                    }
                }
                catch (Exception)
                {
                    comComboBox.SelectedIndex = -1;
                }
            }

            // Show Points on UI
            currentAP = new ArenaPosition(allSets.basicParas.ArmLength, 0, 0);                          // Initial arena position
            posCtrlGrid.DataContext = currentAP;
            tempAP = new ArenaPosition(allSets.basicParas.ArmLength, 0, 0);

            double a = allSets.basicParas.ArmLength;
            double l = allSets.basicParas.railLength;
            arenaBoarder.Width = ArenaBoarderHeight * a / (l + 2 * a);
            upperBorder.Height = ArenaBoarderHeight * 2 * a / (l + 2 * a);
            lowerBorder.Height = ArenaBoarderHeight * 2 * a / (l + 2 * a);
            arenaBoarder.CornerRadius = new CornerRadius(0, ArenaBoarderWidth, ArenaBoarderWidth, 0);
            upperBorder.CornerRadius = arenaBoarder.CornerRadius;
            lowerBorder.CornerRadius = arenaBoarder.CornerRadius;
            GetEllipse(currentAP, Brushes.Tomato, "ap");

            // List out pre-set buttons
            posButtons.Add(preSetPos0Button);
            posButtons.Add(preSetPos1Button);
            posButtons.Add(preSetPos2Button);
            posButtons.Add(preSetPos3Button);

        }
Beispiel #14
0
 public PreSetPos(string n, double x, double y, double z)
 {
     posName = n;
     aPos    = new ArenaPosition(x, y, z);
 }
Beispiel #15
0
 public SeqPosition(LibPos lp)
 {
     ap     = new ArenaPosition(lp.X, lp.Y, lp.Z);
     repeat = lp.repeat;
 }
Beispiel #16
0
 public RandomPosition(LibPos lp, int accumulator)
 {
     lowEdge  = accumulator;
     highEdge = lp.chance + accumulator;
     ap       = new ArenaPosition(lp.X, lp.Y, lp.Z);
 }
Beispiel #17
0
 public bool Equals(ArenaPosition ap)
 {
     return(X == ap.X && Y == ap.Y && Z == ap.Z);
 }
Beispiel #18
0
 private void posUpButton_Click(object sender, RoutedEventArgs e)
 {
     tempAP = new ArenaPosition(currentAP.X, currentAP.Y, currentAP.Z + Convert.ToDouble(posStepSizeTextBox.Text));
     Go2ArenaPos(tempAP);
 }