Skip to content

Instantly share code, notes, and snippets.

@akirayou
Created November 20, 2017 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirayou/cfc79baedfecb07b99ea8710da839397 to your computer and use it in GitHub Desktop.
Save akirayou/cfc79baedfecb07b99ea8710da839397 to your computer and use it in GitHub Desktop.
PCBヒータをkicadで作るスクリプト
#!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
$width= 1.8 #配線太さ(mm)
$T=18.0 #銅箔厚み(um)
$cu=1.72E-08 #銅電気伝導度
#縦方向サイズ関連
$step= $width * 2 + 1.6 #行って帰ってくるまでに縦方向に動く段差(配線ピッチの2倍)
$start=100 #描画開始y座標
#円の時はこれ
$r=81/2.0 -$width/2; #パターン円半径 $start-$endより長い事
$center= $start+$r -$width/2.0 #centerには多少マージンをつける
$end=$start+$r*2 #描画終了y座標 (stepとあわないときは切り捨て)
$stderr.puts "end max is #{$start+ ($center-$start)*2}"
def y2xend(y)
v=$r**2-(y-$center)**2;
v=0if(v<0)
return Math::sqrt(v)
end
#矩形の時はこれ
$sqWidth= 100-$width/2 #矩形の時の指定
#$end=$start+200 - $width -$step/2 #描画終了y座標 (stepとあわないときは切り捨て)
def nouse_y2xend(y)
return $sqWidth
end
#以下コード
$timestamp=0
$totalLen=0;
$maxX=nil;
$maxY=nil;
$minX=nil;
$minY=nil;
def put_line(x1,y1,x2,y2)
if($maxX==nil)then
$maxX=x1;
$maxY=y1;
$minX=x1;
$minY=y1;
end
$maxX=[x1,x2,$maxX].max
$minX=[x1,x2,$minX].min
$maxY=[y1,y2,$maxY].max
$minY=[y1,y2,$minY].min
$totalLen+=Math::sqrt( (x1-x2)**2 + (y1-y2)**2 )
if($timestamp==0)then
puts "(segment (start #{x1} #{y1}) (end #{x2} #{y2}) (width #{$width}) (layer F.Cu) (net 0) )"
else
puts "(segment (start #{x1} #{y1}) (end #{x2} #{y2}) (width #{$width}) (layer F.Cu) (net 0) (tstamp #{"%08x" %[$timestamp]}))"
end
$timestamp+=1
end
def half(sig)
($start).step($end,$step) do |y|
xstart=$step*sig/4.0
xend=[y2xend(y),xstart*sig].max * sig
#go
put_line((($start==y) ? 0.0 : xstart) ,y,xend,y)
#down
y2= y+$step/2.0
xend2=[y2xend(y2),xstart*sig].max * sig
put_line(xend,y,xend2,y2)
#back
put_line(xend2,y2,xstart,y2)
#down
y3=y+$step
put_line(xstart,y2,xstart,y3)
end
end
half(1)
half(-1)
$stderr.puts "length: #{$totalLen} mm Registance: #{$cu/($T*1.0E-6)/($width*1.0E-3)*$totalLen*1.0E-3} Ohm"
$stderr.puts "size: #{$maxX-$minX+$width} x #{$maxY-$minY+$width}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment