该程序的这一部分用于计算面对零件所需的时间。 它从一些基本信息,工件直径,进给速率和您希望工具运行的表面速度开始。然后它运行一个while循环,每次工具前进0.010“时,它会计算该工件将旋转的新rpm,并计算该切割的时间,最后将其全部加起来。
问题:我需要能够限制rpms。随着工具越来越接近工件的中心,转速将达到非常高的无法达到的转速,我希望能够设置一个限制,例如2000。
我无法弄清楚如何做到这一点而不影响我的循环...我已经搜索过,但我是一个小伙子也许我偶然发现了一个可以工作但从未意识到它的解决方案,或者我不是寻找正确的关键词。这是我的代码:
public static void main(String[] args) {
double startRadius = 6; //Radius of stock diameter
double faceFinish = 0;
double feed = .010; //Amount the tool will advance per revolution
double sfm = 200; //Surface speed of tool (Surface feet per minute)
double rpm = 0;
double totalTime = 0;
while(faceFinish < startRadius) {
startRadius -= feed; //reduces diameter by feed
rpm = (sfm * 3.82) / (startRadius * 2); //establishes new rpm per tool advance
totalTime += (feed / (feed * rpm)) * 60;
}
int hours = (int) (totalTime / 3600);
int minutes = (int) ((totalTime % 3600) / 60);
int seconds = (int) (totalTime % 60);
System.out.printf("%02d:%02d:%02d\n", hours, minutes, seconds);
}
编辑 - 如果/其他似乎有效。
public static void main(String[] args) {
double startRadius = 6;
double faceFinish = 0;
double feed = .010;
double sfm = 200;
double rpm = 0;
double rpm2 = 0;
double total = 0;
double total2 = 0;
double totalTime = 0;
while(faceFinish < startRadius) {
startRadius -= feed;
rpm = (sfm * 3.82) / (startRadius * 2);
if(rpm > 2000) {
rpm = 2000;
total += (feed / (feed * rpm)) * 60;
}else {
total2 += (feed / (feed * rpm)) * 60;
}
totalTime = total + total2;
}
int hours = (int) (totalTime / 3600);
int minutes = (int) ((totalTime % 3600) / 60);
int seconds = (int) (totalTime % 60);
System.out.printf("%02d:%02d:%02d\n", hours, minutes, seconds);
}
答案 0 :(得分:0)
将以下代码段用于您正在使用的while循环
while(faceFinish < startRadius) {
startRadius -= feed; //reduces diameter by feed
rpm = ((sfm * 3.82) / (startRadius * 2))>2000?2000:((sfm * 3.82) / (startRadius * 2));
totalTime += (feed / (feed * rpm)) * 60;
}
答案 1 :(得分:-1)
请尝试以下代码。
class Rpm{
double value=0.0;
final double LIMIT = 2000.0;
public void setValue(double value){
if(value < LIMIT)
this.value= value;
}
public double getValue(){
return this.value;
}
}
public class yourclassname {
public static void main(String[] args) {
double startRadius = 6; //Radius of stock diameter
double faceFinish = 0;
double feed = .010; //Amount the tool will advance per revolution
double sfm = 200; //Surface speed of tool (Surface feet per minute)
Rpm rpm = new Rpm();
double totalTime = 0;
while(faceFinish < startRadius) {
startRadius -= feed; //reduces diameter by feed
rpm.setValue( (sfm * 3.82) / (startRadius * 2)); //establishes new rpm per tool advance
totalTime += (feed / (feed * rpm.getValue())) * 60;
}
int hours = (int) (totalTime / 3600);
int minutes = (int) ((totalTime % 3600) / 60);
int seconds = (int) (totalTime % 60);
System.out.printf("%02d:%02d:%02d\n", hours, minutes, seconds);
}
}