Beispiel #1
0
        private void timerUI_Tick(object sender, EventArgs e)
        {
            //refresh the UI values
            float currPos   = SharingMemory.getPos();
            float currAngle = SharingMemory.getAngle();
            float delta     = SharingMemory.getDelta();

            currentAngleDisp.Value = Convert.ToDecimal(currAngle);
            ballPosDisp.Value      = Convert.ToDecimal(currPos);
            targetAngleDisp.Value  = Convert.ToDecimal(targetAngle);
            deltaDisp.Value        = Convert.ToDecimal(delta);
        }
Beispiel #2
0
 private void shareMemoryButton_Click(object sender, EventArgs e)
 {
     if (SharingMemory.ConnectMappedMemory())
     {
         sharedMemoryStatusLabel.Text = "Connected";
         shareMemoryButton.Enabled    = false;
         timerTick.Enabled            = true;
         timerUI.Enabled = true;
     }
     else
     {
         sharedMemoryStatusLabel.Text = "Error, could not connect";
     }
 }
Beispiel #3
0
        private void timerTick_Tick(object sender, EventArgs e)  //this will be used arround 60 times a second
        {
            float currPos = SharingMemory.getPos();
            //float delta = SharingMemory.getDelta();
            float delta = 0.02f;
            float temp1 = T / (T + delta);
            float temp2 = k * (delta + a * T) / (delta + T);
            float temp3 = -(k * a * T) / (delta + T);
            float error = (targetPos - currPos) * 0.1024f;
            float U     = temp1 * prevU + temp2 * error + temp3 * prevError;

            prevError   = error;
            targetAngle = Math.Max(Math.Min(45.0, U), -45.0);
            prevU       = (float)targetAngle;
            if (useController)
            {
                SharingMemory.setAngle(Convert.ToSingle(targetAngle));// should you choose to use it or not, the previously mentionned value can be transmitted to the other program
            }
        }