public CalibrationData GetCalibration()
        {
            CalibrationData cd = new CalibrationData();

            cd.leftEyebrowTrim = (int)leftEyebrowTrim.Value;
            cd.leftEyebrowMax = (int)leftEyebrowMaximum.Value;
            cd.leftEyebrowMin = (int)leftEyebrowMinimum.Value;
            cd.leftEyebrowPin = (int)indexToPin[leftEyebrowPin.SelectedIndex];
            cd.leftEyebrowEnabled = enableLeftEyebrow.Checked;

            cd.rightEyebrowTrim = (int)rightEyebrowTrim.Value;
            cd.rightEyebrowMax = (int)rightEyebrowMaximum.Value;
            cd.rightEyebrowMin = (int)rightEyebrowMinimum.Value;
            cd.rightEyebrowPin = (int)indexToPin[rightEyebrowPin.SelectedIndex];
            cd.rightEyebrowEnabled = enableRightEyebrow.Checked;

            cd.leftLidPositionTrim = (int)leftEyelidTrim.Value;
            cd.leftLidPositionMax = (int)leftEyelidMaximum.Value;
            cd.leftLidPositionMin = (int)leftEyelidMinimum.Value;
            cd.leftLidPositionPin = (int)indexToPin[leftEyelidPin.SelectedIndex];
            cd.leftLidPositionEnabled = enableLeftEyelid.Checked;

            cd.rightLidPositionTrim = (int)rightEyelidTrim.Value;
            cd.rightLidPositionMax = (int)rightEyelidMaximum.Value;
            cd.rightLidPositionMin = (int)rightEyelidMinimum.Value;
            cd.rightLidPositionPin = (int)indexToPin[rightEyelidPin.SelectedIndex];
            cd.rightLidPositionEnabled = enableRightEyelid.Checked;

            cd.leftHorizontalEyeTrim = (int)leftHorizontalEyeTrim.Value;
            cd.leftHorizontalEyeMax = (int)leftHorizontalEyeMaximum.Value;
            cd.leftHorizontalEyeMin = (int)leftHorizontalEyeMinimum.Value;
            cd.leftHorizontalEyePin = (int)indexToPin[leftHorizontalEyePin.SelectedIndex];
            cd.leftHorizontalEyeEnabled = enableLeftHorizontalEye.Checked;

            cd.rightHorizontalEyeTrim = (int)rightHorizontalEyeTrim.Value;
            cd.rightHorizontalEyeMax = (int)rightHorizontalEyeMaximum.Value;
            cd.rightHorizontalEyeMin = (int)rightHorizontalEyeMinimum.Value;
            cd.rightHorizontalEyePin = (int)indexToPin[rightHorizontalEyePin.SelectedIndex];
            cd.rightHorizontalEyeEnabled = enableRightHorizontalEye.Checked;

            cd.leftVerticalEyeTrim = (int)leftVerticalEyeTrim.Value;
            cd.leftVerticalEyeMax = (int)leftVerticalEyeMaximum.Value;
            cd.leftVerticalEyeMin = (int)leftVerticalEyeMinimum.Value;
            cd.leftVerticalEyePin = (int)indexToPin[leftVerticalEyePin.SelectedIndex];
            cd.leftHorizontalEyeEnabled = enableLeftVerticalEye.Checked;

            cd.rightVerticalEyeTrim = (int)rightVerticalEyeTrim.Value;
            cd.rightVerticalEyeMax = (int)rightVerticalEyeMaximum.Value;
            cd.rightVerticalEyeMin = (int)rightVerticalEyeMinimum.Value;
            cd.rightVerticalEyePin = (int)indexToPin[rightVerticalEyePin.SelectedIndex];
            cd.rightVerticalEyeEnabled = enableRightVerticalEye.Checked;

            cd.neckTwistTrim = (int)rotateNeckTrim.Value;// (-(0.5f * ((float)rotateNeckMaximum.Value - (float)rotateNeckMinimum.Value)) - rotateNeckMinimum.Value + 1500 + rotateNeckTrim.Value);
            cd.neckTwistMax = (int)rotateNeckMaximum.Value;
            cd.neckTwistMin = (int)rotateNeckMinimum.Value;
            cd.neckTwistPin = (int)indexToPin[rotateNeckPin.SelectedIndex];
            cd.neckTwistEnabled = enableRotateNeck.Checked;

            cd.neckTiltTrim = (int)tiltNeckTrim.Value;
            cd.neckTiltMax = (int)tiltNeckMaximum.Value;
            cd.neckTiltMin = (int)tiltNeckMinimum.Value;
            cd.neckTiltPin = (int)indexToPin[tiltNeckPin.SelectedIndex];
            cd.neckTiltEnabled = enableTiltNeck.Checked;

            cd.leftLipTrim = (int)leftLipTrim.Value;
            cd.leftLipMax = (int)leftLipMaximum.Value;
            cd.leftLipMin = (int)leftLipMinimum.Value;
            cd.leftLipPin = (int)indexToPin[leftLipPin.SelectedIndex];
            cd.leftLipEnabled = enableLeftLip.Checked;

            cd.rightLipTrim = (int)rightLipTrim.Value;
            cd.rightLipMax = (int)rightLipMaximum.Value;
            cd.rightLipMin = (int)rightLipMinimum.Value;
            cd.rightLipPin = (int)indexToPin[rightLipPin.SelectedIndex];
            cd.rightLipEnabled = enableRightLip.Checked;

            cd.jawTrim = (int)jawTrim.Value;
            cd.jawMax = (int)jawMaximum.Value;
            cd.jawMin = (int)jawMinimum.Value;
            cd.jawPin = (int)indexToPin[jawPin.SelectedIndex];
            cd.jawEnabled = enableJaw.Checked;

            cd.sonarEnabled = enableSonar.Checked;
            cd.sonarTriggerPin = (int)indexToPin[sonarTriggerPin.SelectedIndex];
            cd.sonarEchoPin = (int)indexToPin[sonarEchoPin.SelectedIndex];

            cd.irEnabled = enableIR.Checked;
            cd.irPin = (int)indexToPin[irPin.SelectedIndex];

            return cd;
        }
        public void SetCalibration(CalibrationData cd)
        {
            if ((cd.leftEyebrowPin == 0) && (cd.rightEyebrowPin == 0) && (cd.leftLidPositionPin == 0) &&(cd.rightLidPositionPin==0)) return;

            // ensure that the robot does not move while we update the values ... they will trigger a change update
            conductor.SetAsPaused(true);

            leftEyebrowTrim.Value = cd.leftEyebrowTrim;
            leftEyebrowMaximum.Value = cd.leftEyebrowMax;
            leftEyebrowMinimum.Value = cd.leftEyebrowMin;
            leftEyebrowPin.SelectedIndex = getIndexFromPin(cd.leftEyebrowPin);
            enableLeftEyebrow.Checked = cd.leftEyebrowEnabled;

            rightEyebrowTrim.Value = cd.rightEyebrowTrim;
            rightEyebrowMaximum.Value = cd.rightEyebrowMax;
            rightEyebrowMinimum.Value = cd.rightEyebrowMin;
            rightEyebrowPin.SelectedIndex = getIndexFromPin(cd.rightEyebrowPin);
            enableRightEyebrow.Checked = cd.rightEyebrowEnabled;

            leftEyelidTrim.Value = cd.leftLidPositionTrim;
            leftEyelidMaximum.Value = cd.leftLidPositionMax;
            leftEyelidMinimum.Value = cd.leftLidPositionMin;
            leftEyelidPin.SelectedIndex = getIndexFromPin(cd.leftLidPositionPin);
            enableLeftEyelid.Checked = cd.leftLidPositionEnabled;

            rightEyelidTrim.Value = cd.rightLidPositionTrim;
            rightEyelidMaximum.Value = cd.rightLidPositionMax;
            rightEyelidMinimum.Value = cd.rightLidPositionMin;
            rightEyelidPin.SelectedIndex = getIndexFromPin(cd.rightLidPositionPin);
            enableRightEyelid.Checked = cd.rightLidPositionEnabled;

            leftHorizontalEyeTrim.Value = cd.leftHorizontalEyeTrim;
            leftHorizontalEyeMaximum.Value = cd.leftHorizontalEyeMax;
            leftHorizontalEyeMinimum.Value = cd.leftHorizontalEyeMin;
            leftHorizontalEyePin.SelectedIndex = getIndexFromPin(cd.leftHorizontalEyePin);
            enableLeftHorizontalEye.Checked = cd.leftHorizontalEyeEnabled;

            rightHorizontalEyeTrim.Value = cd.rightHorizontalEyeTrim;
            rightHorizontalEyeMaximum.Value = cd.rightHorizontalEyeMax;
            rightHorizontalEyeMinimum.Value = cd.rightHorizontalEyeMin;
            rightHorizontalEyePin.SelectedIndex = getIndexFromPin(cd.rightHorizontalEyePin);
            enableRightHorizontalEye.Checked = cd.rightHorizontalEyeEnabled;

            leftVerticalEyeTrim.Value = cd.leftVerticalEyeTrim;
            leftVerticalEyeMaximum.Value = cd.leftVerticalEyeMax;
            leftVerticalEyeMinimum.Value = cd.leftVerticalEyeMin;
            leftVerticalEyePin.SelectedIndex = getIndexFromPin(cd.leftVerticalEyePin);
            enableLeftVerticalEye.Checked = cd.leftVerticalEyeEnabled;

            rightVerticalEyeTrim.Value = cd.rightVerticalEyeTrim;
            rightVerticalEyeMaximum.Value = cd.rightVerticalEyeMax;
            rightVerticalEyeMinimum.Value = cd.rightVerticalEyeMin;
            rightVerticalEyePin.SelectedIndex = getIndexFromPin(cd.rightVerticalEyePin);
            enableRightVerticalEye.Checked = cd.rightVerticalEyeEnabled;

            rotateNeckTrim.Value = cd.neckTwistTrim;
            rotateNeckMaximum.Value = cd.neckTwistMax;
            rotateNeckMinimum.Value = cd.neckTwistMin;
            rotateNeckPin.SelectedIndex = getIndexFromPin(cd.neckTwistPin);
            enableRotateNeck.Checked = cd.neckTwistEnabled;

            tiltNeckTrim.Value = cd.neckTiltTrim;
            tiltNeckMaximum.Value = cd.neckTiltMax;
            tiltNeckMinimum.Value = cd.neckTiltMin;
            tiltNeckPin.SelectedIndex = getIndexFromPin(cd.neckTiltPin);
            enableTiltNeck.Checked = cd.neckTiltEnabled;

            leftLipTrim.Value = cd.leftLipTrim;
            leftLipMaximum.Value = cd.leftLipMax;
            leftLipMinimum.Value = cd.leftLipMin;
            leftLipPin.SelectedIndex = getIndexFromPin(cd.leftLipPin);
            enableLeftLip.Checked = cd.leftLipEnabled;

            rightLipTrim.Value = cd.rightLipTrim;
            rightLipMaximum.Value = cd.rightLipMax;
            rightLipMinimum.Value = cd.rightLipMin;
            rightLipPin.SelectedIndex = getIndexFromPin(cd.rightLipPin);
            enableRightLip.Checked = cd.rightLipEnabled;

            jawTrim.Value = cd.jawTrim;
            jawMaximum.Value = cd.jawMax;
            jawMinimum.Value = cd.jawMin;
            jawPin.SelectedIndex = getIndexFromPin(cd.jawPin);
            enableJaw.Checked = cd.jawEnabled;

            enableSonar.Checked = cd.sonarEnabled;
            sonarTriggerPin.SelectedIndex = getIndexFromPin(cd.sonarTriggerPin);
            sonarEchoPin.SelectedIndex = getIndexFromPin(cd.sonarEchoPin);

            enableIR.Checked = cd.irEnabled;
            irPin.SelectedIndex = getIndexFromPin(cd.irPin);

            enableLeftEyebrow_Click(null, null);
            enableRightEyebrow_Click(null, null);
            enableLeftEyelid_Click(null, null);
            enableRightEyelid_Click(null, null);
            enableLeftHorizontalEye_Click(null, null);
            enableRightHorizontalEye_Click(null, null);
            enableLeftVerticalEye_Click(null, null);
            enableRightVerticalEye_Click(null, null);
            enableRotateNeck_Click(null, null);
            enableTiltNeck_Click(null, null);
            enableLeftLip_Click(null, null);
            enableRightLip_Click(null, null);
            enableJaw_Click(null, null);
            enableSonar_Click(null, null);
            enableIR_Click(null, null);

            conductor.SetAsPaused(false);
        }