int main() { std::vector<int> vecIntegers = {50, 1, 987, 1001}; std::cout << "Vector contains " << vecIntegers.size() << " elements: "; DisplayVector(vecIntegers); //Erase one element at the end vecIntegers.pop_back(); std::cout << "After a call to pop_back() " << std::endl; std::cout << "Vector contains " << vecIntegers.size() << " elements: "; DisplayVector(vecIntegers); return 0; }
int main() { char powerfile[]="Power.txt"; GetPower(powerfile); /* * 声明核中的变量 */ std::vector<double> Vcore; std::vector<double> Rcore; //std::vector<double> ecore;//核的热容中的电流源部分 //std::vector<double> rcore;//核的热容中的热阻部分 //std::vector<double> Ipoint; /* * 声明基底中的变量 */ double Vbase(Tamb); double Ibase; double Rbase((r_conduct+r_fan)/A);//初始化基底的热阻,/@param A表示从密度换算 double ebase(0); double rbase(h/(2*(c_conduct*A)));//初始化基底的热容中的热阻部分=@param h/2@param c,*@param A表示从密度换算 /* * 初始化基底中的@param Vbase和@param ebase */ for(int i=0;i<CoreNumber;i++) { Rcore.push_back(r_bulk/Acore.at(i));//初始化核中的热阻,/@param Acore表示从密度换算 } /* * 初始化核中的@param Vcore和@param ecore */ for(int i=0;i<CoreNumber;i++) { Vcore.push_back(Tamb); //rcore.push_back(h/(2*(c_bulk*Acore.at(i))));//初始化@param rcore=@param h/2@param c,*@param Acore表示从密度换算 //ecore.push_back(0); } /* * 二级等效电路中,计算热阻和热容热阻部分的等效值 */ std::vector<double> r; for(int i=0;i<CoreNumber;i++) { r.push_back(Rcore.at(i));//计算等效值 } double rtmp=r.at(0);//用来计算@param Vbase的临时变量,是所有@param rcore的并联值 double Itmp(0); /* * 计算@param Vbase时用到的热阻并联和 */ for(int i=0;i<CoreNumber-1;i++) { rtmp=Pararlle(rtmp,r.at(i+1));//计算并联值 } rtmp=Pararlle(rtmp,Pararlle(Rbase,rbase));//与@param Rbase并联 /* * @brief 打开输出文件,并相应的打印表头 * 主要的输出内容:@param Vore、@param Pcore、@param Vbase、@param compareVbase */ std::ofstream Vout("Vcore.txt"); std::ofstream Pout("Pcore.txt"); std::ofstream Bout("Base.txt"); if(not Vout) std::perror("Vcore.txt"); if(not Bout) std::perror("Pcore.txt"); if(not Pout) std::perror("Base.txt"); Vout.precision(SetPrecision); Bout.precision(SetPrecision); Pout.precision(SetPrecision); for(int i=0;i<CoreNumber;i++) Pout<<std::setw(SetWidth)<<std::right<<"Pcore("<<i+1<<")"; Pout<<"\n"; for(int i=0;i<CoreNumber;i++) Vout<<std::setw(SetWidth)<<std::right<<"Vcore("<<i+1<<")"; Vout<<std::endl; Bout<<std::setw(SetWidth)<<"R(bc)Cb="<<Pararlle(Rbase,Rcore[0])*c_conduct<<"\n"; Bout<<std::setw(SetWidth)<<"VBase"; Bout<<std::setw(SetWidth)<<"Charge"<<"\n"; std::vector<double> Vref; std::vector<double> newPower; for(int i=0;i<CoreNumber;i++) { Vref.push_back(Vcore.at(i)); newPower.push_back(CorePower.at(i)); } double eps(1); double compareVbase(0); do { for(std::vector<double>::iterator i=Vcore.begin();i!=Vcore.end();i++) Vout<<std::setw(SetWidth)<<*i+amb<<"\t"; Vout<<std::endl; for(std::vector<double>::iterator i=newPower.begin();i!=newPower.end();i++) Pout<<std::setw(SetWidth)<<*i; Pout<<"\n"; Bout<<std::setw(SetWidth)<<Vbase; Bout<<std::setw(SetWidth)<<compareVbase<<"\n"; for(int i=0;i<CoreNumber;i++) { Vref.at(i)=Vcore.at(i); } /* * 刷新@param Vbase以及@param ebase */ Itmp=0;//用来计算@param Vbase的临时变量,是所有核内电流的和 for(int j=0;j<CoreNumber;j++) { newPower.at(j)=CorePower.at(j)+LeakagePower(Vcore.at(j));//刷新实际的功耗值(密度)=源功耗+漏电流功耗 //Ipoint.at(j)=(newPower.at(j)*rcore.at(j)/r.at(j)); Itmp+=newPower.at(j);//计算@param Itmp,需要每次刷新 } Itmp+=ebase; /* * 刷新@param Vcore,@param Vbase的值 */ Vbase=rtmp*Itmp; double SumNewPower=0;//计算所有核的实际功耗总值,用以计算稳定@param Vcore以及充电曲线中的@param Vbase for(int i=0;i<CoreNumber;i++) { SumNewPower+=newPower.at(i); } compareVbase=ChargeLine(SumNewPower,Rbase,c_conduct*A,IterNumber++);//注意:@param Cbase=@param c_conduct*@param A for(int i=0;i<CoreNumber;i++) { Vcore.at(i)=Vbase+newPower.at(i)*Rcore.at(i); } /* * 刷新@param Ibase,@param ebase的值 */ Ibase=0; for(int i=0;i<CoreNumber;i++) { Ibase+=(Vcore.at(i)-Vbase)/Rcore.at(i); } Ibase+=-Vbase/Rbase; ebase=Vbase/rbase+Ibase;//计算@param ebase,需要每次刷新 /* * 根据@param eps(@param Icore的前后迭代差)判断迭代的收敛情况 */ eps=0; for(int i=0;i<CoreNumber;i++) { Vref.at(i)=std::fabs(Vref.at(i)-Vcore.at(i)); eps=std::max(Vref.at(i),eps); } }while(std::fabs(eps)>0.000001); std::vector<double> Vstable=StableVcore(newPower,Rcore,Rbase);//@param Vstable看作是理论稳定温度 注意:计算中用的是新的稳定后的功耗向量 char charVstable[]="Vstable"; DisplayVector(Vstable,charVstable);//输出稳定温度值用来对比而已(打开Vstable.txt) Vout.close(); Bout.close(); Pout.close(); return 0; }
void DisplayVectorEndl(std::ostream & out, const std::vector<T> &v, const std::string &delim=" ") { DisplayVector(out,v,delim); out << std::endl; }
void EndlDisplayVector(std::ostream & out, const std::vector<T> &v, const std::string &delim=" ") { out << std::endl; DisplayVector(out,v,delim); }
int main() { SerialDebug(250000); //PrintString() and PrintFloat() using UART BeginBasics(); Blink(); Enable_PeriphClock(); /*Roll-0 Pitch-1 Yaw-2..Roll rotation around X axis.Pitch rotation around Y axis and Yaw rotation around Z axis note: It does not mean rotation along the X Y or Z axis*/ float RPY_c[3],RPY_k[3]; //RPY_c and RPY_k..Roll pitch and yaw obtained from complemntary filter and kalman filter float Accel[3],Gyro[3],Tempreature; //raw values float Accel_RealWorld[3]; //Real World Acceleration while(Init_I2C(400)){PrintString("\nI2C Connection Error");} while(MPU6050_Init()){PrintString("MPU6050 Initialization Error");} MPU6050_UpdateOffsets(&MPU6050_Offsets[0]); //MPU6050_ConfirmOffsets(&MPU6050_Offsets[0]); while(0) //to play around with quaternions and vector rotation { float vector[3]= {1,0,0}; float axis_vector[3]= {0,1,0}; //rotate around Y axis float rot_angle=90; //with 90 degrees Quaternion q; q=RotateVectorY(vector,rot_angle); //Rotates vector around Y axis with rot_angle PrintString("\nRotated Vector's Quaternion\t"); DisplayQ(q); PrintString("\n"); } while(1) { MPU6050_GetRaw(&Accel[0],&Gyro[0],&Tempreature); //Reads MPU6050 Raw Data Buffer..i.e Accel Gyro and Tempreature values if(Gyro[2]<0.3 && Gyro[2]>-0.3) Gyro[2]=0; //this actually reduces Yaw drift..will add magnetometer soon spudnut=tics(); //tics() return current timing info..using SysTick running at CPU_Core_Frequency/8..Counter Runs from 0xFFFFFF to 0 therefore overflows every 1.864135 secs delt=spudnut-donut; //small time dt donut=spudnut; //Display_Raw(Accel,Gyro,Tempreature); Attitude_k(Accel,Gyro,RPY_k,delt); //Estimates YPR using Kalman PrintString("\nYPR\t"); PrintFloat(RPY_k[2]); PrintString("\t"); PrintFloat(RPY_k[1]); PrintString("\t"); PrintFloat(RPY_k[0]); RemoveGravity(RPY_k,Accel,Accel_RealWorld); PrintString("\tReal World Accel with Gravity\t"); //still glitchish..working on it DisplayVector(Accel_RealWorld); PrintString("\t"); PrintFloat(1/delt); } }