2025-01-31 16:56:42 +00:00
program gcodegenerator_v5;
2025-01-17 17:23:09 +00:00
uses
SysUtils, StrUtils, Math;
type
TPoint = record
X, Y: double ;
end ;
type
TStatorParams = record
StatorName: String ;
BaseDiameter: Double ;
BaseRadius: Double ;
NumberOfRays: Integer ;
RayShape: string ;
RayDiameter: Double ;
RayWidth: Double ;
RayHeight: Double ;
RayLength: Double ;
RayTopShape: string ;
RayTopDiameter: Double ;
RayTopWidth: Double ;
RayTopHeight: Double ;
RayCenterOffset: Double ;
WireDiameter: Double ;
NeedleDiameter: Double ;
2025-01-31 16:56:42 +00:00
NeedleRigidity: Double ;
2025-01-17 17:23:09 +00:00
WorkSpeed : integer ;
end ;
type
TLayer = record
2025-01-31 16:56:42 +00:00
Turns: Integer ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
StartZ: double ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
EndZ: double ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
end ;
var
StartTime, EndTime, ExecutionTime: TDateTime;
InputFileName, OutputFileName, CoilGeometryFileName: string ;
StatorParams: TStatorParams;
InFile, OutFile, CoilGeometryFile: TextFile ;
Line: string ;
CoilRadius, CoilWidth, CoilHeight : double ;
2025-01-31 16:56:42 +00:00
StartX: double ;
StartY: double ;
StartZ: double ;
CurrentX: double ;
CurrentY: double ;
2025-01-17 17:23:09 +00:00
CurrentZ: double ;
coords: TPoint;
normalizecoords: TPoint;
Layers: array [ 1 .. 1 0 ] of TLayer;
i, j, k: Integer ;
CoilLength : double ;
CurrentCoilTurns, CoilTurnsSum : Integer ;
AngleBetweenRays : double ;
RequiredSpacing: Double ;
LayerNumber : Integer ;
MaxLayers : Integer ;
angle : double ;
MaxDepth, MaxPath : double ;
MoveForward: boolean ;
2025-01-31 16:56:42 +00:00
WindDirection: integer ;
2025-01-17 17:23:09 +00:00
OperationMode: string ;
2025-01-31 16:56:42 +00:00
xclearance, yclearance, zclearance: Double ;
FixtureOffset: Double ;
FixtureDiameter: Double ;
FixtureTurns: integer ;
2025-01-17 17:23:09 +00:00
function ParseLine( Line: string ) : Boolean ;
var
Parts: array of string ;
Value: string ;
TrimmedLine: string ;
begin
2025-01-31 16:56:42 +00:00
TrimmedLine : = Trim( Line) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
if Length( TrimmedLine) = 0 then
begin
2025-01-31 16:56:42 +00:00
exit( true ) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
end
else if TrimmedLine[ 1 ] in [ ';' , '#' ] then
begin
2025-01-31 16:56:42 +00:00
exit( true ) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
end ;
2025-01-31 16:56:42 +00:00
Parts : = SplitString( TrimmedLine, '=' ) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TrimmedLine
2025-01-17 17:23:09 +00:00
Result : = Length( Parts) = 2 ;
if Result then
begin
2025-01-31 16:56:42 +00:00
Value : = LowerCase( Trim( Parts[ 1 ] ) ) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
case Trim( Parts[ 0 ] ) of
'stator_name' : begin
StatorParams. StatorName : = Value;
writeln( 'StatorName: ' , StatorParams. StatorName) ;
writeln( ) ;
end ;
'Operation_Mode' : begin
OperationMode : = Value;
writeln( 'Operation Mode: ' , OperationMode) ;
writeln( ) ;
end ;
'base_dia' : begin
StatorParams. BaseDiameter : = StrToFloat( Value) ;
writeln( 'Base Diameter: ' , StatorParams. BaseDiameter: 8 : 2 ) ;
writeln( ) ;
StatorParams. BaseRadius : = StatorParams. BaseDiameter/ 2 ;
writeln( 'Base Radius: ' , StatorParams. BaseRadius: 8 : 2 ) ;
writeln( ) ;
end ;
'num_rays' : begin
StatorParams. NumberOfRays : = StrToInt( Value) ;
writeln( 'Number of Rays: ' , StatorParams. NumberOfRays) ;
AngleBetweenRays : = 3 6 0 / StatorParams. NumberOfRays;
writeln( 'Angle Between Rays: ' , AngleBetweenRays) ;
writeln( ) ;
end ;
'ray_shape' : begin
if Pos( Value, 'circle, rect, superellipse' ) = 0 then
raise Exception. Create( 'Invalid value for ray_shape: ' + Value) ;
StatorParams. RayShape : = Value;
writeln( 'Ray Shape: ' , StatorParams. RayShape) ;
writeln( ) ;
end ;
'ray_dia' : begin
StatorParams. RayDiameter : = StrToFloat( Value) ;
writeln( 'Ray Diameter: ' , StatorParams. RayDiameter: 8 : 2 ) ;
writeln( ) ;
end ;
'ray_w' : begin
StatorParams. RayWidth : = StrToFloat( Value) ;
writeln( 'Ray Width: ' , StatorParams. RayWidth: 8 : 2 ) ;
writeln( ) ;
end ;
'ray_h' : begin
StatorParams. RayHeight : = StrToFloat( Value) ;
writeln( 'Ray Height: ' , StatorParams. RayHeight: 8 : 2 ) ;
writeln( ) ;
end ;
'ray_len' : begin
StatorParams. RayLength : = StrToFloat( Value) ;
writeln( 'Ray Length: ' , StatorParams. RayLength: 8 : 2 ) ;
writeln( ) ;
end ;
'raytop_shape' : begin
if Pos( Value, 'circle, rect, superellipse' ) = 0 then
raise Exception. Create( 'Invalid value for ray_top: ' + Value) ;
StatorParams. RayTopShape : = Value;
writeln( 'Ray Top Shape: ' , StatorParams. RayTopShape) ;
end ;
'raytop_dia' : begin
StatorParams. RayTopDiameter : = StrToFloat( Value) ;
writeln( 'Ray Top Diameter: ' , StatorParams. RayTopDiameter: 8 : 2 ) ;
writeln( ) ;
end ;
'raytop_w' : begin
StatorParams. RayTopWidth : = StrToFloat( Value) ;
writeln( 'Ray Top Width: ' , StatorParams. RayTopWidth: 8 : 2 ) ;
writeln( ) ;
end ;
'raytop_h' : begin
StatorParams. RayTopHeight : = StrToFloat( Value) ;
writeln( 'Ray Top Height: ' , StatorParams. RayTopHeight: 8 : 2 ) ;
writeln( ) ;
end ;
'ray_offset' : begin
StatorParams. RayCenterOffset : = StrToFloat( Value) ;
writeln( 'Ray Center Offset: ' , StatorParams. RayCenterOffset: 8 : 2 ) ;
writeln( ) ;
end ;
'wire_diameter' : begin
StatorParams. WireDiameter : = StrToFloat( Value) ;
writeln( 'Wire Diameter: ' , StatorParams. WireDiameter: 8 : 2 ) ;
writeln( ) ;
end ;
'needle_diameter' : begin
StatorParams. NeedleDiameter : = StrToFloat( Value) ;
writeln( 'Needle Diameter: ' , StatorParams. NeedleDiameter: 8 : 2 ) ;
writeln( ) ;
end ;
2025-01-31 16:56:42 +00:00
'needle_rigidity' : begin
StatorParams. NeedleRigidity : = StrToFloat( Value) ;
StatorParams. NeedleRigidity : = StatorParams. NeedleRigidity/ 1 0 0 ;
writeln( 'Needle Rigidity: ' , StatorParams. NeedleRigidity: 8 : 2 ) ;
writeln( ) ;
end ;
'x_clearance' : begin
xclearance : = StrToFloat( Value) ;
writeln( 'X Clearance: ' , xclearance: 8 : 2 ) ;
writeln( ) ;
end ;
'y_clearance' : begin
yclearance : = StrToFloat( Value) ;
writeln( 'Y Clearance: ' , yclearance: 8 : 2 ) ;
2025-01-17 17:23:09 +00:00
writeln( ) ;
end ;
2025-01-31 16:56:42 +00:00
'z_clearance' : begin
zclearance : = StrToFloat( Value) ;
writeln( 'Z Clearance: ' , zclearance: 8 : 2 ) ;
writeln( ) ;
end ;
'fixture_offset' : begin
FixtureOffset : = StrToFloat( Value) ;
writeln( 'Fixture Offset: ' , FixtureOffset: 8 : 2 ) ;
writeln( ) ;
end ;
'fixture_dia' : begin
FixtureDiameter : = StrToFloat( Value) ;
writeln( 'Fixture Diameter: ' , FixtureDiameter: 8 : 2 ) ;
writeln( ) ;
end ;
'fixture_turns' : begin
FixtureTurns : = StrToInt( Value) ;
writeln( 'Fixture Turns: ' , FixtureTurns) ;
writeln( ) ;
end ;
2025-01-17 17:23:09 +00:00
'work_speed' : begin
StatorParams. WorkSpeed : = StrToInt( Value) ;
writeln( 'Work Speed: ' , StatorParams. WorkSpeed) ;
writeln( ) ;
end ;
else
Result : = False ;
end ;
if not Result then
begin
writeln( 'Error: Unknown parameter: ' , Parts[ 0 ] ) ;
exit;
end ;
end ;
end ;
procedure ReadInputFile( ) ;
Begin
// **Opening the input file**
AssignFile( InFile, InputFileName) ;
try
Reset( InFile) ; // **This line opens the file for reading**
while not EOF( InFile) do
begin
ReadLn( InFile, Line) ;
if Length( Line) > 0 then
if not ParseLine( Line) then
writeln( 'Error: Invalid line: ' , Line) ;
end ;
except
on E: Exception do
begin
writeln( 'Error opening or reading input file: ' , E. Message ) ;
Halt( 1 ) ;
end ;
end ;
CloseFile( InFile) ;
end ;
function CircleCoordinates( diameter, angleDegrees: Double ) : TPoint;
var
radius: Double ;
angleRadians: Double ;
begin
radius : = diameter / 2 ;
2025-01-31 16:56:42 +00:00
// angleRadians := -1*angleDegrees * PI / 180; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
angleRadians : = - 1 * DegToRad( angleDegrees) ;
Result . X : = radius * Cos( angleRadians) ;
Result . Y : = radius * Sin( angleRadians) ;
end ;
function CalculateAngle( opposite, adjacent: Double ) : Double ;
begin
if adjacent = 0 then
raise Exception. Create( 'Adjacent side cannot be zero' ) ;
// CalculateAngle := ArcTan(opposite / adjacent) * 180 / PI;
CalculateAngle : = RadToDeg( ArcTan( opposite / adjacent) ) ;
end ;
function NormalizeZ( radius: Real ; thetaDeg: Real ) : Real ;
var
thetaRad, alphaRad, xKas, yKas, mTang, bTang: Real ;
begin
2025-01-31 16:56:42 +00:00
// 1. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2025-01-17 17:23:09 +00:00
thetaRad : = DegToRad( thetaDeg) ;
2025-01-31 16:56:42 +00:00
// 2. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 0,0).
2025-01-17 17:23:09 +00:00
xKas : = radius * Cos( thetaRad) ;
yKas : = radius * Sin( thetaRad) ;
2025-01-31 16:56:42 +00:00
// 3. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ).
2025-01-17 17:23:09 +00:00
alphaRad : = thetaRad + PI / 2 ;
2025-01-31 16:56:42 +00:00
// 4. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2025-01-17 17:23:09 +00:00
mTang : = Tan( alphaRad) ;
2025-01-31 16:56:42 +00:00
// 5. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (y = mTang * x + bTang).
2025-01-17 17:23:09 +00:00
bTang : = yKas - mTang * xKas;
2025-01-31 16:56:42 +00:00
// 6. <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> X <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> X (y = 0).
2025-01-17 17:23:09 +00:00
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> X - <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> NaN.
2025-01-17 17:23:09 +00:00
NormalizeZ : = NaN;
end
else
begin
NormalizeZ : = - bTang / mTang;
end ;
end ;
function DepthCheck( thickness, lineLength, angleDeg: double ) : double ;
var
xIntersection, distanceToIntersection, radius: double ;
begin
xIntersection : = ( thickness/ 2 + thickness/ 2 * cos( DegToRad( angleDeg) ) ) / sin( DegToRad( angleDeg) ) ;
distanceToIntersection : = sqrt( sqr( xIntersection) + sqr( 1.2 ) ) ;
radius : = lineLength / ( 2 * tan( DegToRad( angleDeg) / 2 ) ) ;
DepthCheck : = distanceToIntersection + radius;
end ;
function CalculateMaxPath( length , width, angleDegrees: double ) : double ;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <>
2025-01-17 17:23:09 +00:00
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double ;
begin
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
topLeftX : = - length ;
topLeftY : = width / 2 ;
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
2025-01-17 17:23:09 +00:00
angleRadians : = degToRad( - angleDegrees) ;
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
rotatedX : = - length * cos( angleRadians) - ( - width / 2 ) * sin( angleRadians) ;
rotatedY : = - length * sin( angleRadians) + ( - width / 2 ) * cos( angleRadians) ;
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
distance : = sqrt( sqr( rotatedX - topLeftX) + sqr( rotatedY - topLeftY) ) ;
2025-01-31 16:56:42 +00:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
MaxPath : = distance;
end ;
procedure CalculateCoilGeometry( ) ;
var
StartZ, EndZ: double ;
begin
writeln( 'CalculateCoilGeometry' ) ;
AssignFile( CoilGeometryFile, CoilGeometryFileName) ;
try
Rewrite( CoilGeometryFile) ;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2025-01-17 17:23:09 +00:00
MaxPath: = CalculateMaxPath( ( StatorParams. RayLength+ StatorParams. BaseRadius) , StatorParams. RayWidth, AngleBetweenRays) ;
//writeln(CoilGeometryFile, ';MaxPath:', MaxPath);
//MaxLayers :=trunc(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
MaxLayers : = round( ( MaxPath- StatorParams. NeedleDiameter) / 2 / ( StatorParams. WireDiameter+ RequiredSpacing) ) ;
2025-01-31 16:56:42 +00:00
if ( MaxLayers mod 2 = 0 ) then writeln( CoilGeometryFile, ';MaxLayers ' , MaxLayers) else
2025-01-17 17:23:09 +00:00
begin
dec( MaxLayers) ;
2025-01-31 16:56:42 +00:00
writeln( CoilGeometryFile, ';<3B> alculations resulted in MaxLayers=' , MaxLayers+ 1 , ' because it is even, MaxLayers=MaxLayers-1 and equal ' , MaxLayers) ;
2025-01-17 17:23:09 +00:00
end ;
MoveForward: = true ;
for i : = 1 to MaxLayers do
begin
write( CoilGeometryFile, ';Lair:' , i, ' have ' ) ;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//<2F> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . 2 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> + <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> + 2 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
RequiredSpacing: = yclearance* 2 + ( i- 1 ) * StatorParams. WireDiameter* 2 + StatorParams. NeedleDiameter;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
2025-01-17 17:23:09 +00:00
MaxDepth: = DepthCheck( StatorParams. RayWidth, RequiredSpacing, AngleBetweenRays) ;
//writeln(OutFile, ';RayWidth ', StatorParams.RayWidth:0:5);
//writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
//writeln(OutFile, ';AngleBetweenRays ', AngleBetweenRays:0:5);
//writeln(CoilGeometryFile, ';MaxDepth ', MaxDepth:0:5);
//writeln(OutFile);
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> .
//<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> + <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> .
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> _<EFBFBD> <5F> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> + <20> <> <EFBFBD> <EFBFBD> <EFBFBD> _<EFBFBD> <5F> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
2025-01-17 17:23:09 +00:00
If ( MaxDepth < ( StatorParams. BaseRadius) ) then CoilLength: = StatorParams. RayLength else if ( MaxDepth > ( StatorParams. RayLength+ StatorParams. BaseRadius) ) then break
else CoilLength: = StatorParams. RayLength+ StatorParams. BaseRadius- MaxDepth;
//writeln(CoilGeometryFile, '!!!');
write( CoilGeometryFile, CoilLength: 0 : 5 , 'mm ' ) ;
//CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2025-01-17 17:23:09 +00:00
CurrentCoilTurns : = round( CoilLength/ StatorParams. WireDiameter) ;
write( CoilGeometryFile, CurrentCoilTurns, ' Turns' ) ;
CoilTurnsSum : = CoilTurnsSum+ CurrentCoilTurns;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Z
2025-01-17 17:23:09 +00:00
//writeln(CoilGeometryFile,' StartZ=',CurrentZ:0:5);
// if (MoveForward = false) then CurrentZ:=StatorParams.RayLength+StatorParams.BaseRadius-StatorParams.WireDiameter/2
// else CurrentZ:=StatorParams.RayLength+StatorParams.BaseRadius-StatorParams.WireDiameter*(CurrentCoilTurns-0.5);
if ( MoveForward = false ) then StartZ: = StatorParams. RayLength+ StatorParams. BaseRadius- StatorParams. WireDiameter/ 2
else StartZ: = StatorParams. RayLength+ StatorParams. BaseRadius- StatorParams. WireDiameter* ( CurrentCoilTurns- 0.5 ) ;
write( CoilGeometryFile, ' NewStartZ=' , StartZ: 0 : 5 ) ;
if ( MoveForward = true ) then EndZ: = StartZ+ StatorParams. WireDiameter* CurrentCoilTurns
else EndZ: = StartZ- StatorParams. WireDiameter* CurrentCoilTurns;
writeln( CoilGeometryFile, ' EndZ=' , EndZ: 0 : 5 ) ;
//Inc(LayerNumber);
CoilWidth: = CoilWidth+ StatorParams. WireDiameter* 2 ;
MoveForward: = not MoveForward;
//writeln(CoilGeometryFile,';MoveForward: ', MoveForward);
//writeln(CoilGeometryFile);
writeln( CoilGeometryFile, CurrentCoilTurns, ' ' , StartZ: 0 : 5 , ' ' , EndZ: 0 : 5 ) ;
Layers[ i] . Turns : = CurrentCoilTurns;
Layers[ i] . StartZ : = StartZ;
Layers[ i] . EndZ : = EndZ;
end ;
writeln( CoilGeometryFile) ;
writeln( CoilGeometryFile, ';CoilTurnsSum: ' , CoilTurnsSum) ;
except
on E: Exception do
begin
writeln( 'Error writing to coil_geometry file: ' , E. Message ) ;
Halt( 1 ) ;
end ;
end ;
CloseFile( CoilGeometryFile) ;
end ;
procedure ReadCoilGeometry( ) ;
var
// Parts: array of string;
// Value: string;
TrimmedLine: string ;
line: string ;
count, i, turns: Integer ;
startZ: float;
endZ: float;
spacePos: Integer ;
err: Integer ;
begin
writeln( 'ReadCoilGeometry' ) ;
AssignFile( CoilGeometryFile, CoilGeometryFileName) ;
try
Reset( CoilGeometryFile) ; // **This line opens the file for reading**
i : = 0 ;
while not EOF( CoilGeometryFile) do
begin
//writeln('!!!');
ReadLn( CoilGeometryFile, Line) ;
if Length( Line) > 0 then
begin
2025-01-31 16:56:42 +00:00
TrimmedLine : = Trim( Line) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
if ( Length( TrimmedLine) = 0 ) then continue //exit() // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
else if TrimmedLine[ 1 ] in [ ';' , '#' ] then continue; // exit(); // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
StringReplace( TrimmedLine, ',' , '.' , [ rfReplaceAll] ) ;
2025-01-17 17:23:09 +00:00
inc( i) ;
spacePos : = Pos( ' ' , TrimmedLine) ;
//writeln(spacePos);
//writeln('!', TrimmedLine);
Val( Copy( TrimmedLine, 1 , spacePos - 1 ) , turns, err) ;
spacePos : = 1 + spacePos;
//writeln('? ',spacePos);
//i:=1;
TrimmedLine: = Copy( TrimmedLine, spacePos, Length( TrimmedLine) ) ;
spacePos : = Pos( ' ' , TrimmedLine) ;
//writeln(spacePos);
//writeln('!!', TrimmedLine);
Val( Copy( TrimmedLine, 1 , spacePos - 1 ) , startZ, err) ;
TrimmedLine: = Copy( TrimmedLine, spacePos, Length( TrimmedLine) ) ;
//writeln('!!!', TrimmedLine);
spacePos : = Pos( ' ' , TrimmedLine) ;
//writeln(spacePos);
Val( Copy( TrimmedLine, 1 , Length( TrimmedLine) ) , endZ, err) ;
writeln( 'layer:' , i, ' turns:' , turns, ' startX:' , startZ: 0 : 3 , ' endX:' , endZ: 0 : 3 ) ;
Layers[ i] . Turns : = turns;
Layers[ i] . StartZ : = StartZ;
Layers[ i] . EndZ : = EndZ;
//for i := 1 to CurrentCoilTurns do
//begin
// writeln(Layers[i].Turns,Layers[i].StartZ,Layers[i].EndZ);
//end;
//MaxLayers
//writeln();
end ;
//if not ParseLine(Line) then
// writeln('Error: Invalid line: ', Line);
end ;
MaxLayers: = i;
except
on E: Exception do
begin
writeln( 'Error opening or reading Coil Geometry File: ' , E. Message ) ;
Halt( 1 ) ;
end ;
end ;
CloseFile( CoilGeometryFile) ;
end ;
2025-01-31 16:56:42 +00:00
procedure StartSequence( ) ;
2025-01-17 17:23:09 +00:00
begin
2025-01-31 16:56:42 +00:00
writeln( OutFile, ';Generate G-code file for ' , StatorParams. StatorName, ' stator. At ' , FormatDateTime( 'dd.mm.yyyy hh:nn:ss.zzz' , StartTime) ) ;
writeln( OutFile, '; G-code for stator winding' ) ;
writeln( OutFile, 'G90 ; Absolute coordinate system' ) ;
//writeln(OutFile, 'G1 Y-10');
writeln( OutFile, 'G28 X Y Z' ) ;
writeln( OutFile, 'G1 X0 Y0' ) ;
writeln( OutFile) ;
// Move to center of ray along Y axis and reset coordinate
writeln( OutFile, 'G1 X' , StatorParams. RayCenterOffset: 0 : 2 , ' Y0.0' ) ;
writeln( OutFile, 'G92 X0 Y0' ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
CoilRadius: = ( StatorParams. RayTopHeight/ 2 + StatorParams. NeedleDiameter/ 2 + yclearance) ;
CoilWidth: = ( StatorParams. RayTopWidth+ StatorParams. NeedleDiameter+ yclearance* 2 ) ;
CoilHeight: = ( StatorParams. RayTopHeight+ StatorParams. NeedleDiameter+ xclearance* 2 ) ;
writeln( OutFile, ';CoilRadius = ' , CoilRadius: 0 : 3 ) ;
writeln( OutFile, ';CoilWidth = ' , CoilWidth: 0 : 3 ) ;
writeln( OutFile, ';CoilHeight = ' , CoilHeight: 0 : 3 ) ;
StartX: = - 1 * CoilHeight/ 2 ;
StartY: = - 1 * AngleBetweenRays/ 2 ;
writeln( OutFile, 'G1 X' , StartX: 0 : 3 , ' Y' , StartY: 0 : 3 ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
CurrentZ: = ( StatorParams. BaseDiameter/ 2 ) + zclearance;
writeln( OutFile, 'G1 Z' , CurrentZ: 0 : 2 , ' F' , StatorParams. WorkSpeed) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
writeln( OutFile, 'M0' ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> " <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> . <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
writeln( OutFile, 'G1 X' , StartX: 0 : 3 , ' Y' , - 1 * StartY: 0 : 3 ) ;
end ;
procedure MakeCoil( ) ;
begin
for j : = 1 to CurrentCoilTurns do
begin
writeln( OutFile, ';Coil<69> = ' , j) ;
writeln( OutFile, 'M117 L' , LayerNumber, '/C' , j, '/S' , CoilTurnsSum- CurrentCoilTurns+ j) ;
//Move from -X,Y to X,Y
angle : = WindDirection* AngleBetweenRays/ 2 ;
CurrentX : = CoilHeight/ 2 + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) ;
writeln( OutFile, 'G1 X' , CurrentX: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 , ' F' , StatorParams. WorkSpeed, ' ;Point 1 CurrentZ= ' , CurrentZ: 0 : 5 , ' 2x_clear= ' , + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) : 0 : 3 ) ; // Top Right Corner
if MoveForward then CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 4 else CurrentZ: = CurrentZ- StatorParams. WireDiameter/ 4 ;
//Divide the path into 100 points
//Move from X,Y to X,-Y
for k : = 1 to 1 0 0 do
begin
angle : = AngleBetweenRays/ 2 ;
angle : = WindDirection* ( angle- ( 2 * ( angle/ 1 0 0 * k) ) ) ;
CurrentX : = CoilHeight/ 2 + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) ;
writeln( OutFile, 'G1 X' , CurrentX: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 , ' F' , round( 1.2 * StatorParams. WorkSpeed/ StatorParams. BaseRadius* CurrentZ) , ' ;Point 2 CurrentZ= ' , CurrentZ: 0 : 5 , ' 3x_clear= ' , + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) : 0 : 3 ) ; // Bottom Right Corner
end ;
if MoveForward then CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 4 else CurrentZ: = CurrentZ- StatorParams. WireDiameter/ 4 ;
//Move from X,-Y to -X,-Y
angle : = - 1 * WindDirection* AngleBetweenRays/ 2 ;
CurrentX : = CoilHeight/ 2 + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) ;
writeln( OutFile, 'G1 X' , - 1 * CurrentX: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 , ' F' , StatorParams. WorkSpeed, ' ;Point 3 CurrentZ= ' , CurrentZ: 0 : 5 , ' 4x_clear= ' , + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) : 0 : 3 ) ; // Bottom Left Corner
if MoveForward then CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 4 else CurrentZ: = CurrentZ- StatorParams. WireDiameter/ 4 ;
//Move from -X,-Y to -X,Y
//Divide the path into 100 points
for k : = 1 to 1 0 0 do
begin
angle : = AngleBetweenRays/ 2 ;
angle : = - 1 * WindDirection* ( angle- ( 2 * ( angle/ 1 0 0 * k) ) ) ;
CurrentX : = CoilHeight/ 2 + ( ( CurrentZ- StatorParams. BaseRadius) * xclearance* StatorParams. NeedleRigidity) ;
writeln( OutFile, 'G1 X' , - 1 * CurrentX: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 , ' F' , round( 1.2 * StatorParams. WorkSpeed/ StatorParams. BaseRadius* CurrentZ) , ' ;Point 4 CurrentZ= ' , CurrentZ: 0 : 5 , ' 1x_clear= ' , + ( ( CurrentZ- StatorParams. BaseRadius* xclearance* StatorParams. NeedleRigidity) ) : 0 : 3 ) ; // Top Left Corner
end ;
if MoveForward then CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 4 else CurrentZ: = CurrentZ- StatorParams. WireDiameter/ 4 ;
end ;
end ;
procedure PairCoilWind( mode: string ) ;
begin
if ( ( mode = 'Aa' ) or ( mode = 'Bb' ) or ( mode = 'Cc' ) ) then
begin
WindDirection: = 1 ;
end
else if ( ( mode = 'aA' ) or ( mode = 'bB' ) or ( mode = 'cC' ) ) then
begin
WindDirection: = - 1 ;
end
else
begin
Writeln( 'Wrong Pair Coil Pattern. (Aa, aA, Bb, bB, Cc, cC' ) ;
Readln;
Halt( 1 ) ;
end ;
for LayerNumber : = 1 to MaxLayers do
begin
writeln( OutFile, ';Layer ' , LayerNumber) ;
if ( Layers[ LayerNumber] . StartZ > Layers[ LayerNumber] . EndZ) then CoilLength: = Layers[ LayerNumber] . StartZ- Layers[ LayerNumber] . EndZ
else CoilLength: = Layers[ LayerNumber] . EndZ- Layers[ LayerNumber] . StartZ;
writeln( OutFile, ';CoilLength ' , CoilLength: 0 : 5 ) ;
CurrentCoilTurns: = Layers[ LayerNumber] . Turns;
//writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum : = CoilTurnsSum+ CurrentCoilTurns;
writeln( OutFile, ';CoilTurnsSum ' , CoilTurnsSum) ;
CurrentZ: = Layers[ LayerNumber] . StartZ;
writeln( OutFile, '; NewZ=' , CurrentZ: 0 : 5 ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
writeln( OutFile, ';We make ' , CurrentCoilTurns, ' turns on ' , LayerNumber, ' layer.' ) ;
writeln( OutFile) ;
WindDirection : = 1 ;
MakeCoil( ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
CoilWidth: = CoilWidth+ StatorParams. WireDiameter* 2 ;
MoveForward: = not MoveForward;
writeln( OutFile, ';MoveForward: ' , MoveForward) ;
end ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, 'G4 P100' ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, 'G4 P100' ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, ';Coil Complete.' ) ;
writeln( OutFile, ';Changing coords.' ) ;
writeln( OutFile, 'G92 Y' , - 1 * angle: 0 : 5 ) ;
writeln( OutFile, ';Second coil' ) ;
for LayerNumber : = 1 to MaxLayers do
begin
writeln( OutFile, ';Layer ' , LayerNumber) ;
if ( Layers[ LayerNumber] . StartZ > Layers[ LayerNumber] . EndZ) then CoilLength: = Layers[ LayerNumber] . StartZ- Layers[ LayerNumber] . EndZ
else CoilLength: = Layers[ LayerNumber] . EndZ- Layers[ LayerNumber] . StartZ;
writeln( OutFile, ';CoilLength ' , CoilLength: 0 : 5 ) ;
CurrentCoilTurns: = Layers[ LayerNumber] . Turns;
//writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum : = CoilTurnsSum+ CurrentCoilTurns;
writeln( OutFile, ';CoilTurnsSum ' , CoilTurnsSum) ;
CurrentZ: = Layers[ LayerNumber] . StartZ;
writeln( OutFile, '; NewZ=' , CurrentZ: 0 : 5 ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
writeln( OutFile, ';We make ' , CurrentCoilTurns, ' turns on ' , LayerNumber, ' layer.' ) ;
writeln( OutFile) ;
WindDirection : = - 1 ;
MakeCoil( ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
CoilWidth: = CoilWidth+ StatorParams. WireDiameter* 2 ;
MoveForward: = not MoveForward;
writeln( OutFile, ';MoveForward: ' , MoveForward) ;
end ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, 'G4 P50' ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, 'G4 P50' ) ;
writeln( OutFile, 'M300 S2500 P100' ) ;
writeln( OutFile, ';Coil Complete.' ) ;
end ;
procedure MoveToNextPair( ) ;
begin
writeln( OutFile, ';Move To Next Pair' ) ;
writeln( OutFile, 'G92 Y0' ) ;
writeln( OutFile, 'G1 Y' , 3 6 0 / ( StatorParams. NumberOfRays/ 3 / 2 ) : 0 : 5 ) ; // Top Left Corner
writeln( OutFile, ';Turn to next pair with ' , 3 6 0 / ( StatorParams. NumberOfRays/ 3 / 2 ) : 0 : 5 , '<27> .' ) ;
writeln( OutFile, 'G92 Y' , StartY: 0 : 5 ) ;
end ;
procedure CreateMotorPhase( pattern: string ) ;
begin
PairCoilWind( pattern) ;
MoveToNextPair( ) ;
PairCoilWind( pattern) ;
MoveToNextPair( ) ;
PairCoilWind( pattern) ;
MoveToNextPair( ) ;
PairCoilWind( pattern) ;
end ;
procedure MoveToFixture( ) ;
begin
writeln( OutFile, ';Move To Fixture' ) ;
writeln( OutFile, 'G1 X' , FixtureOffset: 0 : 3 ) ;
writeln( OutFile, 'M0' ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD>
end ;
procedure AttachToFixture( ) ;
begin
writeln( OutFile, ';Attach To Fixture' ) ;
for j : = 0 to FixtureTurns do
begin
for i : = 0 to 3 6 0 do
begin
coords : = CircleCoordinates( FixtureDiameter/ 2 + xclearance, i+ 1 8 0 ) ;
angle : = CalculateAngle( coords. Y, CurrentZ) ;
writeln( OutFile, 'G1 X' , coords. X: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 ) ;
CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 3 6 0 ;
end ;
end ;
end ;
begin //Start Programm
2025-01-17 17:23:09 +00:00
// Command line argument handling
StartTime : = Now;
if ParamCount < 3 then
begin
Writeln( 'Usage: GCodeGenerator <input_file.txt> <output_file.gcode> <coil_geometry.txt>' ) ;
Halt( 1 ) ;
end ;
InputFileName : = ParamStr( 1 ) ;
OutputFileName : = ParamStr( 2 ) ;
CoilGeometryFileName : = ParamStr( 3 ) ;
ReadInputFile( ) ;
// G-code generation
AssignFile( OutFile, OutputFileName) ;
try
Rewrite( OutFile) ;
2025-01-31 16:56:42 +00:00
StartSequence( ) ;
2025-01-17 17:23:09 +00:00
// *** Your G-code generation logic here ***
if ( OperationMode = 'auto' ) then CalculateCoilGeometry( ) else
if ( OperationMode = 'manual' ) then ReadCoilGeometry( ) else
begin
writeln( 'Error determining operation mode.' ) ;
writeln( 'You should use auto or manual.' ) ;
Readln;
Halt( 1 ) ;
end ;
writeln( ) ;
writeln( OutFile, ';Information about layers' ) ;
writeln( OutFile, ';MaxLayers: ' , MaxLayers) ;
for i : = 1 to MaxLayers do
begin
writeln( OutFile, ';' , i, ' ' , Layers[ i] . Turns, ' ' , Layers[ i] . StartZ: 0 : 5 , ' ' , Layers[ i] . EndZ: 0 : 5 ) ;
end ;
2025-01-31 16:56:42 +00:00
2025-01-17 17:23:09 +00:00
Inc( LayerNumber) ;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
2025-01-17 17:23:09 +00:00
writeln( OutFile) ;
writeln( OutFile, ';Start winding' ) ;
2025-01-31 16:56:42 +00:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD>
2025-01-17 17:23:09 +00:00
MoveForward: = true ;
2025-01-31 16:56:42 +00:00
2025-01-17 17:23:09 +00:00
if ( StatorParams. RayShape = 'circle' ) then
begin
for j : = 0 to CurrentCoilTurns do
begin
for i : = 0 to 3 6 0 do
begin
coords : = CircleCoordinates( CoilRadius* 2 , i+ 1 8 0 ) ;
// writeln(OutFile,'CoilRadius*2= ',CoilRadius*2:0:5,' X=', coords.X:0:3, ' Y=', coords.Y:0:5);
angle : = CalculateAngle( coords. Y, CurrentZ) ;
// writeln(OutFile, ';G1 X', coords.X:0:3, ' Y', angle:0:5,' Z', CurrentZ:0:5);
writeln( OutFile, 'G1 X' , coords. X: 0 : 3 , ' Y' , angle: 0 : 5 , ' Z' , NormalizeZ( CurrentZ, angle) : 0 : 5 ) ;
// writeln(OutFile);
CurrentZ: = CurrentZ+ StatorParams. WireDiameter/ 3 6 0 ;
end ;
writeln( OutFile, ';Next coil.' ) ;
end ;
writeln( OutFile, ';Second coil' ) ;
Inc( LayerNumber) ;
// RequiredSpacing:=StatorParams.RayWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
// writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
RequiredSpacing: = StatorParams. RayTopWidth;
writeln( OutFile, ';RequiredSpacing = ' , RequiredSpacing: 0 : 5 ) ;
RequiredSpacing: = RequiredSpacing+ StatorParams. NeedleDiameter;
writeln( OutFile, ';RequiredSpacing = ' , RequiredSpacing: 0 : 5 ) ;
2025-01-31 16:56:42 +00:00
RequiredSpacing: = RequiredSpacing+ yclearance* 2 + LayerNumber* StatorParams. WireDiameter* 2 ;
2025-01-17 17:23:09 +00:00
writeln( OutFile, ';RequiredSpacing = ' , RequiredSpacing: 0 : 5 ) ;
CurrentZ: = RequiredSpacing/ ( 2 * tan( AngleBetweenRays* PI/ 1 8 0 / 2 ) ) ;
writeln( OutFile, ';CurrentZ = ' , CurrentZ: 0 : 3 ) ;
end
else if ( StatorParams. RayShape = 'rect' ) then
begin
// writeln(OutFile, ';Rect? ');
2025-01-31 16:56:42 +00:00
CreateMotorPhase( 'Aa' ) ;
MoveToFixture( ) ;
AttachToFixture( ) ;
2025-01-17 17:23:09 +00:00
end ;
except
on E: Exception do
begin
writeln( 'Error writing to output file: ' , E. Message ) ;
Halt( 1 ) ;
end ;
end ;
CloseFile( OutFile) ;
EndTime : = Now;
ExecutionTime : = EndTime - StartTime;
writeln( 'G-code generated to: ' , OutputFileName, ' in ' , FormatFloat( '0.000' , ExecutionTime * 8 6 4 0 0 ) , ' seconds.' ) ;
writeln( 'Press Enter... ' ) ;
Readln;
end .