rm exe & old versions of gcodegenerator

This commit is contained in:
Игорь Брылёв 2025-01-17 20:13:12 +03:00
parent b8561888fa
commit cd0292f19a
126 changed files with 198 additions and 173982 deletions

44
.gitignore vendored Normal file
View file

@ -0,0 +1,44 @@
# Pascal err out logs
*.err
*.out
~$*.SLDPRT
~$*.SLDASM
# For PCBs designed using KiCad: http://www.kicad-pcb.org/
# Format documentation: http://kicad-pcb.org/help/file-formats/
# Temporary files
*-backups/
*.000
*.bak
*.bck
*.kicad_sch.lck
*.kicad_pcb-bak
*.kicad_pcb.lck
*#auto_saved_files#
*~
_autosave-*
*.tmp
*-cache.lib
*-rescue.lib
*-save.pro
*-save.kicad_pcb
*.sch-bak
fp-info-cache
# Netlist files (exported from Eeschema)
*.net
# Autorouter files (exported from Pcbnew)
*.dsn
*.ses
# Visual Studio Code
*.vscode/
# Platformio .pio
.pio/
# JetBrains CLion
.idea/

View file

@ -1,14 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "fpDebug",
"type": "fpDebug",
"request": "launch",
"program": "${workspaceFolder}/executable"
}
]
}

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="calculateangles.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="calculateangles"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,43 +0,0 @@
program calculateangles;
uses SysUtils, Math; // Для работы с math
var
x0, y0, d, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
// Исходные данные
x0 := -30.37862;
y0 := 5.24115;
d := 0.825;
// Вычисление коэффициентов квадратного уравнения
a := x0 * x0 - d * d;
b := 2 * x0 * y0;
c := y0 * y0 - d * d;
// Вычисление дискриминанта
discriminant := b * b - 4 * a * c;
// Проверка наличия решений
if discriminant >= 0 then
begin
// Вычисление корней квадратного уравнения
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
// Вычисление углов в градусах
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Вывод результатов
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln; // Чтобы консоль не закрылась сразу
end.

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="calculateangles.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="5" Y="43"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="-1"/>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="calculaterectanglecorner.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CalculateRectangleCorner"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="calculaterectanglecorner"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,30 +0,0 @@
program CalculateRectangleCorner;
uses Math;
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY: real;
begin
length := 30.7;
width := 5.6;
angleDegrees := 15;
angleRadians := ((angleDegrees-90)) * Pi / 180;
centerX := 0;
centerY := 0;
halfLength := length / 2;
halfWidth := width / 2;
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
//leftBottomY := centerY - halfWidth * Sin(angleRadians) - halfLength * Cos(angleRadians);
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
readln;
end.

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="calculaterectanglecorner.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CalculateRectangleCorner"/>
<IsVisibleTab Value="True"/>
<CursorPos X="20" Y="12"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="1">
<Position>
<Filename Value="calculaterectanglecorner.lpr"/>
<Caret Line="28" Column="5"/>
</Position>
<Position>
<Filename Value="calculaterectanglecorner.lpr"/>
<Caret Line="13" Column="73"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedCalculation"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,56 +0,0 @@
program CombinedCalculation;
uses Math;
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY, distance, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
// Входные данные для второй задачи (прямоугольник)
length := 30.7;
width := 5.6;
angleDegrees := -15;
distance := 0.825;
//angleRadians := (180-(angleDegrees+90)) * Pi / 180;
angleRadians := angleDegrees * Pi / 180;
halfLength := length / 2;
halfWidth := width / 2;
centerX := 0; //Инициализируем центр
centerY := 0; //Инициализируем центр
// Вычисление координат центра прямоугольника
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
// Вычисление координат левого нижнего угла (вторая задача)
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
// Использование результатов второй задачи в первой задаче
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
// Первая задача (исправленные коэффициенты)
a := leftBottomX * leftBottomX + leftBottomY * leftBottomY;
b := 2 * leftBottomX * leftBottomY;
c := leftBottomY * leftBottomY - distance * distance;
discriminant := b * b - 4 * a * c;
if discriminant >= 0 then
begin
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln;
end.

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedCalculation"/>
<IsVisibleTab Value="True"/>
<CursorPos X="23" Y="12"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="7">
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="33" Column="65" TopLine="12"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="50" Column="5" TopLine="11"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="35" Column="71" TopLine="11"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="25" Column="120"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="37" Column="86" TopLine="7"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="38" Column="66" TopLine="7"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="12" Column="20" TopLine="4"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="15" Column="33"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation2.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation2"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,67 +0,0 @@
program combinedcalculation2;
uses SysUtils, Math; // Для работы с math
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY: real;
x0, y0, d, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
length := 40.7;
width := 5.6;
angleDegrees := 15;
angleRadians := ((angleDegrees+90)) * Pi / 180;
centerX := 0;
centerY := 0;
halfLength := length / 2;
halfWidth := width / 2;
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
//leftBottomY := centerY - halfWidth * Sin(angleRadians) - halfLength * Cos(angleRadians);
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
// Исходные данные
x0 := leftBottomY;
y0 := leftBottomX;
d := 0.825;
// Вычисление коэффициентов квадратного уравнения
a := x0 * x0 - d * d;
b := 2 * x0 * y0;
c := y0 * y0 - d * d;
// Вычисление дискриминанта
discriminant := b * b - 4 * a * c;
// Проверка наличия решений
if discriminant >= 0 then
begin
// Вычисление корней квадратного уравнения
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
// Вычисление углов в градусах
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Вывод результатов
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln; // Чтобы консоль не закрылась сразу
end.

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation2.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="14" Y="10"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="-1"/>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation3.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation3"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,67 +0,0 @@
program combinedcalculation3;
uses SysUtils, Math;
const
lengthConst = 40.7;
widthConst = 5.6;
angleDegreesConst = 15;
distanceConst = 0.825;
function CalculateMaxMinAngle(rodLength, rodWidth, angle, clearance: double): double;
var
angleRadians, leftBottomX, leftBottomY: double;
leftBottomX2, leftBottomY2: double;
a, b, c, discriminant, t1, t2, theta1, theta2: double;
a2, b2, c2, discriminant2, t12, t22, theta12, theta22: double;
begin
CalculateMaxMinAngle := 0; // Изначально нет решений
angleRadians := (angle + 90) * Pi / 180;
leftBottomX := -rodLength / 2 * Cos(angleRadians) - rodLength / 2 * Cos(angleRadians) - rodWidth / 2 * Sin(angleRadians);
leftBottomY := -rodLength / 2 * Sin(angleRadians) - rodLength / 2 * Sin(angleRadians) + rodWidth / 2 * Cos(angleRadians);
writeln('Coordinates bottom-left corner: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
leftBottomY2 := -rodLength / 2 * Cos(0) - rodLength / 2 * Cos(0) - rodWidth / 2 * Sin(0);
leftBottomX2 := -rodLength / 2 * Sin(0) - rodLength / 2 * Sin(0) + rodWidth / 2 * Cos(0);
writeln('Coordinates second bottom-left corner: (', leftBottomX2:0:6, ', ', leftBottomY2:0:6, ')');
a := sqr(leftBottomY) - sqr(clearance);
b := 2 * leftBottomY * leftBottomX;
c := sqr(leftBottomX) - sqr(clearance);
discriminant := sqr(b) - 4 * a * c;
if discriminant >= 0 then
begin
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Возвращаем меньший угол
if theta1 < theta2 then
CalculateMaxMinAngle := theta1
else
CalculateMaxMinAngle := theta2;
end;
end;
var
minAngle: double;
begin
minAngle := CalculateMaxMinAngle(lengthConst, widthConst, angleDegreesConst, distanceConst);
if minAngle <> 0 then
writeln('Меньший угол: ', minAngle:0:10)
else
writeln('Дискриминант отрицательный, нет вещественных решений.');
readln;
end.

View file

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation3.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="50"/>
<CursorPos X="67" Y="82"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="4">
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="12" Column="29"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="28" Column="68"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="67" Column="5" TopLine="28"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="32" Column="64"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="25" Column="76"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="calculateangles.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="calculateangles"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,43 +0,0 @@
program calculateangles;
uses SysUtils, Math; // Для работы с math
var
x0, y0, d, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
// Исходные данные
x0 := -40.03787;
y0 := 7.82934;
d := 0.825;
// Вычисление коэффициентов квадратного уравнения
a := x0 * x0 - d * d;
b := 2 * x0 * y0;
c := y0 * y0 - d * d;
// Вычисление дискриминанта
discriminant := b * b - 4 * a * c;
// Проверка наличия решений
if discriminant >= 0 then
begin
// Вычисление корней квадратного уравнения
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
// Вычисление углов в градусах
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Вывод результатов
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln; // Чтобы консоль не закрылась сразу
end.

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="calculateangles.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="4"/>
<CursorPos X="16" Y="11"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="-1"/>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="calculaterectanglecorner.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CalculateRectangleCorner"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="calculaterectanglecorner"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,30 +0,0 @@
program CalculateRectangleCorner;
uses Math;
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY: real;
begin
length := 30.7;
width := 5.6;
angleDegrees := 15;
angleRadians := ((angleDegrees+90)) * Pi / 180;
centerX := 0;
centerY := 0;
halfLength := length / 2;
halfWidth := width / 2;
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
//leftBottomY := centerY - halfWidth * Sin(angleRadians) - halfLength * Cos(angleRadians);
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
readln;
end.

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="calculaterectanglecorner.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CalculateRectangleCorner"/>
<IsVisibleTab Value="True"/>
<CursorPos X="34" Y="12"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="1">
<Position>
<Filename Value="calculaterectanglecorner.lpr"/>
<Caret Line="28" Column="5"/>
</Position>
<Position>
<Filename Value="calculaterectanglecorner.lpr"/>
<Caret Line="13" Column="73"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="calculatetopleftcorner.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="calculatetopleftcorner"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,15 +0,0 @@
program calculatetopleftcorner;
var
length, width, x, y: real;
begin
length := 27.9;
width := 2.4;
x := -length;
y := width / 2;
writeln('x: ', x:0:5, ', y: ', y:0:5);
readln;
end.

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="calculatetopleftcorner.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="5" Y="15"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="-1"/>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedCalculation"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,56 +0,0 @@
program CombinedCalculation;
uses Math;
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY, distance, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
// Входные данные для второй задачи (прямоугольник)
length := 30.7;
width := 5.6;
angleDegrees := -15;
distance := 0.825;
angleRadians := (angleDegrees+90) * Pi / 180;
//angleRadians := angleDegrees * Pi / 180;
halfLength := length / 2;
halfWidth := width / 2;
centerX := 0; //Инициализируем центр
centerY := 0; //Инициализируем центр
// Вычисление координат центра прямоугольника
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
// Вычисление координат левого нижнего угла (вторая задача)
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
// Использование результатов второй задачи в первой задаче
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
// Первая задача (исправленные коэффициенты)
a := leftBottomX * leftBottomX + leftBottomY * leftBottomY;
b := 2 * leftBottomX * leftBottomY;
c := leftBottomY * leftBottomY - distance * distance;
discriminant := b * b - 4 * a * c;
if discriminant >= 0 then
begin
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln;
end.

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedCalculation"/>
<IsVisibleTab Value="True"/>
<CursorPos X="36" Y="26"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="7">
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="33" Column="65" TopLine="12"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="50" Column="5" TopLine="11"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="35" Column="71" TopLine="11"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="25" Column="120"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="37" Column="86" TopLine="7"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="38" Column="66" TopLine="7"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="12" Column="20" TopLine="4"/>
</Position>
<Position>
<Filename Value="combinedcalculation.lpr"/>
<Caret Line="15" Column="33"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation2.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation2"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,123 +0,0 @@
program combinedcalculation2;
uses SysUtils, Math;
const
LENGTH = 40.7;
WIDTH = 5.6;
ANGLE_DEGREES = 15;
DISTANCE = 0.825;
var
angleRadians, leftBottomX, leftBottomY: real;
a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
angleRadians := (ANGLE_DEGREES + 90) * Pi / 180;
leftBottomX := -LENGTH / 2 * Cos(angleRadians) - LENGTH / 2 * Cos(angleRadians) - WIDTH / 2 * Sin(angleRadians);
leftBottomY := -LENGTH / 2 * Sin(angleRadians) - LENGTH / 2 * Sin(angleRadians) + WIDTH / 2 * Cos(angleRadians);
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
// Вычисление коэффициентов квадратного уравнения
a := sqr(leftBottomY) - sqr(DISTANCE);
b := 2 * leftBottomY * leftBottomX;
c := sqr(leftBottomX) - sqr(DISTANCE);
// Вычисление дискриминанта
discriminant := sqr(b) - 4 * a * c;
// Проверка наличия решений
if discriminant >= 0 then
begin
// Вычисление корней квадратного уравнения
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
// Вычисление углов в градусах
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Вывод результатов
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln;
end.
(*
program combinedcalculation2;
uses SysUtils, Math; // Для работы с math
var
length, width, angleDegrees, angleRadians, centerX, centerY, halfLength, halfWidth, leftBottomX, leftBottomY: real;
x0, y0, d, a, b, c, discriminant, t1, t2, theta1, theta2: real;
begin
length := 40.7;
width := 5.6;
angleDegrees := 15;
angleRadians := ((angleDegrees+90)) * Pi / 180;
centerX := 0;
centerY := 0;
halfLength := length / 2;
halfWidth := width / 2;
centerX := centerX - halfLength * Cos(angleRadians);
centerY := centerY - halfLength * Sin(angleRadians);
leftBottomX := centerX - halfLength * Cos(angleRadians) - halfWidth * Sin(angleRadians);
leftBottomY := centerY - halfLength * Sin(angleRadians) + halfWidth * Cos(angleRadians);
//leftBottomY := centerY - halfWidth * Sin(angleRadians) - halfLength * Cos(angleRadians);
writeln('Координаты левого нижнего угла: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
// Исходные данные
x0 := leftBottomY;
y0 := leftBottomX;
d := 0.825;
// Вычисление коэффициентов квадратного уравнения
a := x0 * x0 - d * d;
b := 2 * x0 * y0;
c := y0 * y0 - d * d;
// Вычисление дискриминанта
discriminant := b * b - 4 * a * c;
// Проверка наличия решений
if discriminant >= 0 then
begin
// Вычисление корней квадратного уравнения
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
// Вычисление углов в градусах
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
// Вывод результатов
writeln('Угол 1: ', theta1:0:10);
writeln('Угол 2: ', theta2:0:10);
end
else
begin
writeln('Дискриминант отрицательный, нет вещественных решений.');
end;
readln; // Чтобы консоль не закрылась сразу
end.
*)

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation2.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="14"/>
<CursorPos X="5" Y="53"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory>
<Position>
<Filename Value="combinedcalculation2.lpr"/>
<Caret Line="33" Column="70"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="combinedcalculation3.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="combinedcalculation3"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,98 +0,0 @@
program combinedcalculation3;
uses SysUtils, Math;
const
lengthConst = 40.7;
widthConst = 5.6;
angleDegreesConst = 15;
distanceConst = 0.825;
function CalculateMaxMinAngle(rodLength, rodWidth, angle, clearance: double): double;
var
angleRadians, leftBottomX, leftBottomY: double;
leftBottomX2, leftBottomY2: double;
a, b, c, discriminant, t1, t2, theta1, theta2: double;
a2, b2, c2, discriminant2, t12, t22, theta12, theta22: double;
begin
CalculateMaxMinAngle := 0; // Изначально нет решений
angleRadians := (angle + 90) * Pi / 180;
leftBottomX := -rodLength / 2 * Cos(angleRadians) - rodLength / 2 * Cos(angleRadians) - rodWidth / 2 * Sin(angleRadians);
leftBottomY := -rodLength / 2 * Sin(angleRadians) - rodLength / 2 * Sin(angleRadians) + rodWidth / 2 * Cos(angleRadians);
writeln('Coordinates bottom-left corner: (', leftBottomX:0:6, ', ', leftBottomY:0:6, ')');
leftBottomY2 := -rodLength / 2 * Cos(0) - rodLength / 2 * Cos(0) - rodWidth / 2 * Sin(0);
leftBottomX2 := -rodLength / 2 * Sin(0) - rodLength / 2 * Sin(0) + rodWidth / 2 * Cos(0);
writeln('Coordinates second bottom-left corner: (', leftBottomX2:0:6, ', ', leftBottomY2:0:6, ')');
a := sqr(leftBottomY) - sqr(clearance);
b := 2 * leftBottomY * leftBottomX;
c := sqr(leftBottomX) - sqr(clearance);
discriminant := sqr(b) - 4 * a * c;
if discriminant >= 0 then
begin
t1 := (-b + sqrt(discriminant)) / (2 * a);
t2 := (-b - sqrt(discriminant)) / (2 * a);
theta1 := ArcTan(t1) * 180 / Pi;
theta2 := ArcTan(t2) * 180 / Pi;
(* // Возвращаем меньший угол
if theta1 < theta2 then
CalculateMaxMinAngle := theta1
else
CalculateMaxMinAngle := theta2;*)
writeln('theta1: ', theta1:0:6);
writeln('theta2: ', theta2:0:6);
writeln();
if theta2 < theta1 then theta1 := theta2;
a2 := sqr(leftBottomY2) - sqr(clearance);
b2 := 2 * leftBottomY2 * leftBottomX2;
c2 := sqr(leftBottomX2) - sqr(clearance);
discriminant2 := sqr(b2) - 4 * a2 * c2;
if discriminant2 >= 0 then
begin
t12 := (-b2 + sqrt(discriminant2)) / (2 * a2);
t22 := (-b2 - sqrt(discriminant2)) / (2 * a2);
theta12 := ArcTan(t12) * 180 / Pi;
theta22 := ArcTan(t22) * 180 / Pi;
writeln('theta12: ', theta12:0:6);
writeln('theta22: ', theta22:0:6);
writeln();
if theta22 > theta12 then theta12 := theta22;
CalculateMaxMinAngle:= (theta12 + theta22)/2;
writeln('CalculateMaxMinAngle: ', CalculateMaxMinAngle:0:6);
end;
end;
end;
var
minAngle: double;
begin
minAngle := CalculateMaxMinAngle(lengthConst, widthConst, angleDegreesConst, distanceConst);
if minAngle <> 0 then
writeln('Меньший угол: ', minAngle:0:10)
else
writeln('Дискриминант отрицательный, нет вещественных решений.');
readln;
end.

View file

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="combinedcalculation3.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="59"/>
<CursorPos Y="98"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="5">
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="12" Column="29"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="28" Column="68"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="67" Column="5" TopLine="28"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="32" Column="64"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="25" Column="76"/>
</Position>
<Position>
<Filename Value="combinedcalculation3.lpr"/>
<Caret Line="82" Column="67" TopLine="50"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -FiD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64 -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\calculateangles.exe calculateangles.lpr"/>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -FiD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64 -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\calculaterectanglecorner.exe calculaterectanglecorner.lpr"/>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -FiD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64 -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\combinedcalculation.exe combinedcalculation.lpr"/>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -FiD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64 -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\combinedcalculation2.exe combinedcalculation2.lpr"/>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -gw3 -gl -l -vewnhibq -FiD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64 -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\Old\combinedcalculation3.exe combinedcalculation3.lpr"/>
</CONFIG>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +0,0 @@
program helloworld;
uses crt;
begin
write('Hello world!');
end.

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="rectangledistance.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedProgram"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="rectangledistance"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,27 +0,0 @@
program CombinedProgram;
uses Math;
var
length, width, angleDegrees, distance: real;
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians: real;
begin
length := 27.9;
width := 2.4;
angleDegrees := 15;
topLeftX := -length;
topLeftY := width / 2;
angleRadians := degToRad(-angleDegrees);
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
writeln('Original top left x: ', topLeftX:0:5, ', y: ', topLeftY:0:5);
writeln('Rotated x: ', rotatedX:0:5, ', y: ', rotatedY:0:5);
writeln('Distance: ', distance:0:5);
readln;
end.

View file

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="rectangledistance.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedProgram"/>
<IsVisibleTab Value="True"/>
<CursorPos Y="27"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="5">
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="30" Column="85"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="33" Column="80" TopLine="13"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="45" Column="5" TopLine="6"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="26" Column="49"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="28" Column="47"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="27" Column="5"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

Binary file not shown.

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="rotatepoint.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="rotatepoint"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,15 +0,0 @@
program CalculateTopLeftCorner;
var
length, width, x, y: real;
begin
length := 27.9;
width := 2.4;
x := -length;
y := width / 2;
writeln('x: ', x:0:5, ', y: ', y:0:5);
readln;
end.

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="rotatepoint.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="5" Y="15"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory>
<Position>
<Filename Value="rotatepoint.lpr"/>
<Caret Line="9" Column="24"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1 +0,0 @@
gcodegenerator.exe input.txt output.gcode

View file

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="GCodeGenerator"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,161 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="GCodeGenerator"/>
<IsVisibleTab Value="True"/>
<TopLine Value="312"/>
<CursorPos X="3" Y="323"/>
<FoldState Value=" TC6B21 PK5I T3i62{e011 TKlM0WT"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="48" Column="39" TopLine="31"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="31" Column="3" TopLine="26"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="22" Column="48" TopLine="10"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="43" Column="59" TopLine="22"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="29" Column="12" TopLine="17"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="35" Column="61" TopLine="12"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="32" Column="40" TopLine="17"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="34" Column="29" TopLine="23"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="71" Column="29" TopLine="47"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="55" Column="50" TopLine="36"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="68" Column="3" TopLine="67"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="190" Column="61" TopLine="162"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="196" Column="51" TopLine="175"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="38" Column="3"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="223" Column="45" TopLine="189"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="231" Column="58" TopLine="213"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="249" Column="40" TopLine="227"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="242" Column="80" TopLine="216"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="248" Column="97" TopLine="231"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="263" Column="45" TopLine="243"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="259" Column="22" TopLine="231"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="260" Column="5" TopLine="21"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="45" Column="27" TopLine="13"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="286" Column="17" TopLine="218"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="7" Column="9"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="289" Column="72" TopLine="272"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="194" Column="72" TopLine="35"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="220" Column="15" TopLine="49"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="338" Column="99" TopLine="316"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="356" Column="40" TopLine="324"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,369 +0,0 @@
program GCodeGenerator;
uses
SysUtils, StrUtils, Math;
type
TPoint = record
X, Y: double;
end;
type
TStatorParams = record
BaseDiameter: 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;
PathClearance: Double;
WorkSpeed :integer;
end;
var
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
i, j, k: Integer;
CurrentCoilTurns :Integer;
AngleBetweenRays :double;
RequiredSpacing: Double;
LayerNumber :Integer;
angle : double;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
case Trim(Parts[0]) of
'base_dia': begin
StatorParams.BaseDiameter := StrToFloat(Value);
writeln('Base Diameter: ', StatorParams.BaseDiameter:8:2);
writeln();
end;
'num_rays': begin
StatorParams.NumberOfRays := StrToInt(Value);
writeln('Number of Rays: ', StatorParams.NumberOfRays);
AngleBetweenRays := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
function CircleCoordinates(diameter, angleDegrees: Double): TPoint;
var
radius: Double;
angleRadians: Double;
begin
radius := diameter / 2;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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;
(* //ToDO Ïåðåïèñàòü ôóíêöèþ, ÷òîáû îíà âîçâðàùàëà òîëüêî îäíî çíà÷åíèå Z. Íàì æå íóæíî èñïðàâëÿòü òîëüêî îäíó êîîðäèíàòó.
function NormalizeZ(xOkr, yOkr, radius: Real; thetaDeg: Real): TPoint;
var
thetaRad, thetaCorrRad, xKas, yKas, alphaRad, mTang, bTang, mHor, xPrym, yPrym: Real;
begin
thetaRad := DegToRad(thetaDeg);
;thetaCorrRad := thetaRad + DegToRad(270);
// 1. Êîîðäèíàòû òî÷êè êàñàíèÿ
xKas := radius * Cos(thetaCorrRad);
yKas := radius * Sin(thetaCorrRad);
// 2. Óãîë íàêëîíà êàñàòåëüíîé
alphaRad := thetaCorrRad + PI / 2;
// 3. Óðàâíåíèå êàñàòåëüíîé (y = m*x + b)
mTang := Tan(alphaRad);
bTang := yKas - mTang * xKas;
// 4. Óðàâíåíèå ãîðèçîíòàëüíîé ïðÿìîé
mHor := Tan(alphaRad - PI/2);
// 5. Òî÷êà ïåðåñå÷åíèÿ
xPrym := (bTang + yOkr + mHor * xOkr)/(mHor - mTang);
yPrym := mTang * xPrym + bTang;
NormalizeZ.x := xPrym;
NormalizeZ.y := yPrym;
//Writeln('thetaDeg =',thetaDeg:0:2,' ,xKas = ',xKas:0:2,' ,yKas = ',yKas:0:2);
Writeln('thetaDeg =',thetaDeg:0:2,' ,xPrym = ',xPrym:0:2,' ,yPrym = ',yPrym:0:2);
end;
*)
function NormalizeZ(radius: Real; thetaDeg: Real): Real;
var
thetaRad, alphaRad, xKas, yKas, mTang, bTang: Real;
begin
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
NormalizeZ := NaN;
end
else
begin
NormalizeZ := -bTang / mTang;
end;
end;
begin
// Command line argument handling
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
// **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);
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
writeln('CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, 'G1 X', -1*CoilRadius:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Äåëàåì êðóã.
Inc(LayerNumber);
CurrentCoilTurns := round(StatorParams.RayLength/StatorParams.WireDiameter);
// CurrentCoilTurns := 1;
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns' );
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
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/36;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
// *** Your G-code generation logic here ***
except
on E: Exception do
begin
writeln('Error writing to output file: ', E.Message);
Halt(1);
end;
end;
CloseFile(OutFile);
writeln('G-code generated to: ', OutputFileName);
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v2"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v2.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v2"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,160 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator_v2.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="402"/>
<CursorPos Y="418"/>
<FoldState Value=" TC6B2 T3iD2{i411 Pj4m021"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="327" Column="6" TopLine="300"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="383" Column="120" TopLine="347"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="392" Column="80" TopLine="355"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="396" Column="51" TopLine="373"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="406" Column="124" TopLine="377"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="6" TopLine="383"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="402" Column="28" TopLine="371"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="406" Column="64" TopLine="377"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="407" TopLine="383"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="404" Column="185" TopLine="384"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="36" TopLine="384"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="370" Column="12" TopLine="361"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="393" Column="30" TopLine="375"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="321" TopLine="306"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="324" Column="24" TopLine="306"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="361" Column="50" TopLine="277"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="292" TopLine="205"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="346" Column="126" TopLine="326"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="344" Column="27" TopLine="329"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="52" Column="19" TopLine="34"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="343" Column="23" TopLine="323"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="411" Column="31" TopLine="379"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="409" Column="49" TopLine="379"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="333" Column="31" TopLine="328"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="11" TopLine="381"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="389" Column="70" TopLine="381"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="430" Column="64" TopLine="391"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="409" Column="33" TopLine="389"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="342" Column="20" TopLine="322"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="42" TopLine="386"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,497 +0,0 @@
program gcodegenerator_v2;
uses
SysUtils, StrUtils, Math;
type
TPoint = record
X, Y: double;
end;
type
TStatorParams = record
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;
PathClearance: Double;
WorkSpeed :integer;
end;
var
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius,CoilWidth,CoilHeight :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
i, j, k: Integer;
CoilLength :double;
CurrentCoilTurns, CoilTurnsSum :Integer;
AngleBetweenRays :double;
RequiredSpacing: Double;
LayerNumber :Integer;
MaxLayers :Integer;
angle :double;
MaxDepth,MaxPath :double;
MoveForward:boolean;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
case Trim(Parts[0]) of
'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 := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
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;
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double;
begin
// Âû÷èñëÿåì êîîðäèíàòû âåðõíåãî ëåâîãî óãëà ïðÿìîóãîëüíèêà
topLeftX := -length;
topLeftY := width / 2;
// Ïðåîáðàçóåì óãîë â ðàäèàíû (ñ ó÷åòîì âðàùåíèÿ ïî ÷àñîâîé ñòðåëêå)
angleRadians := degToRad(-angleDegrees);
// Âû÷èñëÿåì êîîðäèíàòû ïîâåðíóòîãî íèæíåãî ëåâîãî óãëà âòîðîãî ïðÿìîóãîëüíèêà
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
// Âû÷èñëÿåì ðàññòîÿíèå ìåæäó òî÷êàìè
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
// Âîçâðàùàåì ðåçóëüòàò
MaxPath := distance;
end;
begin
// Command line argument handling
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
ReadInputFile();
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
CoilWidth:=(StatorParams.RayTopWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
CoilHeight:=(StatorParams.RayTopHeight+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
writeln('CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, 'G1 X', -1*CoilRadius:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
//Âñòà¸ì íà ïàóçó äëÿ òîãî, ÷òîáû ïðèâÿçàòü êîíåö ïðîâîëîêè
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Íà÷èíàåì ìîòàòü êàòóøêó.
//Ñ÷èòàåì, ñêîëüêî ñëî¸â ìîæåì íàìîòàòü.
MaxPath:=CalculateMaxPath((StatorParams.RayLength+StatorParams.BaseRadius), StatorParams.RayWidth, AngleBetweenRays);
// MaxLayers :=trunc(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
MaxLayers :=round(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
writeln(OutFile, ';MaxLayers ', MaxLayers);
Inc(LayerNumber);
MoveForward:=true;
if (StatorParams.RayShape = 'circle') then
begin
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
// 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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
end
else if (StatorParams.RayShape = 'rect') then
begin
writeln(OutFile, ';Rect? ');
while (LayerNumber < MaxLayers) do
begin
writeln(OutFile, ';Layer ', LayerNumber);
//Ñ÷èòàåì äëèíó êàòóøêè è êîëè÷åñòâî âèòêîâ
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RayWidth ', StatorParams.RayWidth:0:5);
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
writeln(OutFile, ';AngleBetweenRays ', AngleBetweenRays:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
writeln(OutFile);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns on ', LayerNumber, ' layer.' );
writeln(OutFile,';CoilWidth = ',CoilWidth:0:5);
for j := 0 to CurrentCoilTurns do
begin
writeln(OutFile,';Coil¹ = ',j);
writeln(OutFile,'M117 ',j);
//angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
//Divide the path into 100 points
(* for k := 1 to 100 do
begin
end; *)
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(-1*CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
end;
writeln(OutFile, 'M0');
// writeln(OutFile, 'G91');
// writeln(OutFile, 'G1 Y50');
// writeln(OutFile, 'G90');
Inc(LayerNumber);
CoilWidth:=CoilWidth+StatorParams.WireDiameter*2;
MoveForward:= not MoveForward;
writeln(OutFile,MoveForward);
end;
writeln(OutFile);
writeln(OutFile, ';Second coil');
Inc(LayerNumber);
RequiredSpacing:=StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
For i:=1 to 20 do
begin
LayerNumber:=i;
writeln(OutFile, ';Layer ', i);
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := floor(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
end;
end;
// *** Your G-code generation logic here ***
except
on E: Exception do
begin
writeln('Error writing to output file: ', E.Message);
Halt(1);
end;
end;
CloseFile(OutFile);
writeln('G-code generated to: ', OutputFileName);
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v3"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v3.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v3"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator_v3.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="69"/>
<CursorPos X="60" Y="95"/>
<FoldState Value=" TC6B22 PQUB T3lU2L5 PiYj]KT0pO4UR"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="1">
<Position>
<Filename Value="gcodegenerator_v3.pas"/>
<Caret Line="417" Column="42" TopLine="393"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v3.pas"/>
<Caret Line="529" Column="59" TopLine="493"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,544 +0,0 @@
program gcodegenerator_v3;
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;
PathClearance: Double;
WorkSpeed :integer;
end;
type
TLayer = record
Turns: Integer; // Êîëè÷åñòâî âèòêîâ
StartX: double; // Íà÷àëüíàÿ êîîðäèíàòà
EndX: double; // Êîíå÷íàÿ êîîðäèíàòà
end;
var
StartTime, EndTime, ExecutionTime: TDateTime;
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius,CoilWidth,CoilHeight :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
Layers: array[1..10] 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;
OperationMode:string;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
case Trim(Parts[0]) of
'stator_name': begin
StatorParams.StatorName := Value;
writeln('StatorName: ', StatorParams.StatorName);
writeln();
end;
'stator_name': 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 := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
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;
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double;
begin
// Âû÷èñëÿåì êîîðäèíàòû âåðõíåãî ëåâîãî óãëà ïðÿìîóãîëüíèêà
topLeftX := -length;
topLeftY := width / 2;
// Ïðåîáðàçóåì óãîë â ðàäèàíû (ñ ó÷åòîì âðàùåíèÿ ïî ÷àñîâîé ñòðåëêå)
angleRadians := degToRad(-angleDegrees);
// Âû÷èñëÿåì êîîðäèíàòû ïîâåðíóòîãî íèæíåãî ëåâîãî óãëà âòîðîãî ïðÿìîóãîëüíèêà
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
// Âû÷èñëÿåì ðàññòîÿíèå ìåæäó òî÷êàìè
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
// Âîçâðàùàåì ðåçóëüòàò
MaxPath := distance;
end;
begin
// Command line argument handling
StartTime := Now;
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
ReadInputFile();
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå è íèæå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
CoilWidth:=(StatorParams.RayTopWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
CoilHeight:=(StatorParams.RayTopHeight+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
writeln(OutFile, ';CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, ';CoilWidth = ', CoilWidth:0:3);
writeln(OutFile, ';CoilHeight = ', CoilHeight:0:3);
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y',-1*AngleBetweenRays/2:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
//Âñòà¸ì íà ïàóçó äëÿ òîãî, ÷òîáû ïðèâÿçàòü êîíåö ïðîâîëîêè
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Íà÷èíàåì ìîòàòü êàòóøêó.
//Ñ÷èòàåì, ñêîëüêî ñëî¸â ìîæåì íàìîòàòü.
MaxPath:=CalculateMaxPath((StatorParams.RayLength+StatorParams.BaseRadius), StatorParams.RayWidth, AngleBetweenRays);
// MaxLayers :=trunc(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
MaxLayers :=round(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
writeln(OutFile, ';MaxLayers ', MaxLayers);
Inc(LayerNumber);
//Äâèãàåìñÿ îò öåíòðà ê êðàþ
MoveForward:=true;
if (StatorParams.RayShape = 'circle') then
begin
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
// 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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
end
else if (StatorParams.RayShape = 'rect') then
begin
// writeln(OutFile, ';Rect? ');
while (LayerNumber <= MaxLayers) do
begin
//writeln(OutFile, ';Layer ', LayerNumber);
//Ñ÷èòàåì äëèíó êàòóøêè è êîëè÷åñòâî âèòêîâ
//Äëÿ ýòîãî ñ÷èòàåì íåîáõîäèìîå ðàññòîÿíèå ìåæäó ëó÷àìè. 2 äèàìåòðà ïðîâîäà + äèàìåòð èãëû + 2 çàçîðà áåçîïàñíîñòè
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
//Èñïîëüçóÿ íåîáõîäèìîå ðàññòîÿíèå, ðàññ÷èòûâàåì íà êàêóþ, ìàêñèìàëüíóþ ãëóáèíó ìîæåò ïîãðóçèòüñÿ èãîëêà. (ðàññòîÿíèå îò öåíòðà ñòàòîðà)
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(OutFile, ';MaxDepth ', MaxDepth:0:5);
writeln(OutFile);
//Åñëè äîïóñòèìàÿ ãëóáèíà ìåíüøå, ÷åì äèàìåòð îñíîâàíèÿ, òîãäà äëèíà êàòóøêè ðàâíà äëèíå ëó÷à.
//Åñëè äîïóñòèìàÿ ãëóáèíà áîëüøå, ÷åì äèàìåòð + äëèíà ëó÷à, ïðåêðàùàåì äâèæ.
//Èíà÷å äëèíà êàòóøêè ðàâíà "ðàäèóñ_îñíîâàíèÿ + äëèíà_ëó÷à - ãëóáèíà)
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
//Èñõîäÿ èç äëèíû êàòóøêè ñ÷èòàåì êîëè÷åñòâî âèòêîâ. È ñêëàäûâàåì ñêîëüêî âñåãî âèòêîâ íà êàòóøêå.
CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
//Ïåðåä êàæäûì ñëîåì íóæíî ïåðåñ÷èòàòü êîîðäèíàòó Z
write(OutFile,';RecalculateZ. CurrentZ=',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);
writeln(OutFile,'; NewZ=',CurrentZ:0:5);
//Íà÷èíàåì ìîòàòü.
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns on ', LayerNumber, ' layer.' );
for j := 1 to CurrentCoilTurns do
begin
writeln(OutFile,';Coil¹ = ',j);
writeln(OutFile,'M117 ',j);
//angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
//Divide the path into 100 points
//Move from left-down to left-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := ((-1*angle)+2*(angle/100*k));
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Left Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Left Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
//Divide the path into 100 points
//Move from left-down to rt-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := (angle-(2*(angle/100*k)));
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Right Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// angle := CalculateAngle(-1*CoilWidth/2, CurrentZ);
// writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Right Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
end;
writeln(OutFile, 'M0');
// writeln(OutFile, 'G91');
// writeln(OutFile, 'G1 Y50');
// writeln(OutFile, 'G90');
Inc(LayerNumber);
CoilWidth:=CoilWidth+StatorParams.WireDiameter*2;
MoveForward:= not MoveForward;
writeln(OutFile,';MoveForward: ', MoveForward);
end;
(* writeln(OutFile);
writeln(OutFile, ';Second coil');
Inc(LayerNumber);
RequiredSpacing:=StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
For i:=1 to 20 do
begin
LayerNumber:=i;
writeln(OutFile, ';Layer ', i);
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := floor(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
end;*)
end;
// *** Your G-code generation logic here ***
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 * 86400), ' seconds.');
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v4"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v4.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v4"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,160 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator_v4.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="538"/>
<CursorPos X="11" Y="582"/>
<FoldState Value=" TC6B21 PMUB T3iN2{r5 piZm92L]NiejM2 T0tN4U0"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="419" Column="18" TopLine="281"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="422" Column="40" TopLine="398"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="418" Column="18" TopLine="398"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="419" Column="20" TopLine="400"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="291" Column="12" TopLine="247"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="419" Column="66" TopLine="400"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="420" Column="18" TopLine="400"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="419" Column="18" TopLine="400"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="432" Column="22" TopLine="403"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="418" Column="62" TopLine="398"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="422" Column="72" TopLine="403"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="409" Column="32" TopLine="375"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="291" Column="12" TopLine="247"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="507" Column="20" TopLine="487"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="446" Column="34" TopLine="412"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="421" Column="63" TopLine="404"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="427" Column="71" TopLine="411"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="424" Column="42" TopLine="405"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="426" Column="52" TopLine="408"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="291" Column="12" TopLine="247"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="425" Column="157" TopLine="406"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="440" Column="48" TopLine="416"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="436" Column="42" TopLine="417"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="437" Column="42" TopLine="417"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="446" Column="69" TopLine="415"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="439" Column="55" TopLine="418"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="382" Column="23" TopLine="361"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="407" Column="11" TopLine="394"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="445" Column="87" TopLine="419"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v4.pas"/>
<Caret Line="582" Column="3" TopLine="621"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,668 +0,0 @@
program gcodegenerator_v4;
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;
PathClearance: Double;
WorkSpeed :integer;
end;
type
TLayer = record
Turns: Integer; // Êîëè÷åñòâî âèòêîâ
StartZ: double; // Íà÷àëüíàÿ êîîðäèíàòà
EndZ: double; // Êîíå÷íàÿ êîîðäèíàòà
end;
var
StartTime, EndTime, ExecutionTime: TDateTime;
InputFileName, OutputFileName, CoilGeometryFileName: string;
StatorParams: TStatorParams;
InFile, OutFile, CoilGeometryFile: TextFile;
Line: string;
CoilRadius,CoilWidth,CoilHeight :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
Layers: array[1..10] 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;
OperationMode:string;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
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 := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
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;
//ôóíêöèÿ âû÷èñëÿåò ìàêñèìàëüíîå ðàññòîÿíèå ìåæäó ëó÷àìè. Äëÿ ýòîãî îò öåíòðà ñòàòîðà äî
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double;
begin
// Âû÷èñëÿåì êîîðäèíàòû âåðõíåãî ëåâîãî óãëà ïðÿìîóãîëüíèêà
topLeftX := -length;
topLeftY := width / 2;
// Ïðåîáðàçóåì óãîë â ðàäèàíû (ñ ó÷åòîì âðàùåíèÿ ïî ÷àñîâîé ñòðåëêå)
angleRadians := degToRad(-angleDegrees);
// Âû÷èñëÿåì êîîðäèíàòû ïîâåðíóòîãî íèæíåãî ëåâîãî óãëà âòîðîãî ïðÿìîóãîëüíèêà
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
// Âû÷èñëÿåì ðàññòîÿíèå ìåæäó òî÷êàìè
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
// Âîçâðàùàåì ðåçóëüòàò
MaxPath := distance;
end;
procedure CalculateCoilGeometry();
var
StartZ, EndZ: double;
begin
writeln('CalculateCoilGeometry');
AssignFile(CoilGeometryFile, CoilGeometryFileName);
try
Rewrite(CoilGeometryFile);
//Ñ÷èòàåì, ñêîëüêî ñëî¸â ìîæåì íàìîòàòü.
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));
if (MaxLayers mod 2 <> 0) then writeln(CoilGeometryFile, ';MaxLayers ', MaxLayers) else
begin
dec(MaxLayers);
writeln(CoilGeometryFile, ';Ñalculations resulted in MaxLayers=', MaxLayers+1, ' because it is even, MaxLayers=MaxLayers-1 and equal ',MaxLayers);
end;
MoveForward:=true;
for i := 1 to MaxLayers do
begin
write(CoilGeometryFile, ';Lair:', i, ' have ');
//Ñ÷èòàåì äëèíó êàòóøêè è êîëè÷åñòâî âèòêîâ
//Äëÿ ýòîãî ñ÷èòàåì íåîáõîäèìîå ðàññòîÿíèå ìåæäó ëó÷àìè. 2 äèàìåòðà ïðîâîäà + äèàìåòð èãëû + 2 çàçîðà áåçîïàñíîñòè
RequiredSpacing:=StatorParams.PathClearance*2+(i-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
//Èñïîëüçóÿ íåîáõîäèìîå ðàññòîÿíèå, ðàññ÷èòûâàåì íà êàêóþ, ìàêñèìàëüíóþ ãëóáèíó ìîæåò ïîãðóçèòüñÿ èãîëêà. (ðàññòîÿíèå îò öåíòðà ñòàòîðà)
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);
//Åñëè äîïóñòèìàÿ ãëóáèíà ìåíüøå, ÷åì äèàìåòð îñíîâàíèÿ, òîãäà äëèíà êàòóøêè ðàâíà äëèíå ëó÷à.
//Åñëè äîïóñòèìàÿ ãëóáèíà áîëüøå, ÷åì äèàìåòð + äëèíà ëó÷à, ïðåêðàùàåì äâèæ.
//Èíà÷å äëèíà êàòóøêè ðàâíà "ðàäèóñ_îñíîâàíèÿ + äëèíà_ëó÷à - ãëóáèíà)
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);
//Èñõîäÿ èç äëèíû êàòóøêè ñ÷èòàåì êîëè÷åñòâî âèòêîâ. È ñêëàäûâàåì ñêîëüêî âñåãî âèòêîâ íà êàòóøêå.
CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
write(CoilGeometryFile, CurrentCoilTurns, ' Turns');
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
//Ïåðåä êàæäûì ñëîåì íóæíî ïåðåñ÷èòàòü êîîðäèíàòó Z
//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
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if (Length(TrimmedLine) = 0) then continue //exit() // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
else if TrimmedLine[1] in [';','#'] then continue; // exit(); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
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;
begin
// 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);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå è íèæå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
CoilWidth:=(StatorParams.RayTopWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
CoilHeight:=(StatorParams.RayTopHeight+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
writeln(OutFile, ';CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, ';CoilWidth = ', CoilWidth:0:3);
writeln(OutFile, ';CoilHeight = ', CoilHeight:0:3);
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y',-1*AngleBetweenRays/2:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
//Âñòà¸ì íà ïàóçó äëÿ òîãî, ÷òîáû ïðèâÿçàòü êîíåö ïðîâîëîêè
writeln(OutFile, 'M0');
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;
Inc(LayerNumber);
//Íà÷èíàåì ìîòàòü êàòóøêó.
writeln(OutFile);
writeln(OutFile, ';Start winding');
//Äâèãàåìñÿ îò öåíòðà ê êðàþ
MoveForward:=true;
if (StatorParams.RayShape = 'circle') then
begin
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
// 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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
end
else if (StatorParams.RayShape = 'rect') then
begin
// writeln(OutFile, ';Rect? ');
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);
//Íà÷èíàåì ìîòàòü.
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns on ', LayerNumber, ' layer.' );
writeln(OutFile);
(* for j := 1 to CurrentCoilTurns do
begin
writeln(OutFile,';Coil¹ = ',j);
writeln(OutFile,'M117 ',j);
//angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
//Divide the path into 100 points
//Move from left-down to left-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := ((-1*angle)+2*(angle/100*k));
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Left Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Left Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
//Divide the path into 100 points
//Move from left-down to rt-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := (angle-(2*(angle/100*k)));
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Right Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// angle := CalculateAngle(-1*CoilWidth/2, CurrentZ);
// writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Right Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
end;
writeln(OutFile, 'M0');
// writeln(OutFile, 'G91');
// writeln(OutFile, 'G1 Y50');
// writeln(OutFile, 'G90');
CoilWidth:=CoilWidth+StatorParams.WireDiameter*2;
MoveForward:= not MoveForward;
writeln(OutFile,';MoveForward: ', MoveForward); *)
//Inc(LayerNumber);
end;
end;
// *** Your G-code generation logic here ***
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 * 86400), ' seconds.');
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="rectangledistance.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedProgram"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="rectangledistance"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,32 +0,0 @@
program CombinedProgram;
uses Math;
var
length, width, angleDegrees, distance: real;
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians: real;
begin
length := 27.9;
width := 2.4;
angleDegrees := 15;
topLeftX := -length;
topLeftY := width / 2;
angleRadians := degToRad(-angleDegrees);
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
writeln('Original top left x: ', topLeftX:0:5, ', y: ', topLeftY:0:5);
writeln('Rotated x: ', rotatedX:0:5, ', y: ', rotatedY:0:5);
writeln('Distance: ', distance:0:5);
readln;
end.
function degToRad(deg: real): real;
begin
degToRad := deg * pi / 180;
end;

View file

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="rectangledistance.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="CombinedProgram"/>
<IsVisibleTab Value="True"/>
<CursorPos X="5" Y="27"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="4">
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="30" Column="85"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="33" Column="80" TopLine="13"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="45" Column="5" TopLine="6"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="26" Column="49"/>
</Position>
<Position>
<Filename Value="rectangledistance.lpr"/>
<Caret Line="28" Column="47"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="rotatepoint.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="rotatepoint"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,30 +0,0 @@
program rotatepoint;
uses Math;
var
x, y, angleDegrees, rotatedX, rotatedY: real;
function rotatePoint(x, y, angle: real; var rotatedX_out, rotatedY_out: real): real;
var
angleRadians: real;
begin
angleRadians := degToRad(-angle);
rotatedX_out := x * cos(angleRadians) - y * sin(angleRadians);
rotatedY_out := x * sin(angleRadians) + y * cos(angleRadians);
end;
function degToRad(deg: real): real;
begin
degToRad := deg * pi / 180;
end;
begin
x := -27.9;
y := -1.2;
angleDegrees := 15;
rotatePoint(x, y, angleDegrees, rotatedX, rotatedY);
writeln('Rotated x: ', rotatedX:0:5, ', y: ', rotatedY:0:5);
readln;
end.

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="rotatepoint.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="5" Y="30"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="-1"/>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

Binary file not shown.

View file

@ -1,161 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="GCodeGenerator"/>
<IsVisibleTab Value="True"/>
<TopLine Value="312"/>
<CursorPos X="57" Y="337"/>
<FoldState Value=" TC6B21 PK5I T3i62{e011 TKlM0WT"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="48" Column="39" TopLine="31"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="31" Column="3" TopLine="26"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="22" Column="48" TopLine="10"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="43" Column="59" TopLine="22"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="29" Column="12" TopLine="17"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="35" Column="61" TopLine="12"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="32" Column="40" TopLine="17"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="34" Column="29" TopLine="23"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="71" Column="29" TopLine="47"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="55" Column="50" TopLine="36"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="68" Column="3" TopLine="67"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="190" Column="61" TopLine="162"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="196" Column="51" TopLine="175"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="38" Column="3"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="223" Column="45" TopLine="189"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="231" Column="58" TopLine="213"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="249" Column="40" TopLine="227"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="242" Column="80" TopLine="216"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="248" Column="97" TopLine="231"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="263" Column="45" TopLine="243"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="259" Column="22" TopLine="231"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="260" Column="5" TopLine="21"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="45" Column="27" TopLine="13"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="286" Column="17" TopLine="218"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="7" Column="9"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="289" Column="72" TopLine="272"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="194" Column="72" TopLine="35"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="220" Column="15" TopLine="49"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="338" Column="99" TopLine="316"/>
</Position>
<Position>
<Filename Value="gcodegenerator.pas"/>
<Caret Line="356" Column="40" TopLine="324"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,369 +0,0 @@
program GCodeGenerator;
uses
SysUtils, StrUtils, Math;
type
TPoint = record
X, Y: double;
end;
type
TStatorParams = record
BaseDiameter: 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;
PathClearance: Double;
WorkSpeed :integer;
end;
var
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
i, j, k: Integer;
CurrentCoilTurns :Integer;
AngleBetweenRays :double;
RequiredSpacing: Double;
LayerNumber :Integer;
angle : double;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
case Trim(Parts[0]) of
'base_dia': begin
StatorParams.BaseDiameter := StrToFloat(Value);
writeln('Base Diameter: ', StatorParams.BaseDiameter:8:2);
writeln();
end;
'num_rays': begin
StatorParams.NumberOfRays := StrToInt(Value);
writeln('Number of Rays: ', StatorParams.NumberOfRays);
AngleBetweenRays := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
function CircleCoordinates(diameter, angleDegrees: Double): TPoint;
var
radius: Double;
angleRadians: Double;
begin
radius := diameter / 2;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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;
(* //ToDO Ïåðåïèñàòü ôóíêöèþ, ÷òîáû îíà âîçâðàùàëà òîëüêî îäíî çíà÷åíèå Z. Íàì æå íóæíî èñïðàâëÿòü òîëüêî îäíó êîîðäèíàòó.
function NormalizeZ(xOkr, yOkr, radius: Real; thetaDeg: Real): TPoint;
var
thetaRad, thetaCorrRad, xKas, yKas, alphaRad, mTang, bTang, mHor, xPrym, yPrym: Real;
begin
thetaRad := DegToRad(thetaDeg);
;thetaCorrRad := thetaRad + DegToRad(270);
// 1. Êîîðäèíàòû òî÷êè êàñàíèÿ
xKas := radius * Cos(thetaCorrRad);
yKas := radius * Sin(thetaCorrRad);
// 2. Óãîë íàêëîíà êàñàòåëüíîé
alphaRad := thetaCorrRad + PI / 2;
// 3. Óðàâíåíèå êàñàòåëüíîé (y = m*x + b)
mTang := Tan(alphaRad);
bTang := yKas - mTang * xKas;
// 4. Óðàâíåíèå ãîðèçîíòàëüíîé ïðÿìîé
mHor := Tan(alphaRad - PI/2);
// 5. Òî÷êà ïåðåñå÷åíèÿ
xPrym := (bTang + yOkr + mHor * xOkr)/(mHor - mTang);
yPrym := mTang * xPrym + bTang;
NormalizeZ.x := xPrym;
NormalizeZ.y := yPrym;
//Writeln('thetaDeg =',thetaDeg:0:2,' ,xKas = ',xKas:0:2,' ,yKas = ',yKas:0:2);
Writeln('thetaDeg =',thetaDeg:0:2,' ,xPrym = ',xPrym:0:2,' ,yPrym = ',yPrym:0:2);
end;
*)
function NormalizeZ(radius: Real; thetaDeg: Real): Real;
var
thetaRad, alphaRad, xKas, yKas, mTang, bTang: Real;
begin
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
NormalizeZ := NaN;
end
else
begin
NormalizeZ := -bTang / mTang;
end;
end;
begin
// Command line argument handling
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
// **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);
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
writeln('CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, 'G1 X', -1*CoilRadius:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Äåëàåì êðóã.
Inc(LayerNumber);
CurrentCoilTurns := round(StatorParams.RayLength/StatorParams.WireDiameter);
// CurrentCoilTurns := 1;
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns' );
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
// *** Your G-code generation logic here ***
except
on E: Exception do
begin
writeln('Error writing to output file: ', E.Message);
Halt(1);
end;
end;
CloseFile(OutFile);
writeln('G-code generated to: ', OutputFileName);
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v2"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v2.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v2"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,160 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator_v2.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="302"/>
<CursorPos X="24" Y="326"/>
<FoldState Value=" TC6B2 T3iD2{i5 piZm02KT"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="327" Column="6" TopLine="300"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="383" Column="120" TopLine="347"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="392" Column="80" TopLine="355"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="396" Column="51" TopLine="373"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="406" Column="124" TopLine="377"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="6" TopLine="383"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="402" Column="28" TopLine="371"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="406" Column="64" TopLine="377"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="407" TopLine="383"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="404" Column="185" TopLine="384"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="36" TopLine="384"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="370" Column="12" TopLine="361"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="393" Column="30" TopLine="375"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="321" TopLine="306"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="324" Column="24" TopLine="306"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="361" Column="50" TopLine="277"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="292" TopLine="205"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="346" Column="126" TopLine="326"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="344" Column="27" TopLine="329"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="52" Column="19" TopLine="34"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="343" Column="23" TopLine="323"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="411" Column="31" TopLine="379"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="409" Column="49" TopLine="379"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="333" Column="31" TopLine="328"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="11" TopLine="381"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="389" Column="70" TopLine="381"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="430" Column="64" TopLine="391"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="409" Column="33" TopLine="389"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="342" Column="20" TopLine="322"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v2.pas"/>
<Caret Line="408" Column="42" TopLine="386"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,497 +0,0 @@
program gcodegenerator_v2;
uses
SysUtils, StrUtils, Math;
type
TPoint = record
X, Y: double;
end;
type
TStatorParams = record
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;
PathClearance: Double;
WorkSpeed :integer;
end;
var
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius,CoilWidth,CoilHeight :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
i, j, k: Integer;
CoilLength :double;
CurrentCoilTurns, CoilTurnsSum :Integer;
AngleBetweenRays :double;
RequiredSpacing: Double;
LayerNumber :Integer;
MaxLayers :Integer;
angle :double;
MaxDepth,MaxPath :double;
MoveForward:boolean;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
case Trim(Parts[0]) of
'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 := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
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;
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double;
begin
// Âû÷èñëÿåì êîîðäèíàòû âåðõíåãî ëåâîãî óãëà ïðÿìîóãîëüíèêà
topLeftX := -length;
topLeftY := width / 2;
// Ïðåîáðàçóåì óãîë â ðàäèàíû (ñ ó÷åòîì âðàùåíèÿ ïî ÷àñîâîé ñòðåëêå)
angleRadians := degToRad(-angleDegrees);
// Âû÷èñëÿåì êîîðäèíàòû ïîâåðíóòîãî íèæíåãî ëåâîãî óãëà âòîðîãî ïðÿìîóãîëüíèêà
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
// Âû÷èñëÿåì ðàññòîÿíèå ìåæäó òî÷êàìè
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
// Âîçâðàùàåì ðåçóëüòàò
MaxPath := distance;
end;
begin
// Command line argument handling
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
ReadInputFile();
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
CoilWidth:=(StatorParams.RayTopWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
CoilHeight:=(StatorParams.RayTopHeight+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
writeln(OutFile, ';CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, 'G1 X', -1*CoilRadius:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
//Âñòà¸ì íà ïàóçó äëÿ òîãî, ÷òîáû ïðèâÿçàòü êîíåö ïðîâîëîêè
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Íà÷èíàåì ìîòàòü êàòóøêó.
//Ñ÷èòàåì, ñêîëüêî ñëî¸â ìîæåì íàìîòàòü.
MaxPath:=CalculateMaxPath((StatorParams.RayLength+StatorParams.BaseRadius), StatorParams.RayWidth, AngleBetweenRays);
// MaxLayers :=trunc(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
MaxLayers :=round(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
writeln(OutFile, ';MaxLayers ', MaxLayers);
Inc(LayerNumber);
MoveForward:=true;
if (StatorParams.RayShape = 'circle') then
begin
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
// 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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
end
else if (StatorParams.RayShape = 'rect') then
begin
writeln(OutFile, ';Rect? ');
while (LayerNumber < MaxLayers) do
begin
writeln(OutFile, ';Layer ', LayerNumber);
//Ñ÷èòàåì äëèíó êàòóøêè è êîëè÷åñòâî âèòêîâ
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RayWidth ', StatorParams.RayWidth:0:5);
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
writeln(OutFile, ';AngleBetweenRays ', AngleBetweenRays:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
writeln(OutFile);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns on ', LayerNumber, ' layer.' );
writeln(OutFile,';CoilWidth = ',CoilWidth:0:5);
for j := 0 to CurrentCoilTurns do
begin
writeln(OutFile,';Coil¹ = ',j);
writeln(OutFile,'M117 ',j);
//angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
//Divide the path into 100 points
(* for k := 1 to 100 do
begin
end; *)
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(-1*CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
end;
writeln(OutFile, 'M0');
// writeln(OutFile, 'G91');
// writeln(OutFile, 'G1 Y50');
// writeln(OutFile, 'G90');
Inc(LayerNumber);
CoilWidth:=CoilWidth+StatorParams.WireDiameter*2;
MoveForward:= not MoveForward;
writeln(OutFile,MoveForward);
end;
writeln(OutFile);
writeln(OutFile, ';Second coil');
Inc(LayerNumber);
RequiredSpacing:=StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
For i:=1 to 20 do
begin
LayerNumber:=i;
writeln(OutFile, ';Layer ', i);
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := floor(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
end;
end;
// *** Your G-code generation logic here ***
except
on E: Exception do
begin
writeln('Error writing to output file: ', E.Message);
Halt(1);
end;
end;
CloseFile(OutFile);
writeln('G-code generated to: ', OutputFileName);
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v3"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v3.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v3"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,52 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="gcodegenerator_v3.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="74"/>
<CursorPos X="10" Y="93"/>
<FoldState Value=" TC6B22 PQUB T3lU2L5 PiYj]KT0pO4UR"/>
<UsageCount Value="220"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="2">
<Position>
<Filename Value="gcodegenerator_v3.pas"/>
<Caret Line="417" Column="42" TopLine="393"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v3.pas"/>
<Caret Line="529" Column="59" TopLine="493"/>
</Position>
<Position>
<Filename Value="gcodegenerator_v3.pas"/>
<Caret Line="95" Column="60" TopLine="69"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode="default">
<Mode Name="default">
<local>
<CommandLineParams Value="input.txt output.gcode"/>
</local>
</Mode>
</Modes>
</RunParams>
<HistoryLists>
<List Name="LaunchingApplication" Type="File" Count="1">
<Item1 Value="C:\Windows\system32\cmd.exe /C ${TargetCmdLine}"/>
</List>
<List Name="CommandLineParameters" Count="1">
<Item1 Value="input.txt output.gcode"/>
</List>
</HistoryLists>
</ProjectSession>
</CONFIG>

View file

@ -1,544 +0,0 @@
program gcodegenerator_v3;
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;
PathClearance: Double;
WorkSpeed :integer;
end;
type
TLayer = record
Turns: Integer; // Êîëè÷åñòâî âèòêîâ
StartX: double; // Íà÷àëüíàÿ êîîðäèíàòà
EndX: double; // Êîíå÷íàÿ êîîðäèíàòà
end;
var
StartTime, EndTime, ExecutionTime: TDateTime;
InputFileName, OutputFileName: string;
StatorParams: TStatorParams;
InFile, OutFile: TextFile;
Line: string;
CoilRadius,CoilWidth,CoilHeight :double;
CurrentZ: double;
coords: TPoint;
normalizecoords: TPoint;
Layers: array[1..10] 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;
OperationMode:string;
function ParseLine(Line: string): Boolean;
var
Parts: array of string;
Value: string;
TrimmedLine: string;
begin
TrimmedLine := Trim(Line); // Óäàëÿåì ïðîáåëû â íà÷àëå è êîíöå ñòðîêè
if Length(TrimmedLine) = 0 then
begin
exit(true); // Ïóñòàÿ ñòðîêà - ïðîïóñêàåì
end
else if TrimmedLine[1] in [';','#'] then
begin
exit(true); // Ñòðîêà êîììåíòàðèÿ - ïðîïóñêàåì
end;
Parts := SplitString(TrimmedLine, '='); // Èñïîëüçóåì TrimmedLine
Result := Length(Parts) = 2;
if Result then
begin
Value := LowerCase(Trim(Parts[1])); // Ïðèâîäèì ê íèæíåìó ðåãèñòðó
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 := 360/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;
'path_clearance': begin
StatorParams.PathClearance := StrToFloat(Value);
writeln('Path Clearance: ', StatorParams.PathClearance:8:2);
writeln();
end;
'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;
// angleRadians := -1*angleDegrees * PI / 180; // Ïåðåâîä ãðàäóñîâ â ðàäèàíû
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
// 1. Ïðåîáðàçîâàíèå óãëà èç ãðàäóñîâ â ðàäèàíû.
thetaRad := DegToRad(thetaDeg);
// 2. Âû÷èñëåíèå êîîðäèíàò òî÷êè êàñàíèÿ íà îêðóæíîñòè (îòíîñèòåëüíî öåíòðà 0,0).
xKas := radius * Cos(thetaRad);
yKas := radius * Sin(thetaRad);
// 3. Âû÷èñëåíèå óãëà, ïåðïåíäèêóëÿðíîãî ðàäèóñ-âåêòîðó (êàñàòåëüíîé).
alphaRad := thetaRad + PI / 2;
// 4. Âû÷èñëåíèå óãëîâîãî êîýôôèöèåíòà êàñàòåëüíîé.
mTang := Tan(alphaRad);
// 5. Âû÷èñëåíèå ñâîáîäíîãî ÷ëåíà óðàâíåíèÿ êàñàòåëüíîé (y = mTang * x + bTang).
bTang := yKas - mTang * xKas;
// 6. Âû÷èñëåíèå êîîðäèíàòû X òî÷êè ïåðåñå÷åíèÿ êàñàòåëüíîé ñ îñüþ X (y = 0).
// 0 = mTang * x + bTang
// x = -bTang / mTang
if mTang = 0 then
begin
// Êàñàòåëüíàÿ ïàðàëëåëüíà îñè X - íåò òî÷êè ïåðåñå÷åíèÿ. Âîçâðàùàåì NaN.
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;
var
topLeftX, topLeftY, rotatedX, rotatedY, angleRadians, distance: double;
begin
// Âû÷èñëÿåì êîîðäèíàòû âåðõíåãî ëåâîãî óãëà ïðÿìîóãîëüíèêà
topLeftX := -length;
topLeftY := width / 2;
// Ïðåîáðàçóåì óãîë â ðàäèàíû (ñ ó÷åòîì âðàùåíèÿ ïî ÷àñîâîé ñòðåëêå)
angleRadians := degToRad(-angleDegrees);
// Âû÷èñëÿåì êîîðäèíàòû ïîâåðíóòîãî íèæíåãî ëåâîãî óãëà âòîðîãî ïðÿìîóãîëüíèêà
rotatedX := -length * cos(angleRadians) - (-width / 2) * sin(angleRadians);
rotatedY := -length * sin(angleRadians) + (-width / 2) * cos(angleRadians);
// Âû÷èñëÿåì ðàññòîÿíèå ìåæäó òî÷êàìè
distance := sqrt(sqr(rotatedX - topLeftX) + sqr(rotatedY - topLeftY));
// Âîçâðàùàåì ðåçóëüòàò
MaxPath := distance;
end;
begin
// Command line argument handling
StartTime := Now;
if ParamCount < 2 then
begin
Writeln('Usage: GCodeGenerator <input_file.txt> <output_file.gcode>');
Halt(1);
end;
InputFileName := ParamStr(1);
OutputFileName := ParamStr(2);
ReadInputFile();
// G-code generation
AssignFile(OutFile, OutputFileName);
try
Rewrite(OutFile);
// *** Your G-code generation logic here ***
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, 'G28 O'); //Home all "untrusted" axes
writeln(OutFile);
// Move to center of ray along Y axis and reset coordinate
writeln(OutFile, 'G1 X', StatorParams.RayCenterOffset:0:2);
writeln(OutFile, 'G92 X0');
//îòâîäèì èãëó ëåâåå è íèæå âåðøèíû ëó÷à
CoilRadius:=(StatorParams.RayTopHeight/2+StatorParams.NeedleDiameter/2+StatorParams.PathClearance);
CoilWidth:=(StatorParams.RayTopWidth+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
CoilHeight:=(StatorParams.RayTopHeight+StatorParams.NeedleDiameter+StatorParams.PathClearance*2);
writeln(OutFile, ';CoilRadius = ', CoilRadius:0:3);
writeln(OutFile, ';CoilWidth = ', CoilWidth:0:3);
writeln(OutFile, ';CoilHeight = ', CoilHeight:0:3);
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y',-1*AngleBetweenRays/2:0:3);
//ïðèáëèæàåìñÿ ê îñíîâàíèþ ñòàòîðà.
CurrentZ:=(StatorParams.BaseDiameter/2)+StatorParams.PathClearance;
writeln(OutFile, 'G1 Z', CurrentZ:0:2, ' F', StatorParams.WorkSpeed);
//Âñòà¸ì íà ïàóçó äëÿ òîãî, ÷òîáû ïðèâÿçàòü êîíåö ïðîâîëîêè
writeln(OutFile, 'M0');
writeln(OutFile, ';Start coil');
//Íà÷èíàåì ìîòàòü êàòóøêó.
//Ñ÷èòàåì, ñêîëüêî ñëî¸â ìîæåì íàìîòàòü.
MaxPath:=CalculateMaxPath((StatorParams.RayLength+StatorParams.BaseRadius), StatorParams.RayWidth, AngleBetweenRays);
// MaxLayers :=trunc(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
MaxLayers :=round(((MaxPath-RequiredSpacing)/2/StatorParams.WireDiameter));
writeln(OutFile, ';MaxLayers ', MaxLayers);
Inc(LayerNumber);
//Äâèãàåìñÿ îò öåíòðà ê êðàþ
MoveForward:=true;
if (StatorParams.RayShape = 'circle') then
begin
for j := 0 to CurrentCoilTurns do
begin
for i := 0 to 360 do
begin
coords := CircleCoordinates(CoilRadius*2, i+180);
// 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/360;
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);
RequiredSpacing:=RequiredSpacing+StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
CurrentZ:=RequiredSpacing/(2 * tan(AngleBetweenRays*PI/180/2));
writeln(OutFile, ';CurrentZ = ',CurrentZ:0:3);
end
else if (StatorParams.RayShape = 'rect') then
begin
// writeln(OutFile, ';Rect? ');
while (LayerNumber <= MaxLayers) do
begin
//writeln(OutFile, ';Layer ', LayerNumber);
//Ñ÷èòàåì äëèíó êàòóøêè è êîëè÷åñòâî âèòêîâ
//Äëÿ ýòîãî ñ÷èòàåì íåîáõîäèìîå ðàññòîÿíèå ìåæäó ëó÷àìè. 2 äèàìåòðà ïðîâîäà + äèàìåòð èãëû + 2 çàçîðà áåçîïàñíîñòè
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
//Èñïîëüçóÿ íåîáõîäèìîå ðàññòîÿíèå, ðàññ÷èòûâàåì íà êàêóþ, ìàêñèìàëüíóþ ãëóáèíó ìîæåò ïîãðóçèòüñÿ èãîëêà. (ðàññòîÿíèå îò öåíòðà ñòàòîðà)
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(OutFile, ';MaxDepth ', MaxDepth:0:5);
writeln(OutFile);
//Åñëè äîïóñòèìàÿ ãëóáèíà ìåíüøå, ÷åì äèàìåòð îñíîâàíèÿ, òîãäà äëèíà êàòóøêè ðàâíà äëèíå ëó÷à.
//Åñëè äîïóñòèìàÿ ãëóáèíà áîëüøå, ÷åì äèàìåòð + äëèíà ëó÷à, ïðåêðàùàåì äâèæ.
//Èíà÷å äëèíà êàòóøêè ðàâíà "ðàäèóñ_îñíîâàíèÿ + äëèíà_ëó÷à - ãëóáèíà)
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
//Èñõîäÿ èç äëèíû êàòóøêè ñ÷èòàåì êîëè÷åñòâî âèòêîâ. È ñêëàäûâàåì ñêîëüêî âñåãî âèòêîâ íà êàòóøêå.
CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
//Ïåðåä êàæäûì ñëîåì íóæíî ïåðåñ÷èòàòü êîîðäèíàòó Z
write(OutFile,';RecalculateZ. CurrentZ=',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);
writeln(OutFile,'; NewZ=',CurrentZ:0:5);
//Íà÷èíàåì ìîòàòü.
writeln(OutFile, ';We make ',CurrentCoilTurns, ' turns on ', LayerNumber, ' layer.' );
for j := 1 to CurrentCoilTurns do
begin
writeln(OutFile,';Coil¹ = ',j);
writeln(OutFile,'M117 ',j);
//angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
//Divide the path into 100 points
//Move from left-down to left-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := ((-1*angle)+2*(angle/100*k));
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Left Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Top Left Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Top Right Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
//Divide the path into 100 points
//Move from left-down to rt-up
for k := 1 to 100 do
begin
angle := AngleBetweenRays/2;
angle := (angle-(2*(angle/100*k)));
writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Right Corner
end;
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
// angle := CalculateAngle(-1*CoilWidth/2, CurrentZ);
// writeln(OutFile, 'G1 X', CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5); // Bottom Right Corner
// if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
// angle := CalculateAngle(CoilWidth/2, CurrentZ);
angle := AngleBetweenRays/2;
writeln(OutFile, 'G1 X', -1*CoilHeight/2:0:3, ' Y', -angle:0:5,' Z', NormalizeZ(CurrentZ, angle):0:5, ' ;CurrentZ= ',CurrentZ:0:5); // Bottom Left Corner
if MoveForward then CurrentZ:=CurrentZ+StatorParams.WireDiameter/4 else CurrentZ:=CurrentZ-StatorParams.WireDiameter/4;
//writeln(OutFile, 'M0');
end;
writeln(OutFile, 'M0');
// writeln(OutFile, 'G91');
// writeln(OutFile, 'G1 Y50');
// writeln(OutFile, 'G90');
Inc(LayerNumber);
CoilWidth:=CoilWidth+StatorParams.WireDiameter*2;
MoveForward:= not MoveForward;
writeln(OutFile,';MoveForward: ', MoveForward);
end;
(* writeln(OutFile);
writeln(OutFile, ';Second coil');
Inc(LayerNumber);
RequiredSpacing:=StatorParams.PathClearance*2+LayerNumber*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing = ',RequiredSpacing:0:5);
For i:=1 to 20 do
begin
LayerNumber:=i;
writeln(OutFile, ';Layer ', i);
RequiredSpacing:=StatorParams.PathClearance*2+(LayerNumber-1)*StatorParams.WireDiameter*2+StatorParams.NeedleDiameter;
writeln(OutFile, ';RequiredSpacing ', RequiredSpacing:0:5);
MaxDepth:=DepthCheck(StatorParams.RayWidth, RequiredSpacing, AngleBetweenRays);
writeln(OutFile, ';MaxDepth ', MaxDepth:0:5);
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(OutFile, ';CoilLength ', CoilLength:0:5);
// CurrentCoilTurns := round(CoilLength/StatorParams.WireDiameter);
// CurrentCoilTurns := ceil(CoilLength/StatorParams.WireDiameter);
CurrentCoilTurns := floor(CoilLength/StatorParams.WireDiameter);
writeln(OutFile, ';CurrentCoilTurns ', CurrentCoilTurns);
CoilTurnsSum := CoilTurnsSum+CurrentCoilTurns;
writeln(OutFile, ';CoilTurnsSum ', CoilTurnsSum);
writeln(OutFile);
end;*)
end;
// *** Your G-code generation logic here ***
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 * 86400), ' seconds.');
writeln('Press Enter... ');
Readln;
end.

View file

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="gcodegenerator_v4"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="gcodegenerator_v4.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="gcodegenerator_v4"/>
</Target>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View file

@ -1,36 +0,0 @@
# диаметр основания статора
base_dia=37,8
# количество лучей статора
num_rays=1
# форма луча статора (circle, rect, superellipse)
ray_shape=rect
# диаметр луча статора
# ray_dia=5,0
# ширина луча статора
ray_w=2,4
# высота луча статора
ray_h=5
# длина луча статора
ray_len=9,0
# форма вершины луча
raytop_shape=circle
# диаметр вершины луча
raytop_dia=8,9
# ширина вершины луча
raytop_w=5,6
# высота вершины луча
raytop_h=14,0
# смещение центра луча
ray_offset=14,7
# диаметр провода
wire_diameter=0,25
# диаметр иглы
needle_diameter=1,25
# зазор пути
path_clearance=0,2
# скорость намотки
work_speed=2000

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -gw3 -gl -l -vewnhibq -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\gcodegenerator.exe gcodegenerator.pas"/>
</CONFIG>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Compiler Value="C:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe" Date="1497193866"/>
<Params Value=" -MObjFPC -Scghi -O1 -gw3 -gl -l -vewnhibq -FuD:\Documents\GitHub\motor-wire-winder\gcode\Generator\ -FUD:\Documents\GitHub\motor-wire-winder\gcode\Generator\lib\x86_64-win64\ -FED:\Documents\GitHub\motor-wire-winder\gcode\Generator\ -oD:\Documents\GitHub\motor-wire-winder\gcode\Generator\gcodegenerator_v2.exe gcodegenerator_v2.pas"/>
</CONFIG>

Some files were not shown because too many files have changed in this diff Show more