Пример #1
0
        public ContinuousNeuralNetForm()
        {
            InitializeComponent();

            net = new NeuralNet(8, 7, ANNfilename, KFoldFilename);
            inputTrainingData  = new List <double[]>();
            outputTrainingData = new List <double[]>();

            if (inputTrainingData.Count > expirationTimer)
            {
                inputTrainingData.RemoveAt(0);
                outputTrainingData.RemoveAt(0);
            }

            serial = new SerialReader();
            serial.Read();

            UnityCommunicationHub.InitializeUnityCommunication();
            UnityCommunicationHub.TwoWayTransmission();

            Random rand = new Random(23);

            setPointList = Globals.GetBasicPositions();

            var firstPoint = setPointList[3];

            Globals.A1DesiredPosition = firstPoint.A1Position;
            Globals.A2DesiredPosition = firstPoint.A2Position;
            Globals.A3DesiredPosition = firstPoint.A3Position;
            Globals.B1DesiredPosition = firstPoint.B1Position;
            Globals.B2DesiredPosition = firstPoint.B2Position;
            Globals.B3DesiredPosition = firstPoint.B3Position;
            Globals.C1DesiredPosition = firstPoint.C1Position;
            Globals.C2DesiredPosition = firstPoint.C2Position;
            Globals.C3DesiredPosition = firstPoint.C3Position;
            Globals.D1DesiredPosition = firstPoint.D1Position;
            Globals.D2DesiredPosition = firstPoint.D2Position;
            Globals.D3DesiredPosition = firstPoint.D3Position;
            Globals.T1DesiredPosition = firstPoint.T1Position;
            Globals.T2DesiredPosition = firstPoint.T2Position;
            //Globals.T1DesiredPosition = (float)rand.Next(0, 90);
            //Globals.T2DesiredPosition = (float)rand.Next(0, 90);
            //Globals.A1DesiredPosition = (float)rand.Next(0, 90);
            //Globals.A2DesiredPosition = (float)rand.Next(0, 90);
            //Globals.A3DesiredPosition = (float)rand.Next(0, 90);
            //Globals.B1DesiredPosition = (float)rand.Next(0, 90);
            //Globals.B2DesiredPosition = (float)rand.Next(0, 90);
            //Globals.B3DesiredPosition = (float)rand.Next(0, 90);
            //Globals.C1DesiredPosition = (float)rand.Next(0, 90);
            //Globals.C2DesiredPosition = (float)rand.Next(0, 90);
            //Globals.C3DesiredPosition = (float)rand.Next(0, 90);
            //Globals.D1DesiredPosition = (float)rand.Next(0, 90);
            //Globals.D2DesiredPosition = (float)rand.Next(0, 90);
            //Globals.D3DesiredPosition = (float)rand.Next(0, 90);


            lastSetPoint = firstPoint;
            UnityCommunicationHub.WriteData(true);
        }
Пример #2
0
 public Node(string name, SetPoint handPosition, int id, List <int> children, int parent)
 {
     this.name     = name;
     this.id       = id;
     this.children = children;
     this.parent   = parent;
     this.setHandPosition(handPosition);
 }
Пример #3
0
        private void Run()
        {
            //while (true)
            {
                lock (dataLock)
                {
                    var      input     = serial.GetData();
                    double[] inputData = new double[8];
                    for (int j = 0; j < 8; j++)
                    {
                        inputData[j] = input[j];
                    }
                    var percievedPositionArray = net.Think(inputData);

                    double   bestVal      = 0;
                    SetPoint bestSetPoint = new SetPoint();


                    for (int i = 0; i < percievedPositionArray.Length; i++)
                    {
                        if (percievedPositionArray[i] > bestVal)
                        {
                            bestVal      = percievedPositionArray[i];
                            bestSetPoint = setPointList[i];
                        }
                    }


                    var percievedPosition = bestSetPoint;

                    Globals.T1DesiredPosition = percievedPosition.T1Position;
                    Globals.T2DesiredPosition = percievedPosition.T2Position;
                    Globals.A1DesiredPosition = percievedPosition.A1Position;
                    Globals.A2DesiredPosition = percievedPosition.A2Position;
                    Globals.A3DesiredPosition = percievedPosition.A3Position;
                    Globals.B1DesiredPosition = percievedPosition.B1Position;
                    Globals.B2DesiredPosition = percievedPosition.B2Position;
                    Globals.B3DesiredPosition = percievedPosition.B3Position;
                    Globals.C1DesiredPosition = percievedPosition.C1Position;
                    Globals.C2DesiredPosition = percievedPosition.C2Position;
                    Globals.C3DesiredPosition = percievedPosition.C3Position;
                    Globals.D1DesiredPosition = percievedPosition.D1Position;
                    Globals.D2DesiredPosition = percievedPosition.D2Position;
                    Globals.D3DesiredPosition = percievedPosition.D3Position;

                    UnityCommunicationHub.WriteData(true);
                }
            }
        }
