Pid_q&a

#include "robot-config.h"
#include <cmath>
#include <iostream>
using namespace vex;


competition Competition;



void calibrateInertial(inertial& Gyro){
  if(Gyro.installed()){
    Gyro.startCalibration();
    task::sleep(200);
    Gyro.calibrate();
    std::cout << "Calibrating Inertial Sensor..." << std::flush;
    while(Gyro.isCalibrating()){
      task::sleep(100);
      std::cout << "." << std::flush;
    }
    std::cout << std::endl;
    task::sleep(100);
  }
  else {
    std::cout << "No Inertial Sensor" << std::endl;
  }
}

void pre_auton(void) {

  
} 


double posNeg180(double angle){
  while(angle > 180){
    angle -= 360;
  }
  while(angle <= -180){
    angle += 360;
  }
  return angle;
}
double mypid(double desiredValue){
  double kp=0.5; //This number gets the bot to move

  double ki=0.000005; //This prevents it from stopping

  double kd=0.1; // This stops it at the end

  double prevErrror = 0;

  double derivitive = 0.0;

  double totalError=0;

  double error=posNeg180(desiredValue - inertials.yaw());

  while(std::abs(error) > 4){
    double angle=(inertials.yaw());

    prevErrror=error;

    error=posNeg180(desiredValue - angle);

    derivitive=error-prevErrror;

    totalError+=error;
    //double error = inertial9.pitch(degrees);
    double motorPower = error*kp + derivitive*kd + totalError*ki;

    lrw.spin(directionType::fwd,motorPower,velocityUnits::pct);

    lfw.spin(directionType::fwd,motorPower,velocityUnits::pct);

    rrw.spin(directionType::fwd,motorPower,velocityUnits::pct);

    rfw.spin(directionType::fwd,motorPower,velocityUnits::pct);

    vex::task::sleep(20);
  }
  lrw.stop(hold);
  lfw.stop(hold);
  rrw.stop(hold);
  rfw.stop(hold);

  return 1;

};



void autonomous(void) {
  calibrateInertial(inertials);

mypid(-90);
wait(500,msec);
mypid(90);

} 

void usercontrol(void) {
  
  while (1) {
    
    wait(20, msec); 
                    
  }  
}    


int main() {
  calibrateInertial(inertials);
  
  
  std::cout << inertials.heading() << std::endl;

edit by mods:
@46b_toxic Please try and use code tags when posting code. I have added them to this post for you. It would also be helpful if you also asked a question rather than posting code and expecting the forum members to guess what that might be.