Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- # Script to calculate gear combinations for thread cutting on Sieg C3 lathe
- # Available gears
- my %GearExist = (
- 0 => 1,
- 20 => 2,
- 30 => 1,
- 35 => 1,
- 40 => 2,
- 45 => 1,
- 50 => 1,
- 55 => 1,
- 57 => 1,
- 60 => 1,
- 63 => 1,
- 65 => 1,
- 80 => 2);
- # Not sure if all gears fit on all axes or if all combinations work. If not, reduce the lists below accordingly
- my @A=(20, 30, 35, 40, 50, 55, 57, 60, 63, 65, 80);
- my @B=(20, 30, 35, 40, 50, 55, 57, 60, 63, 65, 80);
- my @C=(0, 20, 30, 35, 40, 50, 55, 57, 60, 63, 65, 80); # C can be unused
- my @D=(20, 30, 35, 40, 50, 55, 57, 60, 63, 65, 80);
- my ($Ratio, $Pitch_int, $Pitch_fract, $Pitch, $Indicator_step, $i, $Indicator_product);
- my (@Works, $Found, $First, $Indicator_value, %GearCount);
- open (FILE, '>table.txt');
- print FILE "A\tB\tC\tD\tThread Pitch";
- print FILE "\tIndicator"x16;
- print FILE "\n";
- foreach my $Agear (@A) {
- foreach my $Dgear (@D) {
- foreach my $Cgear (@C) {
- foreach my $Bgear(@B) {
- # Count the number of used gears and check availability
- $GearCount{$Agear}++;
- $GearCount{$Bgear}++;
- $GearCount{$Cgear}++;
- $GearCount{$Dgear}++;
- if ($GearCount{$Agear}<=$GearExist{$Agear} and
- $GearCount{$Bgear}<=$GearExist{$Bgear} and
- $GearCount{$Cgear}<=$GearExist{$Cgear} and
- $GearCount{$Dgear}<=$GearExist{$Dgear}) {
- if ($Cgear != 0) { # All gears used
- $Ratio=$Agear/$Bgear*$Cgear/$Dgear;
- }
- else { # If C is not used
- $Ratio=$Agear/$Dgear;
- }
- $Pitch=$Ratio*1.5; # For every chuck revolution, the toolbit is moved this amount with lead screw pitch 1.5 mm
- # Split in integer and fraction to be able to print values with decimal comma
- if ($Pitch=~m/\./) {
- $Pitch=~m/(\d+)\.(\d+)/;
- $Pitch_int=$1;
- $Pitch_fract=$2;
- }
- else { # The pitch is an integer
- $Pitch_int=$Pitch;
- $Pitch_fract=0;
- }
- # The gear exchange must work with the indicator i e an integer number 1-16
- $Indicator_step=1/$Ratio;
- $Found=0;
- for ($i=1;$i<=16;$i++) {
- $Indicator_product=$Indicator_step*$i;
- if($Indicator_product-int($Indicator_product)<1e-6) {
- $Works[$i]=1;
- $Found=1;
- }
- else {
- $Works[$i]=0;
- }
- }
- $First=0;
- # Only print combinations that work with the indicator
- if ($Found and $Pitch>=0.4 and $Pitch <=3) {
- print FILE "$Agear\t$Bgear\t$Cgear\t$Dgear\t$Pitch_int,$Pitch_fract\t";
- for ($i=1;$i<=16;$i++) {
- if ($Works[$i]==1) {
- if($First==0) {
- $First=$i;
- }
- $Indicator_value=($i-$First)/2+1;
- print FILE "$Indicator_value\t";
- }
- }
- print FILE "\n";
- }
- if ($Cgear == 0) {
- last;
- }
- }
- # Reset gear count
- $GearCount{$Agear}=0;
- $GearCount{$Bgear}=0;
- $GearCount{$Cgear}=0;
- $GearCount{$Dgear}=0;
- }
- }
- }
- }
- close(FILE);
Advertisement
Add Comment
Please, Sign In to add comment