Пример #4
0
 public void setHandPosition(SetPoint input)
 {
     //needed for error catching
     if (input != null)
     {
         this.T1Position = input.T1Position;
         this.T2Position = input.T2Position;
         this.A1Position = input.A1Position;
         this.A2Position = input.A2Position;
         this.A3Position = input.A3Position;
         this.B1Position = input.B1Position;
         this.B2Position = input.B2Position;
         this.B3Position = input.B3Position;
         this.C1Position = input.C1Position;
         this.C2Position = input.C2Position;
         this.C3Position = input.C3Position;
         this.D1Position = input.D1Position;
         this.D2Position = input.D2Position;
         this.D3Position = input.D3Position;
     }
 }
Пример #5
0
        private void setHandPositionButton_Click(object sender, EventArgs e)
        {
            UnityCommunicationHub.ReadData(true);
            SetPoint newPoint = new SetPoint
            {
                A1Position = Globals.A1DesiredPosition,
                A2Position = Globals.A2DesiredPosition,
                A3Position = Globals.A3DesiredPosition,
                B1Position = Globals.B1DesiredPosition,
                B2Position = Globals.B2DesiredPosition,
                B3Position = Globals.B3DesiredPosition,
                C1Position = Globals.C1DesiredPosition,
                C2Position = Globals.C2DesiredPosition,
                C3Position = Globals.C3DesiredPosition,
                D1Position = Globals.D1DesiredPosition,
                D2Position = Globals.D2DesiredPosition,
                D3Position = Globals.D3DesiredPosition,
                T1Position = Globals.T1DesiredPosition,
                T2Position = Globals.T2DesiredPosition
            };

            controls.allNodes[(int)activeNode.Tag].setHandPosition(newPoint);
        }
