Control gear motor like a Servo, project , suggestions

Your logic to decide which way to move the motor (and how fast) looks very strange. I'd expect you to decide what the desired position was based on the joystick, compare that with the actual position to determine how far the motor was from the desired position and in which direction, and determine the motor speed and direction from that. Instead you're just comparing the motor and joystick positions against some limits. Presumably this means that the motor is just supposed to go between two fixed positions rather than follow the joystick. Could you clarify what behaviour you're aiming for?

The technique of setting the motor speed and then waiting for a second before you do anything else pretty much guarantys that the motor will overshoot. If I were you I'd do the position comparison as fast as possible and decide what direction/speed you want the motor to move, tell it to move in that direction / speed and then immediately do the position comparison again etc.