Problem with compound addition

I have a sketch to act as a "cruise control" for my live steam locomotive. I made a change so the servo movements will be proportional to the speed, e.g. slow speed, slow servo movements. This has caused a problem.
Everything was fine when using a constant number for the amount to move the servo, e.g. servopos+=5. Changing away from that has caused problems. Variables cruiseFactor and servoMove are int variables. The compound minus seems to work OK; compound plus does not. unAuxin is basically the speed from wheel sensor. The 2nd and 3rd "If" statements are similar because i was trying different amounts of servo movement depending on the speed. Same with the 4th and 5th "Ifs". Initially i tried it w/ "cruiseFactor/10" in place of servoMove. Didn't work that way so i thought i'd try a variable. Right now at different time the servopos will go very large , above 2700 if i remember, which is outside of my parameters, and "locks up" the program.

I bet it's something simple i'm missing. Any help would be appreciated.
Marty

  if (cruiseButton)//if cruiseButton is true then run CC sequence
  {
    cruiseFactor = map(unThrottleIn, 1130, 1900, 1, 100);
    servoMove = (cruiseFactor/10);
    if ((unAuxIn > (996/cruiseFactor)) && (servopos > 956)) //if speed very slow, open throttle fast.
    {      
      servopos -= servoMove; //
      servoAux.writeMicroseconds(servopos);      // sets the servo position according to the scaled value
    }

    if ((unAuxIn > (804/cruiseFactor)) && (unAuxIn <= (996/cruiseFactor)) && (servopos > 956)) //if speed slow, open throttle.
    {
     // servoMove = (cruiseFactor/10);
      servopos -= servoMove;
      servoAux.writeMicroseconds(servopos);      // 
    }
    if ((unAuxIn < (570/cruiseFactor)) && (unAuxIn >= (502/cruiseFactor)) && (servopos < 1472)) //if speed high, close throttle. 
   {
     //servoMove = (cruiseFactor/10);
      servopos += servoMove;
      servoAux.writeMicroseconds(servopos);      // 
    } 
    if ((unAuxIn < (502/cruiseFactor)) && (servopos < 1472)) // If speed very fast, close throttle quicker
    {
      //servoMove = (cruiseFactor/10);
      servopos += servoMove; //
      servoAux.writeMicroseconds(servopos);      // 
    } 

    Serial.print(unAuxIn);
    Serial.print("    ");
    Serial.print(servopos);
    Serial.print("   ");
    Serial.print(servoMove);
    Serial.print("    ");
    Serial.println(cruiseFactor);
    delay(50); // measuring dwell time

This is the whole loop() function?

I think that what can be happening is after you enter one if and changing servopos, in the next loop you will enter again, and in the next... and so on. I don't know if this make sense.

I'm not sure what that code is supposed to do, or what it actually does. If it is not doing what you expect then I suggest you put serial print statements in to check that it is taking the path through the code that you expect, and that variables are being assigned the values you expect.

I'm not sure what that code is supposed to do, or what it actually does. If it is not doing what you expect then I suggest you put serial print statements in to check that it is taking the path through the code that you expect, and that variables are being assigned the values you expect.

Total agreement.

You might go so far as to take that block and put it in a sketch that feeds it values and prints trails to show how they work through, changing servoAux to prints including which branch they are printing from.

Guys, thx for your quick responses and tips.
I put print statements in each IF statement and found that when cruisefactor is at its minimum of 1, servoMove =0, so the servo never closes. I figured it was something simple.
servoMove = (cruiseFactor/10);

Thx again. For those w/ some time to kill check out little video of my loco in action.

Nice but I'm wondering why you didn't go with a traditional flyweight-valve control governor system?

And possibly you have seen Fred Dibnah's Age Of Steam videos?
https://www.youtube.com/results?search_query=dibnah+age+of+steam

It's fascinating even to someone who isn't a steam-head. England had an over 130-mph steam engine in 1938!