Пример #6
0
        private void Test()
        {
            lock (dataLock)
            {
                //var input = serial.GetData();
                //UnityCommunicationHub.ReadData();
                //var percievedPositionArray = net.Think(input);



                //inputTrainingData.Add(input);
                //outputTrainingData.Add(Globals.GetDoubles());

                //for (int i = 0; i < percievedPositionArray.Length; i++)
                //{
                //    percievedPositionArray[i] = percievedPositionArray[i] * 90;
                //}



                //Globals.T1DesiredPosition = (float)percievedPositionArray[0];
                //Globals.T2DesiredPosition = (float)percievedPositionArray[1];
                //Globals.A1DesiredPosition = (float)percievedPositionArray[2];
                //Globals.A2DesiredPosition = (float)percievedPositionArray[3];
                //Globals.A3DesiredPosition = (float)percievedPositionArray[4];
                //Globals.B1DesiredPosition = (float)percievedPositionArray[5];
                //Globals.B2DesiredPosition = (float)percievedPositionArray[6];
                //Globals.B3DesiredPosition = (float)percievedPositionArray[7];
                //Globals.C1DesiredPosition = (float)percievedPositionArray[8];
                //Globals.C2DesiredPosition = (float)percievedPositionArray[9];
                //Globals.C3DesiredPosition = (float)percievedPositionArray[10];
                //Globals.D1DesiredPosition = (float)percievedPositionArray[11];
                //Globals.D2DesiredPosition = (float)percievedPositionArray[12];
                //Globals.D3DesiredPosition = (float)percievedPositionArray[13];
                var percievedPosition = new SetPoint(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                var rand = new Random();
                //UnityCommunicationHub.WriteData(true);

                var percievedPositionArray = new double[7];

                if (inputTrainingData.Count != 0)
                {
                    percievedPositionArray = net.Think(inputTrainingData[inputTrainingData.Count - 1]);

                    double   bestVal      = 0;
                    SetPoint bestSetPoint = new SetPoint();


                    for (int i = 0; i < percievedPositionArray.Length; i++)
                    {
                        if (percievedPositionArray[i] > bestVal)
                        {
                            bestVal      = percievedPositionArray[i];
                            bestSetPoint = setPointList[i];
                        }
                    }

                    if (lastSetPoint.Equals(bestSetPoint))
                    {
                        percievedPosition = setPointList[rand.Next(0, 7)];
                    }
                    else
                    {
                        percievedPosition = bestSetPoint;
                    }
                }
                else
                {
                    percievedPosition = setPointList[rand.Next(0, 7)];
                }

                if (positionsToVisit.Count > 0)
                {
                    percievedPosition = setPointList[positionsToVisit.First()];
                    for (int i = 0; i < 7; i++)
                    {
                        if ((7 - i) == positionsToVisit.Count)
                        {
                            percievedPositionArray[i] = 1;
                        }
                    }
                    positionsToVisit.RemoveAt(0);
                }

                Globals.T1DesiredPosition = percievedPosition.T1Position;
                Globals.T2DesiredPosition = percievedPosition.T2Position;
                Globals.A1DesiredPosition = percievedPosition.A1Position;
                Globals.A2DesiredPosition = percievedPosition.A2Position;
                Globals.A3DesiredPosition = percievedPosition.A3Position;
                Globals.B1DesiredPosition = percievedPosition.B1Position;
                Globals.B2DesiredPosition = percievedPosition.B2Position;
                Globals.B3DesiredPosition = percievedPosition.B3Position;
                Globals.C1DesiredPosition = percievedPosition.C1Position;
                Globals.C2DesiredPosition = percievedPosition.C2Position;
                Globals.C3DesiredPosition = percievedPosition.C3Position;
                Globals.D1DesiredPosition = percievedPosition.D1Position;
                Globals.D2DesiredPosition = percievedPosition.D2Position;
                Globals.D3DesiredPosition = percievedPosition.D3Position;

                UnityCommunicationHub.WriteData(true);
                lastSetPoint = percievedPosition;
                Thread.Sleep(200);
                for (int i = 0; i < 250; i++)
                {
                    var      input     = serial.GetData();
                    double[] inputData = new double[8];
                    for (int j = 0; j < 8; j++)
                    {
                        inputData[j] = input[j];
                    }
                    UnityCommunicationHub.ReadData();


                    inputTrainingData.Add(inputData);
                    outputTrainingData.Add(percievedPositionArray);
                    Thread.Sleep(1);
                }
            }
        }
Пример #7
0
        private void Run()
        {
            lock (dataLock)
            {
                //var input = serial.GetData();
                //var percievedPositionArray = net.Think(input);

                //if (input.Contains(double.NaN))
                //{
                //    while (input.Contains(double.NaN))
                //    {
                //        input = serial.GetData();
                //    }
                //}

                //for (int i = 0; i < percievedPositionArray.Length; i++)
                //{
                //    percievedPositionArray[i] = percievedPositionArray[i] * 90;
                //}



                //Globals.T1DesiredPosition = (float)percievedPositionArray[0];
                //Globals.T2DesiredPosition = (float)percievedPositionArray[1];
                //Globals.A1DesiredPosition = (float)percievedPositionArray[2];
                //Globals.A2DesiredPosition = (float)percievedPositionArray[3];
                //Globals.A3DesiredPosition = (float)percievedPositionArray[4];
                //Globals.B1DesiredPosition = (float)percievedPositionArray[5];
                //Globals.B2DesiredPosition = (float)percievedPositionArray[6];
                //Globals.B3DesiredPosition = (float)percievedPositionArray[7];
                //Globals.C1DesiredPosition = (float)percievedPositionArray[8];
                //Globals.C2DesiredPosition = (float)percievedPositionArray[9];
                //Globals.C3DesiredPosition = (float)percievedPositionArray[10];
                //Globals.D1DesiredPosition = (float)percievedPositionArray[11];
                //Globals.D2DesiredPosition = (float)percievedPositionArray[12];
                //Globals.D3DesiredPosition = (float)percievedPositionArray[13];

                //UnityCommunicationHub.WriteData(true);

                var      input     = serial.GetData();
                double[] inputData = new double[8];
                for (int j = 0; j < 8; j++)
                {
                    inputData[j] = input[j];
                }
                var percievedPositionArray = net.Think(inputData);

                double   bestVal      = 0;
                SetPoint bestSetPoint = new SetPoint();


                for (int i = 0; i < percievedPositionArray.Length; i++)
                {
                    if (percievedPositionArray[i] > bestVal)
                    {
                        bestVal      = percievedPositionArray[i];
                        bestSetPoint = setPointList[i];
                    }
                }


                var percievedPosition = bestSetPoint;

                Globals.T1DesiredPosition = percievedPosition.T1Position;
                Globals.T2DesiredPosition = percievedPosition.T2Position;
                Globals.A1DesiredPosition = percievedPosition.A1Position;
                Globals.A2DesiredPosition = percievedPosition.A2Position;
                Globals.A3DesiredPosition = percievedPosition.A3Position;
                Globals.B1DesiredPosition = percievedPosition.B1Position;
                Globals.B2DesiredPosition = percievedPosition.B2Position;
                Globals.B3DesiredPosition = percievedPosition.B3Position;
                Globals.C1DesiredPosition = percievedPosition.C1Position;
                Globals.C2DesiredPosition = percievedPosition.C2Position;
                Globals.C3DesiredPosition = percievedPosition.C3Position;
                Globals.D1DesiredPosition = percievedPosition.D1Position;
                Globals.D2DesiredPosition = percievedPosition.D2Position;
                Globals.D3DesiredPosition = percievedPosition.D3Position;

                UnityCommunicationHub.WriteData(true);
            }
        }
Пример #8
0
        private void Run()
        {
            //while (true)
            {
                lock (dataLock)
                {
                    var      input     = serial.GetData();
                    double[] inputData = new double[7];
                    for (int j = 0; j < 8; j++)
                    {
                        if (j < 1)
                        {
                            inputData[j] = input[j];
                        }
                        else if (j > 1)
                        {
                            inputData[j - 1] = input[j];
                        }
                    }
                    var percievedPositionArray = net.Think(inputData);

                    double   bestVal      = 0;
                    SetPoint bestSetPoint = new SetPoint();
                    bool     goodToMove   = false;

                    while (!goodToMove)
                    {
                        var index = 0;
                        for (int i = 0; i < percievedPositionArray.Length; i++)
                        {
                            if (percievedPositionArray[i] > bestVal)
                            {
                                bestVal      = percievedPositionArray[i];
                                index        = i;
                                bestSetPoint = setPointList[i];
                            }
                        }

                        if (bestVal > 0.95)
                        {
                            goodToMove = true;
                        }
                        else
                        {
                            PositionTextBox.Text = reverseIndexList[index];
                            goodToMove           = RunFocus();
                            if (!goodToMove)
                            {
                                percievedPositionArray[index] = 0;
                                bestVal = 0;
                            }
                        }
                    }

                    var percievedPosition = bestSetPoint;

                    Globals.T1DesiredPosition = percievedPosition.T1Position;
                    Globals.T2DesiredPosition = percievedPosition.T2Position;
                    Globals.A1DesiredPosition = percievedPosition.A1Position;
                    Globals.A2DesiredPosition = percievedPosition.A2Position;
                    Globals.A3DesiredPosition = percievedPosition.A3Position;
                    Globals.B1DesiredPosition = percievedPosition.B1Position;
                    Globals.B2DesiredPosition = percievedPosition.B2Position;
                    Globals.B3DesiredPosition = percievedPosition.B3Position;
                    Globals.C1DesiredPosition = percievedPosition.C1Position;
                    Globals.C2DesiredPosition = percievedPosition.C2Position;
                    Globals.C3DesiredPosition = percievedPosition.C3Position;
                    Globals.D1DesiredPosition = percievedPosition.D1Position;
                    Globals.D2DesiredPosition = percievedPosition.D2Position;
                    Globals.D3DesiredPosition = percievedPosition.D3Position;

                    UnityCommunicationHub.WriteData(true);
                }
            }
        }