Inertial sensor displaying inf as heading on PROS

My inertial sensor is displaying on the terminal an “int” value which causes the pid loop to run infinitely. here is the code

void turn(int target){
    //Creates important variables
    // std::this_thread::sleep_for (std::chrono::seconds(2));
    pros::delay(3000);
    int error;
    int lasterror;
    int totalerror;
    int power;

    int tol = 1;
    int range = 10;

    //Driving loop
    while (true){
        //Calculates the error
        error = target - rotationer.get_heading();

        if(error > 180){
            error -= 360;
        } else if (error < -180){
            error += 360;
        }

        if (std::abs(error) < tol){
            totalerror = 0;
        }

        //Calculates other variables
        totalerror += error;
        totalerror = std::max(std::min(totalerror, range), -1 * range);
        int turnd = error - lasterror;
        // int turnd = 0;

        //Calculates power and drives
        power = (error * turnkp) + (totalerror * turnti) + (turnd * turntd);
        power = std::max(-50, std::min(power, 50));

        LDrive.move(power);
        RDrive.move(-1 * power);

        lasterror = error;
        pros::lcd::clear();
        pros::lcd::set_text(1, std::to_string(error));
        std::cout << "\ntarget: "<< target << std::endl << "rotation: " << rotationer.get_heading() <<"\nerror is\n\n" << error << std::endl << std::endl;

    }
    LDrive.brake();
    RDrive.brake();

    
}

Looks like the loop never ends because there’s no break condition. Try adding a check like if (abs(error) < tol) break; so it exits once it reaches the target angle.

turns out I didn’t initialize the inertial sensor. loop works fine now.