         roofState = STOPPING;
         phase = RAMP_DOWN;
         // start mid-ramp if we were not running at full speed
-        countSincePhase = RAMP_LENGTH - RAMP_LENGTH * motorShield.getM1Speed() / FULL_SPEED;
+        countSincePhase = RAMP_LENGTH - RAMP_LENGTH * motorShield.getM1Speed() / roofSpeed;
     }
     if (roofState == ERROR) {
         roofState = STOPPED;

static Scheduler taskScheduler;
static RoofState roofState = STOPPED;
static Phase phase = IDLE;
static int countSincePhase;
static int direction;
static float temperature = DEVICE_DISCONNECTED_C;


    switch (phase) {
        case RAMP_UP: {
            int power = roofSpeed * countSincePhase / RAMP_LENGTH;
            if (power > roofSpeed)
                power = roofSpeed;
            motorShield.setM1Speed(power * direction);
            if (power == roofSpeed)
                phase = MOVE_UNTIL_NEAR;
            break;
        }
        case RAMP_DOWN: {
            int power = roofSpeed - roofSpeed * countSincePhase / RAMP_LENGTH;
            int minimumPower = (roofState == CLOSING ? CLOSING_SPEED : 0);
            if (power < minimumPower)
                power = minimumPower;
