From 8ca8eb7122661448a5f03eae364d4d663090ab9e Mon Sep 17 00:00:00 2001 From: Aik-Siong Koh Date: Fri, 28 Apr 2023 16:29:43 -0600 Subject: [PATCH] Second commit --- MbDCode/Array.h | 10 +++- MbDCode/CartesianFrame.h | 1 + MbDCode/EulerConstraint.h | 6 +-- MbDCode/FullColumn.cpp | 15 ++++++ MbDCode/FullColumn.h | 3 ++ MbDCode/MarkerFrame.cpp | 31 ++++++++++++ MbDCode/MarkerFrame.h | 30 ++++++++++- MbDCode/MbDCode.cpp | 90 ++++++++++++++++++++++++++++++--- MbDCode/MbDCode.vcxproj | 15 ++++++ MbDCode/MbDCode.vcxproj.filters | 39 ++++++++++++++ MbDCode/Part.cpp | 29 +++++++++++ MbDCode/Part.h | 20 ++++---- MbDCode/PartFrame.cpp | 39 +++++++++++--- MbDCode/PartFrame.h | 27 +++++----- MbDCode/System.cpp | 12 +++++ MbDCode/System.h | 8 ++- MbDCode/Vector.cpp | 4 ++ MbDCode/Vector.h | 1 + 18 files changed, 329 insertions(+), 51 deletions(-) diff --git a/MbDCode/Array.h b/MbDCode/Array.h index eb1f4fd..b0277b8 100644 --- a/MbDCode/Array.h +++ b/MbDCode/Array.h @@ -9,6 +9,14 @@ namespace MbD { Array(){} Array(int i) : std::vector(i) {} Array(std::initializer_list list) : std::vector{ list } {} - }; + void copy(Array* x); + }; + template + inline void Array::copy(Array* x) + { + for (int i = 0; i < x->size(); i++) { + this->at(i) = x->at(i); + } + } } diff --git a/MbDCode/CartesianFrame.h b/MbDCode/CartesianFrame.h index 98733d5..ef75b69 100644 --- a/MbDCode/CartesianFrame.h +++ b/MbDCode/CartesianFrame.h @@ -1,5 +1,6 @@ #pragma once #include "Item.h" + namespace MbD { class CartesianFrame : public Item diff --git a/MbDCode/EulerConstraint.h b/MbDCode/EulerConstraint.h index 5479e5b..04f65ab 100644 --- a/MbDCode/EulerConstraint.h +++ b/MbDCode/EulerConstraint.h @@ -6,17 +6,15 @@ #include "FullRow.h" namespace MbD { - using FullRowDPtr = std::shared_ptr>; class EulerConstraint : public Constraint { public: EulerConstraint() : Constraint() { - pGpE = std::make_shared>(4); } //pGpE iqE - FullRowDPtr pGpE; //partial derivative of G wrt pE - int iqE; + FullRow pGpE = FullRow(4); //partial derivative of G wrt pE + int iqE = -1; }; } diff --git a/MbDCode/FullColumn.cpp b/MbDCode/FullColumn.cpp index 36d7990..3a73cf2 100644 --- a/MbDCode/FullColumn.cpp +++ b/MbDCode/FullColumn.cpp @@ -1 +1,16 @@ +#include + #include "FullColumn.h" + +using namespace MbD; + +std::string FullColumn::toString() { + std::stringstream ss; + + ss << "FullColumn { "; + for (int i = 0; i < this->size() - 1; i++) { + ss << this->at(i) << ", "; + } + ss << this->back() << " }"; + return ss.str(); +} diff --git a/MbDCode/FullColumn.h b/MbDCode/FullColumn.h index 6b809b6..70c13e3 100644 --- a/MbDCode/FullColumn.h +++ b/MbDCode/FullColumn.h @@ -1,11 +1,14 @@ #pragma once #include "Vector.h" + namespace MbD { template class FullColumn : public Vector { public: + FullColumn(int i) : Vector(i) {} FullColumn(std::initializer_list list) : Vector{ list } {} + std::string toString(); }; } diff --git a/MbDCode/MarkerFrame.cpp b/MbDCode/MarkerFrame.cpp index 476f7c5..ed2b4c8 100644 --- a/MbDCode/MarkerFrame.cpp +++ b/MbDCode/MarkerFrame.cpp @@ -1 +1,32 @@ #include "MarkerFrame.h" + +using namespace MbD; + +MarkerFrame::MarkerFrame() +{ + partFrame = nullptr; + auto endFrm = std::make_shared(); + std::string str = "EndFrame1"; + endFrm->setName(str); + this->addEndFrame(endFrm); +} + +void MarkerFrame::setPartFrame(PartFrame* partFrm) +{ + partFrame = partFrm; +} + +void MarkerFrame::setrpmp(FullColumn* x) +{ + rpmp->copy(x); +} + +void MarkerFrame::setaApm(FullMatrix* x) +{ + aApm->copy(x); +} +void MarkerFrame::addEndFrame(std::shared_ptr endFrm) +{ + endFrm->setMarkerFrame(this); + endFrames.push_back(endFrm); +} diff --git a/MbDCode/MarkerFrame.h b/MbDCode/MarkerFrame.h index 0d87ffe..d351576 100644 --- a/MbDCode/MarkerFrame.h +++ b/MbDCode/MarkerFrame.h @@ -1,9 +1,35 @@ #pragma once +#include + #include "CartesianFrame.h" +#include "PartFrame.h" +#include "FullColumn.h" +#include "FullMatrix.h" +#include "EndFrameqc.h" + namespace MbD { - class MarkerFrame : - public CartesianFrame + class PartFrame; + class EndFrameqc; + + class MarkerFrame : public CartesianFrame { + //partFrame rpmp aApm rOmO aAOm prOmOpE pAOmpE pprOmOpEpE ppAOmpEpE endFrames + public: + MarkerFrame(); + void setPartFrame(PartFrame* partFrm); + void setrpmp(FullColumn* x); + void setaApm(FullMatrix* x); + void addEndFrame(std::shared_ptr x); + + PartFrame* partFrame; + FullColumn* rpmp = new FullColumn(3); + FullMatrix* aApm = new FullMatrix(3, 3); + FullColumn* rOmO = new FullColumn(3); + FullMatrix* aAOm = new FullMatrix(3, 3); + FullMatrix* prOmOpE = new FullMatrix(3, 4); + FullColumn>* pAOmpE = new FullColumn>(4); + std::vector> endFrames; + }; } diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index 23214b2..47534f3 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -1,17 +1,95 @@ #include -#include "Item.h" #include "System.h" +#include "FullColumn.h" +#include "FullMatrix.h" +#include "Part.h" +#include "MbDCode.h" using namespace MbD; int main() { std::cout << "Hello World!\n"; - auto& TheSystem = System::getInstance(); + System& TheSystem = System::getInstance(); std::string str = "TheSystem"; TheSystem.setName(str); - std::cout << TheSystem.getName(); - //auto fixedPart = std::make_shared(); - //str = "FixedPart"; - //fixedPart->setName(str); + std::cout << "TheSystem.getName() " << TheSystem.getName() << std::endl; + FullColumn* qX, * qE; + FullColumn* rpmp; + FullMatrix* aApm; + FullRow* fullRow; + auto row = new FullRow{ 0, 0, 0, 1 }; + fullRow = new FullRow(4); + fullRow->copy(row); + // + auto assembly1 = std::make_shared(); + str = "Assembly1"; + assembly1->setName(str); + std::cout << "assembly1->getName() " << assembly1->getName() << std::endl; + qX = new FullColumn{ 0, 0, 0 }; + qE = new FullColumn{ 0, 0, 0, 1 }; + assembly1->setqX(qX); + assembly1->setqE(qE); + std::cout << "assembly1->getqX() " << assembly1->getqX()->toString() << std::endl; + std::cout << "assembly1->getqE() " << assembly1->getqE()->toString() << std::endl; + TheSystem.addPart(assembly1); + { + auto marker1 = std::make_shared(); + str = "Marker1"; + marker1->setName(str); + rpmp = new FullColumn{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }; + marker1->setrpmp(rpmp); + aApm = new FullMatrix(); + fullRow = new FullRow{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }; + aApm->push_back(fullRow); + fullRow = new FullRow{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }; + aApm->push_back(fullRow); + fullRow = new FullRow{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }; + aApm->push_back(fullRow); + marker1->setaApm(aApm); + assembly1->partFrame->addMarkerFrame(marker1); + // + auto marker2 = std::make_shared(); + str = "Marker2"; + marker2->setName(str); + rpmp = new FullColumn{ 0.0, 0.0, 0.0 }; + marker2->setrpmp(rpmp); + aApm = new FullMatrix(); + fullRow = new FullRow{ 1.0, 0.0, 0.0 }; + aApm->push_back(fullRow); + fullRow = new FullRow{ 0.0, 1.0, 0.0 }; + aApm->push_back(fullRow); + fullRow = new FullRow{ 0.0, 0.0, 1.0 }; + aApm->push_back(fullRow); + marker2->setaApm(aApm); + assembly1->partFrame->addMarkerFrame(marker2); + } + // + auto part1 = std::make_shared(); + str = "Part1"; + part1->setName(str); + qX = new FullColumn{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }; + qE = new FullColumn{ 0.0, 0.0, 1.4248456266393e-10, 1.0 }; + part1->setqX(qX); + part1->setqE(qE); + TheSystem.parts.push_back(part1); + // + auto part2 = std::make_shared(); + str = "Part2"; + part2->setName(str); + qX = new FullColumn{ 0.38423366582893, 0.49215308269277, 0.048029210642807 }; + qE = new FullColumn{ 0.0, 0.0, 0.89871701272344, 0.4385290538168 }; + part2->setqX(qX); + part2->setqE(qE); + TheSystem.parts.push_back(part2); + // + auto part3 = std::make_shared(); + str = "Part3"; + part3->setName(str); + qX = new FullColumn{ -1.284772285311e-18, 1.4645982581368, -4.788228906425e-17 }; + qE = new FullColumn{ 0.70710678118655, 0.70710678118655, 0.0, 0.0 }; + part3->setqX(qX); + part3->setqE(qE); + TheSystem.parts.push_back(part3); + // } \ No newline at end of file diff --git a/MbDCode/MbDCode.vcxproj b/MbDCode/MbDCode.vcxproj index c1ce89f..65349fe 100644 --- a/MbDCode/MbDCode.vcxproj +++ b/MbDCode/MbDCode.vcxproj @@ -131,8 +131,13 @@ + + + + + @@ -141,27 +146,37 @@ + + + + + + + + + + diff --git a/MbDCode/MbDCode.vcxproj.filters b/MbDCode/MbDCode.vcxproj.filters index d6dc645..63e0800 100644 --- a/MbDCode/MbDCode.vcxproj.filters +++ b/MbDCode/MbDCode.vcxproj.filters @@ -66,6 +66,24 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -116,5 +134,26 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/MbDCode/Part.cpp b/MbDCode/Part.cpp index 9dbf298..c63f634 100644 --- a/MbDCode/Part.cpp +++ b/MbDCode/Part.cpp @@ -1 +1,30 @@ #include "Part.h" +#include "PartFrame.h" +#include "FullColumn.h" + +using namespace MbD; + +Part::Part() { + partFrame = std::make_shared(); +} + +void Part::setqX(FullColumn* x) { + partFrame.get()->setqX(x); +} + +FullColumn* Part::getqX() { + return partFrame.get()->getqX(); +} + +void Part::setqE(FullColumn* x) { + partFrame.get()->setqE(x); +} + +FullColumn* Part::getqE() { + return partFrame.get()->getqE(); +} + +void Part::setSystem(System& sys) +{ + //May be needed in the future +} diff --git a/MbDCode/Part.h b/MbDCode/Part.h index 1aa7347..6bc8327 100644 --- a/MbDCode/Part.h +++ b/MbDCode/Part.h @@ -2,26 +2,24 @@ #include #include "Item.h" +#include "System.h" #include "PartFrame.h" #include "FullColumn.h" - namespace MbD { + class System; class PartFrame; class Part : public Item { + //ToDo: ipX ipE m aJ partFrame pX pXdot pE pEdot mX mE mEdot pTpE ppTpEpE ppTpEpEdot public: - Part() { - partFrame = std::make_shared(); - } - void setqX(FullColumn* x) { - partFrame.get()->setqX(x); - } - FullColumn* getqX() { - return partFrame.get()->getqX(); - } - //ToDo: Needed members ipX ipE m aJ partFrame pX pXdot pE pEdot mX mE mEdot pTpE ppTpEpE ppTpEpEdot + Part(); + void setqX(FullColumn* x); + FullColumn* getqX(); + void setqE(FullColumn* x); + FullColumn* getqE(); + void setSystem(System& sys); std::shared_ptr partFrame; }; } diff --git a/MbDCode/PartFrame.cpp b/MbDCode/PartFrame.cpp index 3d043f1..d96501c 100644 --- a/MbDCode/PartFrame.cpp +++ b/MbDCode/PartFrame.cpp @@ -1,12 +1,37 @@ +#include "Part.h" #include "PartFrame.h" #include "AbsConstraint.h" #include "MarkerFrame.h" -namespace MbD { +using namespace MbD; - PartFrame::PartFrame() - { - aGabs = std::vector>(); - markerFrames = std::vector>(); - } -} \ No newline at end of file +PartFrame::PartFrame() +{ + aGeu = std::make_shared(); + aGabs = std::vector>(); + markerFrames = std::vector>(); +} +void PartFrame::setqX(FullColumn* x) { + qX->copy(x); +} +FullColumn* PartFrame::getqX() { + return qX; +} +void PartFrame::setqE(FullColumn* x) { + qE->copy(x); +} +FullColumn* PartFrame::getqE() { + return qE; +} +void PartFrame::setPart(std::shared_ptr x) { + part = x; +} +std::shared_ptr PartFrame::getPart() { + return part.lock(); +} + +void MbD::PartFrame::addMarkerFrame(std::shared_ptr markerFrame) +{ + markerFrame->setPartFrame(this); + markerFrames.push_back(markerFrame); +} diff --git a/MbDCode/PartFrame.h b/MbDCode/PartFrame.h index 481fd62..0c30ab4 100644 --- a/MbDCode/PartFrame.h +++ b/MbDCode/PartFrame.h @@ -15,25 +15,22 @@ namespace MbD { class PartFrame : public CartesianFrame { + //ToDo: part iqX iqE qX qE qXdot qEdot qXddot qEddot aGeu aGabs markerFrames public: PartFrame(); - void setqX(FullColumn* x) { - qX = x; - } - FullColumn* getqX() { - return qX; - } - void setPart(std::shared_ptr x) { - part = x; - } - std::shared_ptr getPart() { - return part.lock(); - } - //part iqX iqE qX qE qXdot qEdot qXddot qEddot aGeu aGabs markerFrames + + void setqX(FullColumn* x); + FullColumn* getqX(); + void setqE(FullColumn* x); + FullColumn* getqE(); + void setPart(std::shared_ptr x); + std::shared_ptr getPart(); + void addMarkerFrame(std::shared_ptr x); + std::weak_ptr part; int iqX, iqE; //Position index of frame variables qX and qE in system list of variables - FullColumn* qX; - FullColumn* qE; + FullColumn* qX = new FullColumn(3); + FullColumn* qE = new FullColumn(4); std::shared_ptr aGeu; std::vector> aGabs; std::vector> markerFrames; diff --git a/MbDCode/System.cpp b/MbDCode/System.cpp index 183b648..67d096b 100644 --- a/MbDCode/System.cpp +++ b/MbDCode/System.cpp @@ -1 +1,13 @@ #include "System.h" + +void MbD::System::addPart(std::shared_ptr part) +{ + part->setSystem(*this); + parts.push_back(part); +} + +MbD::System::System() { + parts = std::vector>(); + jointsMotions = std::vector>(); + systemSolver = std::make_shared(*this); +} diff --git a/MbDCode/System.h b/MbDCode/System.h index 872ad42..cbc3cca 100644 --- a/MbDCode/System.h +++ b/MbDCode/System.h @@ -8,6 +8,7 @@ #include "SystemSolver.h" namespace MbD { + class Part; class SystemSolver; class System : public Item { @@ -22,12 +23,9 @@ namespace MbD { std::vector> jointsMotions; bool hasChanged = false; std::shared_ptr systemSolver; + void addPart(std::shared_ptr part); private: - System() { - parts = std::vector>(); - jointsMotions = std::vector>(); - systemSolver = std::make_shared(*this); - } + System(); //System() = default; // Private constructor System(const System&) = delete; System& operator=(const System&) = delete; // Deleted copy assignment diff --git a/MbDCode/Vector.cpp b/MbDCode/Vector.cpp index 1a0d306..356c3b4 100644 --- a/MbDCode/Vector.cpp +++ b/MbDCode/Vector.cpp @@ -1 +1,5 @@ #include "Vector.h" + +using namespace MbD; + + diff --git a/MbDCode/Vector.h b/MbDCode/Vector.h index 100516c..302ca66 100644 --- a/MbDCode/Vector.h +++ b/MbDCode/Vector.h @@ -1,5 +1,6 @@ #pragma once #include "Array.h" + namespace MbD { template class Vector : public Array