Relative Servo Position

Hello, I am doing a project in which a set of servos turn a solar panel so that it finds the brightest spot. I have already written code and built the device that does this. When the device if first turned on it utilizes both servo motors to search the entire upper hemisphere of its environment and then takes in information about the brightness while also recording the coordinates of both servo motors that belong to the brightest spot. I am trying to implement a solar-tracking system so that after the unit has found the brightest spot it will scan plus/minus 20 degrees every 15 min to make sure that the sun hasn't moved too much. Like i said, i am able to find the brightest spot, but when i try to write the servo to a position relative to the variable that has the value of the brightest spot it won't work.

For instance, if the brightest spot is at 65 degrees, and the variable that holds the value 65 is "highestValueX", shouldn't i be able to say...

...say highestValueX is already at the value of 60...

for(int pos = (highestValueX - 20); pos < (highestValueX + 20); pos += 2)
{
myServo_X.write(pos);
delay(500);
}

Does anyone have any idea why this won't work? The servo either freaks out completely or will write to the positions below the highestValueX, but not the ones above it. Any help or suggestions would be greatly appreciated.

My suggestion would be to put a serial print of highestValueX and pos in there, so you can see where it's supposed to be going:

// put a Serial.begin(9600) up top /////////////////////

    Serial.println(highestValueX);   //////////////////////
for(int pos = (highestValueX - 20); pos < (highestValueX + 20); pos += 2)
   {
     Serial.println(pos);  ///////////////////////////////
     myServo_X.write(pos); 
     delay(500); 
    }

I'd also test it with some minimal code... presumably that snippet is part of the whole program. Cut it back to the bare minimum, including hardcoding a start value for highestValueX and run just that snippet with the necessary servo setup code.

Only other question is, I've never used this style int pos = (highestValueX - 20) in the initialisation of a for... I guess it's kosher?

I guess it's kosher?

Yes it is.

The idea of printing data is good, but the implementation needs work. Just seeing some raw number appear on the serial monitor is not all that useful. Seeing

Current high value: nnn
pos: nnn
pos: nnn
pos: nnn
pos: nnn
pos: nnn

seems a lot more useful, to me. It's a lot easier to figure out what any given value means in this situation, vs:

nnn
nnn
nnn
nnn
nnn
nnn