Skip to content

Commit

Permalink
Rapid Feed mismatch at WS 10 of hardmoldy
Browse files Browse the repository at this point in the history
  • Loading branch information
salamb committed Jan 19, 2016
1 parent 928725b commit f0f6384
Show file tree
Hide file tree
Showing 12 changed files with 923,625 additions and 54,645 deletions.
977,963 changes: 923,349 additions & 54,614 deletions DATA.txt

Large diffs are not rendered by default.

185 changes: 174 additions & 11 deletions Patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ WP^ Patcher::getAllExec(__int64 root,STEPNCLib::Finder ^find,WP^plan,__int64 ind
else if (find->IsWorkingstep(nestedPlans[i])&&find->IsEnabled(nestedPlans[i])){
name=find->GetExecutableName(nestedPlans[i]);
toolID=find->GetWorkingstepTool(nestedPlans[i]);
bool ret;
toolID = find->GetToolNumberAsNumber(toolID, ret);
mainWS=gcnew WS(name,nestedPlans[i],i,mainWP,toolID);
mainWP->addExecutable(mainWS);
//need to add all toolpaths
Expand Down Expand Up @@ -625,7 +627,7 @@ void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileNa

samples->changeSourceTxt(coor);
samples->parse();

samples->convertMMToInches();
root=getAllExec(oldWPID,find,nullptr,0);

/////init
Expand All @@ -637,24 +639,54 @@ void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileNa
apt->NestWorkplanAfter("Workplan for MTConnect results", find->GetWorkplanExecutableCount(wp_id) + 1, wp_id);
// get the first path
ToolPath^ firstPath=root->firstPath();
//init apt with first WS befor loop

List<WP^>^ path = firstPath->getWS()->pathtoRoot();
path->Reverse();
for (int i = 0; i < path->Count; i++) {
apt->NestWorkplan(path[i]->getName());
path[i]->setCopyID(apt->GetCurrentWorkplan());

}
generateWSForToolPath(apt, find, firstPath->getWS(), nullptr);
double feed = 0;
array<double>^ coor1;
array<double>^coor2;

for (int i = 0; i > samples->getSize()-1; i++) {
ToolPath^ currentTP = firstPath;
bool firstRapid = true;
for (int i = 0; i < samples->getSize()-1; i++) {
coor1 = samples->getCoor(i);
coor2 = samples->getCoor(i + 1);
feed = samples->actualFeedRate(i,i+1);

if (.6 < feed ) {
if (firstRapid == true) {
currentTP = patchRapidToolPaths(apt, find, currentTP);
firstRapid = false;
}

}
else {
firstRapid = true;
apt->GoToXYZ("feed", coor2[0], coor2[1], coor2[2]);
}



if (currentTP == nullptr) { break; }
}

apt->SaveAsModules("patchedWithWS");

}
//wpid of extension WP
//not of the copied WP

void Patcher::generateWSForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, WS^ ws ,ToolPath^tp) {
apt->Workingstep(ws->getName());
apt->LoadTool(ws->getToolId());
ws->setCopyID(apt->GetCurrentWorkingstep());
apt->Rapid();
Console::WriteLine(" created mirror WS {0} ", ws->getName());
}

void Patcher::generateWPForToolPath(STEPNCLib::AptStepMaker^ apt,STEPNCLib::Finder^ find,ToolPath^newtool,ToolPath^old) {
WS^ desiredWS = newtool->getWS();
List<WP^> ^path = desiredWS->pathtoRoot();
Expand All @@ -677,27 +709,158 @@ void Patcher::generateWPForToolPath(STEPNCLib::AptStepMaker^ apt,STEPNCLib::Find

}
if (branchAfter != nullptr) {
countAbove= branchAfter->distanceAbove(path[path->Count - 1]);
countAbove = oldPath->Count - (positionInPath + 1);
for (int i = 0; i < countAbove; i++) {
apt->EndWorkplan();

}
}
else {
branchAfter = old->getWS()->getParent;

//there is no wp change
if (max1 == max2) {
return;
}
branchAfter = old->getWS()->getParent();
positionInPath = oldPath->Count - 1;
}
for (int i = positionInPath + 1; i < max1; i++) {
apt->NestWorkplan(path[positionInPath]->getName());
path[positionInPath]->setCopyID(apt->GetCurrentWorkplan());
apt->NestWorkplan(path[i]->getName());
path[i]->setCopyID(apt->GetCurrentWorkplan());
}

}
void Patcher::rapidToPoints(STEPNCLib::AptStepMaker^apt,STEPNCLib::Finder ^ find, List<__int64>^STPNCpath) {
List<double>^ coor = getAllPoints(STPNCpath, find);
int totalPts = coor->Count / 3;
apt->Rapid();
for (int i = 0; i<totalPts; i++) {
apt->GoToXYZ("rapid", coor[i * 3], coor[i * 3 + 1], coor[i * 3 + 2]);

}

}
bool transitionToFeed(ToolPath ^tp1, ToolPath ^tp2) {
if (tp1!=nullptr&&tp2!=nullptr&&tp1->rapid()&&tp2->rapid()) {
return false;
}
else { return true; }

}
ToolPath^ Patcher::patchRapidToolPaths(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^tp) {
bool wp, ws;
ToolPath ^tp1 = tp;
ToolPath ^tp2 = nullptr;
List<__int64> ^STPNCpath = gcnew List<__int64>();
while (!tp1->rapid()) {
tp1=tp1->nextPath(wp, ws);
}
while (tp1->rapid())
{
STPNCpath->Add(tp1->getId());
rapidToPoints(apt, find, STPNCpath);
STPNCpath->Clear();
ws = false;
wp = false;
tp2= tp1->nextPath(wp, ws);
if (tp2 == nullptr) { return nullptr; }
if (ws || wp) {

//rapidToPoints(apt, find, STPNCpath);
//STPNCpath->Clear();
if (wp) {
generateWPForToolPath(apt, find, tp2, tp1);

}
generateWSForToolPath(apt, find, tp2->getWS(), nullptr);

}
tp1 = tp2;
}

apt->Feedrate(tp1->getWS()->getMaxFeed());
apt->SpindleSpeed(tp1->getWS()->getMaxSpindle());
return tp1;
}
/*
ToolPath^ Patcher::patchRapidToolPaths(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^tp) {
bool prevRapid = false;
bool currentRapid = false;
bool first = true;
ToolPath ^WStransisiton = nullptr;
List<__int64> ^STPNCpath = gcnew List<__int64>();
bool wp = false;
bool ws = false;
while (!(prevRapid==true&&currentRapid==false)||first) {
if (first) {
first = false;
prevRapid = tp->rapid();
if (prevRapid == true) { STPNCpath->Add(tp->getId());
rapidToPoints(apt, find, STPNCpath);
STPNCpath->Clear();
}
}
else {
prevRapid = currentRapid;
}
ws = false;
wp = false;
WStransisiton = tp->nextPath(wp, ws);
if (WStransisiton == nullptr) {
break;
}
if (ws || wp) {
//rapidToPoints(apt, find, STPNCpath);
//STPNCpath->Clear();
if (wp) {
generateWPForToolPath(apt, find, WStransisiton, tp);
}
generateWSForToolPath(apt, find, tp->getWS(), WStransisiton);
}
currentRapid = WStransisiton->rapid();
if (currentRapid == true) {
STPNCpath->Add(WStransisiton->getId());
rapidToPoints(apt, find, STPNCpath);
STPNCpath->Clear();
}
tp = WStransisiton;
}
apt->Feedrate(tp->getWS()->getMaxFeed());
apt->SpindleSpeed(tp->getWS()->getMaxSpindle());
return tp;
}
*/


double Patcher::actualFeedRate(array<double>^ coor1, array<double>^ coor2) {


double dx = coor1[0] - coor2[0];
double dy = coor1[1] - coor2[1];
double dz = coor1[2] - coor2[2];

double dist = Math::Sqrt(Math::Pow(dx, 2) + Math::Pow(dy, 2) + Math::Pow(dz, 2)) / coor2[3];

//Console::WriteLine("dx {0} dy{1} dz {2} deltat {3} speed{4}",dx,dy,dz,coor2[3],dist);

return dist;

}
5 changes: 4 additions & 1 deletion Patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ref class Patcher{
void createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor);
//ToolPath^ firstPath(__int64 root);
void DeleteBefore(__int64 wpid, STEPNCLib::Finder ^find, STEPNCLib::AptStepMaker^apt);
void generateWPForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^newtool, ToolPath^old)
void generateWPForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^newtool, ToolPath^old);
void generateWSForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, WS^, ToolPath^tp);
ToolPath^ patchRapidToolPaths(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^tp);
void rapidToPoints(STEPNCLib::AptStepMaker^apt, STEPNCLib::Finder ^ find, List<__int64>^STPNCpath);
};
#endif
24 changes: 21 additions & 3 deletions RawData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool RawData::changeSourceTxt(String^ file) {
Console::WriteLine(e);
return false;
}
type = TXTFILE->Clone;
type = TXTFILE;

}
bool RawData::parse() {
Expand All @@ -22,26 +22,38 @@ bool RawData::parse() {
}
}

