Converting between camera normalized data and servo

I have been trying to have a servo attached to the camera x axis twist to turn it so the center image is the center of the target. Since the normalized output in the vision target is a value that shows it to the left or right of the center of the image, you should be able to take that and convert it to the scale a servo uses. Then make changes to the servo until it and the target are centered.

The issue I am having is figuring out how to normalize the ranges. I have gotten this far, I do not think I am lost, but that I am just not understanding the math, or the proper procedure for determining it. Suggestions or help would be greatly appreciated.
I tried following the math on this pagehttp://stackoverflow.com/questions/1471370/normalizing-from-0-5-1-to-0-1
not sure if this is the right method or not

            double servoChange = ((report.center_mass_x_normalized-(-1))/2);
                        System.out.println("Servo Change: " + servoChange);
                        double servoInput = CameraX.get()-servoChange;
                               if(servoChange > 1) {
                        servoChange = 1; }
                    else if(servoChange < 0) {
                        servoChange = 0;
                    }
                        CameraX.set(servoInput);

It seems odd that you are pinning servoChange but don’t use the value and use servoInput instead.

The other variable is how the servo is mounted. It could be that the serverInput should be the cameraS.get() + servoChange.

Greg McKaskle

Ok, reworked it a little. What i am getting for a servo change is usually over 1 at current testing. So i think i am back to trying to get the values scaled correctly.


                        servoChange = ((report.center_mass_x_normalized-(-1))/2);
                        
                        servoChange += CameraX.get();
                        System.out.println(servoChange);
                        CameraX.set(servoChange);