太羞耻了,,回头来整理调整一波,把整个程序运行的过程整理一遍。
从cpp到exe不完全过程
一、一个cpp
二、CTRL+F7
三、找到exe,发送快捷方式。
以上。
#include <iostream>
#include <cmath>
using namespace std;
float u, v_Strait, v_Curve, m, g, degree_Bridge, r_Curve,servo_V;//舵机工作电压;
void initial();
void initial2();
float bridge_Force_analysis();
void motor_Power();
float servo_Power();
float curve_Power();
float motor_parameter();
void motor_Select();
/*主函数*/
void main()
{
initial2();
cout << "============功能选择表============" << endl;
cout << "0:设定初始数据 1:上桥受力分析 " << endl;
cout << "2:舵机功率计算 3:电机选型分析 " << endl;
cout << "================================== " << endl;
int a;
while (1)
{
fflush;
cin >> a;
switch (a)
{
case 0: initial(); break;
case 1: bridge_Force_analysis(); break; //上桥受力分析
case 2: servo_Power(); break; //舵机功率计算
case 3: motor_Select(); break; //电机选型
default:cout << "error!"<<endl;
}
}
system("pause");
return ;
}
void initial()
{
cout << "================================== " << endl;
cout << "滑动摩擦系数:";
cin >> u;
cout << "直道速度:";
cin >> v_Strait;
cout << "弯道速度:";
cin >> v_Curve;
cout << "车重(单位:kg):";
cin >> m;
cout << "重力加速度:";
cin >> g;
cout << "桥角度(弧度):";
cin >> degree_Bridge;
cout << "弯道半径:";
cin >> r_Curve;
}
void initial2()
{
u=0.5;
v_Strait=2.7;
v_Curve=2.4;
m=0.35;
g=9.8;
degree_Bridge=0.055556;
r_Curve=0.5;
}
float bridge_Force_analysis()
{
cout << "================================== " << endl;
float f_Sliding_friction, f_Normal_force;
float f = u*g*m*(cos(degree_Bridge)) + g*m*(sin(degree_Bridge));
cout << "桥上驱动力:" << f<<"N"<<endl;
return f;
}
float servo_Power()
{
cout << "================================== " << endl;
float servo_X, servo_Y; //舵机输出扭矩,舵机动作速度
cout << "舵机输出扭矩(单位:Kg·cm):";
cin >> servo_X;
cout << "舵机动作速度(单位:S/60°):";
cin >> servo_Y;
cout << "舵机工作电压(单位:V):";
cin >> servo_V;
float servo_power = 0.103*(float)servo_X / servo_Y;
cout << "舵机输出功率:" << servo_power<<"W"<<endl;
cout << "舵机工作电流:" << (float)servo_power / servo_V<<"A"<<endl;
return servo_power;
}
float curve_Power() //弯道所需驱动力
{
cout << "================================== " << endl;
float f = m*pow(v_Curve, 2) / r_Curve; //向心力
cout << "滑动摩擦系数:";
cin >> u;
cout << "弯道处所需驱动力为:" << f <<"N"<< endl;
return f;
}
float motor_parameter()
{
cout << "================================== " << endl;
float motor_T, motor_Gear_ratio, motor_efficiency,motor_P,motor_n;
float f; //驱动力
int a;
cout << "电机已是否已知扭矩 0:未知 1:已知" << endl;
cin >> a;
if (a == 0){
cout << "输入电机相关参数:" << endl;
cout << " 功率(单位kw):";
cin >> motor_P;
cout << " 转速(单位rpm)";
cin >> motor_n;
motor_T = 9.55*(float)motor_P / motor_n;
}
else
{
cout << " 扭矩:(单位:N·m)";
cin >> motor_T;
}
cout << " 齿轮比:";
cin >> motor_Gear_ratio;
cout << " 机械效率:(小数)";
cin >> motor_efficiency;
return motor_T*motor_Gear_ratio*motor_efficiency;
}
void motor_Select()
{
cout << "================================== " << endl;
float bridge = bridge_Force_analysis();
float curve = curve_Power();
float motor = motor_parameter();
float temp = ((bridge > curve) ? bridge : curve);
if (temp <= motor)
{
cout << "该电机有效驱动力为:" <<motor <<"N"<< endl;
cout << "OK!"<<endl;
}
else
cout << "Sorry!" << endl;
}