re-init
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Hi.Milling.Apts;
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Geom;
|
||||
using Hi.Machining;
|
||||
using Hi.Mech.Topo;
|
||||
using Hi.Milling.Cutters;
|
||||
using Hi.Milling.FluteContours;
|
||||
using Hi.MillingForces.Fittings;
|
||||
using Hi.MillingMech.MillingTools;
|
||||
using Hi.NcMech.Fixtures;
|
||||
using Hi.NcMech.Holders;
|
||||
using Hi.NcMech.Workpieces;
|
||||
using Hi.NcMech.Xyzabc;
|
||||
using Hi.NcOpt;
|
||||
using Hi.Physics;
|
||||
using Hi.MongoUtils;
|
||||
using Hi.Licenses;
|
||||
using Hi.MachiningProcs;
|
||||
using System.IO;
|
||||
|
||||
namespace Sample.Machining
|
||||
{
|
||||
public static class DemoBuildMachiningProject
|
||||
{
|
||||
#region CreateMillingCutter1
|
||||
private static MillingCutter CreateMillingCutter1()
|
||||
{
|
||||
MillingCutter millingCutter = new MillingCutter()
|
||||
{
|
||||
UpperBeamGeom = new TransformationGeom(),
|
||||
MillingCutterOptLimit = new MillingCutterOptLimit()
|
||||
};
|
||||
// since the following properties of MillingCutter has self-invoke,
|
||||
// they have to be seperated from the initializer syntex.
|
||||
|
||||
//build ShaperProfile property
|
||||
double diameter_mm = 12;
|
||||
double roundRadius_mm = 0.5;
|
||||
millingCutter.ShaperProfile = new AptProfile(millingCutter,
|
||||
new ColumnApt()
|
||||
{
|
||||
Diameter_mm = diameter_mm,
|
||||
Rc_mm = roundRadius_mm,
|
||||
FluteHeight_mm = 40
|
||||
});
|
||||
|
||||
//build FluteContourTray property
|
||||
double helixAngle_deg = 50;
|
||||
double radialRakeAngle_deg = 15;
|
||||
double bottomOuterRadius_mm = diameter_mm / 2 - roundRadius_mm;
|
||||
millingCutter.FluteContourTray = new UniformContourTray()
|
||||
{
|
||||
TrackNum = 3,
|
||||
BaselineOneContour = new FluteContour()
|
||||
{
|
||||
BaseSideContour = new ConstHelixSideContour(millingCutter)
|
||||
{
|
||||
Helix_deg = helixAngle_deg,
|
||||
RadialRakeAngle_deg = radialRakeAngle_deg
|
||||
},
|
||||
BaseBottomContour = new SlideBottomContour()
|
||||
{
|
||||
//In most case, helix angle from side equal to rake angle from bottom.
|
||||
AxialRakeAngle_deg = MathUtil.ToDeg(helixAngle_deg),
|
||||
DiskAngle_deg = 1.5,
|
||||
//In most case, rake angle from side equal to eccentric angle from bottom.
|
||||
EccentricAngle_deg = radialRakeAngle_deg,
|
||||
CutterLengthOnBottomProjection_mm = bottomOuterRadius_mm * 0.9,
|
||||
OuterRadius_mm = bottomOuterRadius_mm
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
millingCutter.InnerBeamProfile
|
||||
= new FluteDependentRatioProfile(millingCutter);
|
||||
|
||||
return millingCutter;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateMillingCutter2
|
||||
private static MillingCutter CreateMillingCutter2()
|
||||
{
|
||||
MillingCutter millingCutter = new MillingCutter()
|
||||
{
|
||||
UpperBeamGeom = new TransformationGeom(),
|
||||
MillingCutterOptLimit = new MillingCutterOptLimit()
|
||||
};
|
||||
|
||||
//build ShaperProfile property
|
||||
double diameter_mm = 12;
|
||||
millingCutter.ShaperProfile = new AptProfile(millingCutter,
|
||||
new ColumnApt()
|
||||
{
|
||||
Diameter_mm = diameter_mm,
|
||||
FluteHeight_mm = 40
|
||||
});
|
||||
|
||||
//build FluteContourTray property
|
||||
double helixAngle_deg = 50;
|
||||
double radialRakeAngle_deg = 15;
|
||||
millingCutter.FluteContourTray = new UniformContourTray()
|
||||
{
|
||||
TrackNum = 3,
|
||||
BaselineOneContour = new FluteContour()
|
||||
{
|
||||
BaseSideContour = new ConstHelixSideContour(millingCutter)
|
||||
{
|
||||
Helix_deg = helixAngle_deg,
|
||||
RadialRakeAngle_deg = radialRakeAngle_deg
|
||||
},
|
||||
//since no bottom cut, set bottom contour to null.
|
||||
BaseBottomContour = null
|
||||
}
|
||||
};
|
||||
|
||||
millingCutter.InnerBeamProfile
|
||||
= new FluteDependentRatioProfile(millingCutter);
|
||||
|
||||
return millingCutter;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMethod
|
||||
[STAThread]
|
||||
public static void Test()
|
||||
{
|
||||
Console.WriteLine($"License Login.");
|
||||
License.LogInAll();
|
||||
|
||||
Console.WriteLine($"Start Database.");
|
||||
MongoServer.Default = MongoServer.Run(new MongoRunnerOptions()
|
||||
{
|
||||
MongoPort = 28100
|
||||
});
|
||||
|
||||
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
|
||||
var projectDirectory = Path.GetDirectoryName(projectPath);
|
||||
Console.WriteLine($"Directory of the New Project: {projectDirectory}");
|
||||
MachiningProject machiningProject = new MachiningProject(projectDirectory);
|
||||
|
||||
#region ConfigureHolder
|
||||
CylindroidHolder cylindroidHolder = new CylindroidHolder()
|
||||
{
|
||||
Note = "BT40",
|
||||
Cylindroid = new Cylindroid()
|
||||
{
|
||||
PairZrs = new List<PairZr>([ new PairZr(0,12),new PairZr(20,12),
|
||||
new PairZr(20,16),new PairZr(30,16)]),
|
||||
LongitudeNum = 30
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureMachiningToolHouse
|
||||
machiningProject.MachiningToolHouse = new MachiningToolHouse()
|
||||
{
|
||||
[1] = new StickMachiningTool()
|
||||
{
|
||||
Note = "T1",
|
||||
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
|
||||
Holder = cylindroidHolder,
|
||||
Cutter = CreateMillingCutter1()
|
||||
},
|
||||
[2] = new StickMachiningTool()
|
||||
{
|
||||
Note = "T2",
|
||||
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
|
||||
Holder = cylindroidHolder,
|
||||
Cutter = CreateMillingCutter2()
|
||||
},
|
||||
[3] = new StickMachiningTool()
|
||||
{
|
||||
Note = "T3",
|
||||
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
|
||||
Holder = cylindroidHolder,
|
||||
Cutter = CreateMillingCutter1()
|
||||
},
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureFixture
|
||||
machiningProject.MachiningEquipment.Fixture = new Fixture()
|
||||
{
|
||||
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
|
||||
TableToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureWorkpiece
|
||||
machiningProject.MachiningEquipment.Workpiece = new Workpiece()
|
||||
{
|
||||
InitResolution = 0.25,
|
||||
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
|
||||
IdealGeom = null,
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
MillingPara = XFactory.Default.GenByFile<ICuttingPara>(
|
||||
"Resource/CuttingParameter", "Al6061T6.mp", GenMode.Default),
|
||||
WorkpieceMaterial = XFactory.Default.GenByFile<WorkpieceMaterial>(
|
||||
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", GenMode.Default),
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureMachineChain
|
||||
machiningProject.MachiningEquipment.SolidMachiningChain
|
||||
= XFactory.Default.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource/MachineTool", "PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
#endregion
|
||||
|
||||
machiningProject.MakeXmlSourceFile(projectPath);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using Hi.Licenses;
|
||||
using Hi.Common.Messages;
|
||||
using Hi.MachiningProcs;
|
||||
using Hi.Common.FileLines;
|
||||
using Hi.MongoUtils;
|
||||
|
||||
namespace Sample.Machining
|
||||
{
|
||||
public static class DemoUseMachiningProject
|
||||
{
|
||||
#region LoadProjectFileAndRunNcFiles
|
||||
static void LoadProjectFileAndRunNcFiles()
|
||||
{
|
||||
#region LicenseAndDatabaseSetup
|
||||
Console.WriteLine($"License Login.");
|
||||
License.LogInAll();
|
||||
|
||||
Console.WriteLine($"Start Database.");
|
||||
MongoServer.Default = MongoServer.Run(new MongoRunnerOptions()
|
||||
{
|
||||
MongoPort = 28100
|
||||
});
|
||||
#endregion
|
||||
|
||||
#region ProjectLoading
|
||||
var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
||||
Console.WriteLine($"Load Project: {projectPath}");
|
||||
MachiningProject machiningProject = MachiningProject.LoadFile(projectPath);
|
||||
#endregion
|
||||
|
||||
#region EventHandling
|
||||
Console.WriteLine($"Set message event.");
|
||||
//show message if something abnormal.
|
||||
machiningProject.SessionMessageHost.CollectionItemAdded += pack =>
|
||||
{
|
||||
if (pack.Tags.Contains(MessageFlag.Warning.ToString()) ||
|
||||
pack.Tags.Contains(MessageFlag.Error.ToString()) ||
|
||||
pack.Tags.Contains(MessageFlag.SysErr.ToString()))
|
||||
{
|
||||
var sourceCommand = pack.SourceCommand;
|
||||
Console.WriteLine($"{pack.Message} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
||||
}
|
||||
};
|
||||
Console.WriteLine($"Set machining step event.");
|
||||
//show MRR.
|
||||
machiningProject.ShellApi.MachiningStepBuilt += (preStep, curStep) =>
|
||||
{
|
||||
var sourceCommand = curStep.SourceCommand;
|
||||
if (curStep.Mrr_mm3ds > 500) //show only the step that contains large MRR.
|
||||
Console.WriteLine($"MRR = {curStep.Mrr_mm3ds} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region MachiningExecution
|
||||
Console.WriteLine($"Reset runtime status.");
|
||||
machiningProject.ResetRuntime();
|
||||
|
||||
Console.WriteLine($"Session begin.");
|
||||
machiningProject.BeginSession();
|
||||
machiningProject.ShellApi.MachiningResolution_mm = 1;
|
||||
machiningProject.ShellApi.EnableCollisionDetection = true;
|
||||
machiningProject.ShellApi.EnablePauseOnCollision = false;
|
||||
machiningProject.ShellApi.EnableMillingForceEvaluation = false;
|
||||
//the path from Shell-API is relative by project directory.
|
||||
machiningProject.ShellApi.PlayNcFile("NC/side.ptp");
|
||||
machiningProject.ShellApi.PlayNcFile("NC/circle.ptp");
|
||||
machiningProject.EndSession();
|
||||
Console.WriteLine($"Session end.");
|
||||
#endregion
|
||||
|
||||
#region CleanupResources
|
||||
Console.WriteLine($"Close Project: {projectPath}");
|
||||
machiningProject.Dispose();
|
||||
|
||||
Console.WriteLine($"Close Database.");
|
||||
MongoServer.Default.Dispose();
|
||||
|
||||
Console.WriteLine($"License Logout.");
|
||||
License.LogOutAll();
|
||||
|
||||
Console.WriteLine($"Program end.");
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Main
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
LoadProjectFileAndRunNcFiles();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user