public void setPower()
    {
        //actual train velcity
        vAct = train.getCurrentSpeed();   
        //call redundant method to check
        double powerCheck = setPowerRedundant(vAct,  authority, ctcSuggestedAuthority,mboCommandedAuthority, power, uk, ek);
        //use min authority
        authority = Math.min(ctcSuggestedAuthority,mboCommandedAuthority);       
        /*if(authority <= 0)
        {
            authority = 0.1;            
        }    */            

        //Need to calculate a velocity such that train stops moving 
        //(Vf=0) based on given authority (d) and trains max deceleration (a)
        //Vf^2 = Vi^2 +2ad
        //0 = Vi^2 +2ad
        //Vi^2 = -2ad
        //Vi = sqrt(-2ad) -> ommitting the - sign and using a positive value for deceleration(1.2)

        double vLimit = Math.sqrt(2*maxTrainDeceleration*authority);              

        //decide what speed setpoint to use
        velocitySetpoint = evaluateVelocity(vLimit);           

        //check that setpoint is not greater than track speed limit or velocity limit      
        if(power < maxTrainPower)//if pcm < pmax
        {
             uk = uk + (T/2)*(ek + (velocitySetpoint - vAct));
        }       

        ek = velocitySetpoint - vAct;            
        power = (KP*ek) + (KI * uk);           
        //if there is a 10% difference in calculations, then check has failed.
        if (Math.abs(power) < Math.abs(powerCheck) * 0.9 || Math.abs(power) > Math.abs(powerCheck) * 1.1) 
        {
            power = 0.0;
        } 
        
        /*if(power < 0)
        {
            power = 0;
        }*/
        train.setPower(power);         
    }