void RawData::convertMMToInches() {
array<double> ^coor = nullptr;
for (int i = 0; i < getSize(); i++) {
coor = getCoor(i);
coor[0] = coor[0] / 25.4;
coor[1] = coor[1] / 25.4;
coor[2] = coor[2] / 25.4;

}


}
bool RawData::parseTxt() {
String ^data = nullptr;
array<String^>^ values;
array<double>^ coorWithTimeDiff;
while (!read->EndOfStream) {
data = read->ReadLine();
if (!data->Contains("#") && data->Contains("UNAVAILABLE")) {
if (!data->Contains("#")&& !data->Contains("UNAVAILABLE")) {
values = data->Split();
coorWithTimeDiff = gcnew array<double>(4);
coorWithTimeDiff[0]= Convert::ToDouble(values[0]);
coorWithTimeDiff[1] = Convert::ToDouble(values[1]);
coorWithTimeDiff[2] = Convert::ToDouble(values[2]);
coorWithTimeDiff[3] = Convert::ToDouble(values[3]);
coor->Add(coorWithTimeDiff);
}

}



return true;
}

__int64 RawData::getSize() {
Expand Down Expand Up @@ -71,5 +83,11 @@ array<double>^ RawData::getCoor(__int64 i) {

return dist;
}
RawData::RawData() {
read = nullptr;
sourceFile = nullptr;
coor = gcnew List<array<double>^>();

}


8 changes: 3 additions & 5 deletions RawData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ref class RawData {
const String^ TXTFILE = "TXT";
String^ sourceFile;
StreamReader ^read ;
String^type;
const String^type;
List<array<double>^>^ coor;
public:

Expand All @@ -22,15 +22,13 @@ ref class RawData {
//bool changeSourceMTConnect(String^ request);

bool parse();
RawData() { read = nullptr;
sourceFile = nullptr;
}
RawData();
__int64 getSize();
bool RawData::parseTxt();

array<double>^getCoor(__int64 i);

double actualFeedRate(__int64, __int64);


void convertMMToInches();
};
20 changes: 18 additions & 2 deletions ToolPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ ToolPath^ ToolPath::nextPath(bool % newWP, bool% newWS) {
return temp;
}
else {
newWP = true;
newWS = true;
WS^ tempWS = getWS();
ToolPath^ nextToolPath = nullptr;
List<WP^>^path = getWS()->pathtoRoot();
for (int i = 0; i<path->Count; i++) {
nextToolPath = recurseToNextToolPath(path[i], tempWS->getIndex());
if (i == 0) {
nextToolPath = recurseToNextToolPath(path[i], tempWS->getIndex());
}
else {
nextToolPath = recurseToNextToolPath(path[i], path[i-1]->getIndex());


}

if (nextToolPath != nullptr) {
return nextToolPath;
}
Expand All @@ -57,6 +67,8 @@ ToolPath^ ToolPath::recurseToNextToolPath(WP^ current, __int64 startIndexAfter)
}
}

Console::WriteLine("could notge next path ");
return nullptr;

}
ToolPath^ ToolPath::recurseToolPath(Exec^ current) {
Expand Down Expand Up @@ -89,4 +101,8 @@ ToolPath^ ToolPath::recurseToolPath(Exec^ current) {
}

__int64 ToolPath::getCopyID() { return copyID; }
bool ToolPath::copyCreated() { if (copyID == -1) { return false; } else { return true; } }
bool ToolPath::copyCreated() { if (copyID == -1) { return false; } else { return true; } }

double ToolPath::getFeed() { return feedrate; }
bool ToolPath::rapid() { return isRapid; }
double ToolPath::getSpindle() { return spindleSpeed; }
Loading

0 comments on commit f0f6384

Please sign in to comment.