diff --git a/.gitignore b/.gitignore index fdeeb7b..774534a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ *.app .vs -x64/ \ No newline at end of file +x64/ +*.bak \ No newline at end of file diff --git a/MbDCode/AbsConstraint.cpp b/MbDCode/AbsConstraint.cpp index adb9408..030db5f 100644 --- a/MbDCode/AbsConstraint.cpp +++ b/MbDCode/AbsConstraint.cpp @@ -12,6 +12,11 @@ AbsConstraint::AbsConstraint(const char* str) : Constraint(str) initialize(); } +MbD::AbsConstraint::AbsConstraint(int i) +{ + axis = i; +} + void AbsConstraint::initialize() { axis = 0; diff --git a/MbDCode/AbsConstraint.h b/MbDCode/AbsConstraint.h index 001f811..29551c7 100644 --- a/MbDCode/AbsConstraint.h +++ b/MbDCode/AbsConstraint.h @@ -7,6 +7,7 @@ namespace MbD { public: AbsConstraint(); AbsConstraint(const char* str); + AbsConstraint(int axis); void initialize(); int axis; int iqXminusOnePlusAxis; diff --git a/MbDCode/Array.h b/MbDCode/Array.h index 86dcb35..c0b8ce2 100644 --- a/MbDCode/Array.h +++ b/MbDCode/Array.h @@ -12,6 +12,7 @@ namespace MbD { Array(size_t count, const T& value) : std::vector(count, value) {} Array(std::initializer_list list) : std::vector{ list } {} void copy(std::shared_ptr> x); + void zeroSelf(); }; template inline void Array::copy(std::shared_ptr> x) @@ -20,5 +21,14 @@ namespace MbD { this->at(i) = x->at(i); } } + template <> + inline void Array::zeroSelf() { + for (int i = 0; i < this->size(); i++) { + this->at(i) = 0.0;; + } + } + using ListD = std::initializer_list; + using ListListD = std::initializer_list>; + using ListListPairD = std::initializer_list>>; } diff --git a/MbDCode/BasicUserFunction.cpp b/MbDCode/BasicUserFunction.cpp new file mode 100644 index 0000000..febfc13 --- /dev/null +++ b/MbDCode/BasicUserFunction.cpp @@ -0,0 +1 @@ +#include "BasicUserFunction.h" diff --git a/MbDCode/BasicUserFunction.h b/MbDCode/BasicUserFunction.h new file mode 100644 index 0000000..17c4b7b --- /dev/null +++ b/MbDCode/BasicUserFunction.h @@ -0,0 +1,15 @@ +#pragma once +#include + +#include "UserFunction.h" + +namespace MbD { + class BasicUserFunction : public UserFunction + { + //funcText myUnit units + public: + std::string funcText; + double myUnit; + }; +} + diff --git a/MbDCode/Constant.cpp b/MbDCode/Constant.cpp new file mode 100644 index 0000000..8f7cbc5 --- /dev/null +++ b/MbDCode/Constant.cpp @@ -0,0 +1,16 @@ +#include "Constant.h" + +using namespace MbD; + +Constant::Constant() +{ +} + +Constant::Constant(double val) : Variable(val) +{ +} + +std::shared_ptr MbD::Constant::differentiateWRT(std::shared_ptr var) +{ + return std::make_shared(0.0); +} diff --git a/MbDCode/Constant.h b/MbDCode/Constant.h new file mode 100644 index 0000000..5ac5a89 --- /dev/null +++ b/MbDCode/Constant.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Variable.h" + +namespace MbD { + class Constant : public Variable + { + public: + Constant(); + Constant(double val); + std::shared_ptr differentiateWRT(std::shared_ptr var) override; + }; +} + diff --git a/MbDCode/Constraint.h b/MbDCode/Constraint.h index 71b89f2..eef8945 100644 --- a/MbDCode/Constraint.h +++ b/MbDCode/Constraint.h @@ -15,9 +15,9 @@ namespace MbD { Item* getOwner(); int iG; - double aG; //Constraint function - double lam; //Lambda is Lagrange Multiplier - Item* owner; //A Joint or PartFrame owns the constraint + double aG; //Constraint function + double lam; //Lambda is Lagrange Multiplier + Item* owner; //A Joint or PartFrame owns the constraint }; } diff --git a/MbDCode/ConstraintIJ.cpp b/MbDCode/ConstraintIJ.cpp new file mode 100644 index 0000000..e065d91 --- /dev/null +++ b/MbDCode/ConstraintIJ.cpp @@ -0,0 +1,9 @@ +#include "ConstraintIJ.h" +#include "EndFramec.h" + +using namespace MbD; + +MbD::ConstraintIJ::ConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj) : frmI(frmi), frmJ(frmj) +{ + aConstant = 0.0; +} diff --git a/MbDCode/ConstraintIJ.h b/MbDCode/ConstraintIJ.h new file mode 100644 index 0000000..12ffeff --- /dev/null +++ b/MbDCode/ConstraintIJ.h @@ -0,0 +1,18 @@ +#pragma once + +//#include "typedef.h" +#include "Constraint.h" +#include "EndFramec.h" + +namespace MbD { + class ConstraintIJ : public Constraint + { + //frmI frmJ aConstant + public: + ConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj); + + EndFrmcptr frmI, frmJ; + double aConstant; + }; +} + diff --git a/MbDCode/DirectionCosineConstraintIJ.cpp b/MbDCode/DirectionCosineConstraintIJ.cpp new file mode 100644 index 0000000..bb544bb --- /dev/null +++ b/MbDCode/DirectionCosineConstraintIJ.cpp @@ -0,0 +1,10 @@ +#include "DirectionCosineConstraintIJ.h" +#include "EndFramec.h" + +using namespace MbD; + +DirectionCosineConstraintIJ::DirectionCosineConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj, int axisi, int axisj) : + ConstraintIJ(frmI, frmJ), axisI(axisi), axisJ(axisj) +{ + aAijIeJe = std::make_shared(frmI, frmJ, axisI, axisJ); +} diff --git a/MbDCode/DirectionCosineConstraintIJ.h b/MbDCode/DirectionCosineConstraintIJ.h new file mode 100644 index 0000000..0a0f330 --- /dev/null +++ b/MbDCode/DirectionCosineConstraintIJ.h @@ -0,0 +1,18 @@ +#pragma once + +#include "ConstraintIJ.h" +#include "DirectionCosineIecJec.h" + +namespace MbD { + class DirectionCosineConstraintIJ : public ConstraintIJ + { + //axisI axisJ aAijIeJe + public: + // self owns : (MbDDirectionCosineConstraintIJ withFrmI : frmI frmJ : frmJ axisI : 2 axisJ : 1). + DirectionCosineConstraintIJ(EndFrmcptr frmI, EndFrmcptr frmJ, int axisI, int axisJ); + + int axisI, axisJ; + std::shared_ptr aAijIeJe; + }; +} + diff --git a/MbDCode/DirectionCosineIecJec.cpp b/MbDCode/DirectionCosineIecJec.cpp new file mode 100644 index 0000000..b84a0c6 --- /dev/null +++ b/MbDCode/DirectionCosineIecJec.cpp @@ -0,0 +1,18 @@ +#include + +#include "DirectionCosineIecJec.h" +#include "FullColumn.h" + +using namespace MbD; + +MbD::DirectionCosineIecJec::DirectionCosineIecJec() +{ +} + +MbD::DirectionCosineIecJec::DirectionCosineIecJec(EndFrmcptr frmi, EndFrmcptr frmj, int axisi, int axisj) : + KinematicIeJe(frmi, frmj), axisI(axisi), axisJ(axisj) +{ + aAijIeJe = 0.0; + aAjOIe = std::make_shared>(3); + aAjOJe = std::make_shared>(3); +} diff --git a/MbDCode/DirectionCosineIecJec.h b/MbDCode/DirectionCosineIecJec.h new file mode 100644 index 0000000..d76a874 --- /dev/null +++ b/MbDCode/DirectionCosineIecJec.h @@ -0,0 +1,21 @@ +#pragma once +#include + +#include "KinematicIeJe.h" +//#include "EndFramec.h" +#include "FullColumn.h" + +namespace MbD { + class DirectionCosineIecJec : public KinematicIeJe + { + //aAijIeJe axisI axisJ aAjOIe aAjOJe + public: + DirectionCosineIecJec(); + DirectionCosineIecJec(EndFrmcptr frmI, EndFrmcptr frmJ, int axisI, int axisJ); + + int axisI, axisJ; + double aAijIeJe; + std::shared_ptr> aAjOIe, aAjOJe; + }; +} + diff --git a/MbDCode/DirectionCosineIeqcJec.cpp b/MbDCode/DirectionCosineIeqcJec.cpp new file mode 100644 index 0000000..ead28b8 --- /dev/null +++ b/MbDCode/DirectionCosineIeqcJec.cpp @@ -0,0 +1,14 @@ +#include "DirectionCosineIeqcJec.h" + +using namespace MbD; + +MbD::DirectionCosineIeqcJec::DirectionCosineIeqcJec() +{ + initialize(); +} + +void MbD::DirectionCosineIeqcJec::initialize() +{ + pAijIeJepEI = std::make_shared>(4); + ppAijIeJepEIpEI = std::make_shared>(4, 4); +} diff --git a/MbDCode/DirectionCosineIeqcJec.h b/MbDCode/DirectionCosineIeqcJec.h new file mode 100644 index 0000000..59f1446 --- /dev/null +++ b/MbDCode/DirectionCosineIeqcJec.h @@ -0,0 +1,19 @@ +#pragma once + +#include "DirectionCosineIecJec.h" + +namespace MbD { + class DirectionCosineIeqcJec : public DirectionCosineIecJec + { + //pAijIeJepEI ppAijIeJepEIpEI pAjOIepEIT ppAjOIepEIpEI + public: + DirectionCosineIeqcJec(); + void initialize(); + + FRowDsptr pAijIeJepEI; + FMatDsptr ppAijIeJepEIpEI; + FMatDsptr pAjOIepEIT; + std::shared_ptr>>> ppAjOIepEIpEI; + }; +} + diff --git a/MbDCode/DirectionCosineIeqcJeqc.cpp b/MbDCode/DirectionCosineIeqcJeqc.cpp new file mode 100644 index 0000000..ba59a9c --- /dev/null +++ b/MbDCode/DirectionCosineIeqcJeqc.cpp @@ -0,0 +1,15 @@ +#include "DirectionCosineIeqcJeqc.h" + +using namespace MbD; + +MbD::DirectionCosineIeqcJeqc::DirectionCosineIeqcJeqc() +{ + initialize(); +} + +void MbD::DirectionCosineIeqcJeqc::initialize() +{ + pAijIeJepEJ = std::make_shared>(4); + ppAijIeJepEIpEJ = std::make_shared>(4, 4); + ppAijIeJepEJpEJ = std::make_shared>(4, 4); +} diff --git a/MbDCode/DirectionCosineIeqcJeqc.h b/MbDCode/DirectionCosineIeqcJeqc.h new file mode 100644 index 0000000..239a3fa --- /dev/null +++ b/MbDCode/DirectionCosineIeqcJeqc.h @@ -0,0 +1,21 @@ +#pragma once + +#include "DirectionCosineIeqcJec.h" + +namespace MbD { + class DirectionCosineIeqcJeqc : public DirectionCosineIeqcJec + { + //pAijIeJepEJ ppAijIeJepEIpEJ ppAijIeJepEJpEJ pAjOJepEJT ppAjOJepEJpEJ + public: + DirectionCosineIeqcJeqc(); + void initialize(); + + FRowDsptr pAijIeJepEJ; + FMatDsptr ppAijIeJepEIpEJ; + FMatDsptr ppAijIeJepEJpEJ; + FMatDsptr pAjOJepEJT; + std::shared_ptr>>> ppAjOJepEJpEJ; + + }; +} + diff --git a/MbDCode/DirectionCosineIeqctJeqc.cpp b/MbDCode/DirectionCosineIeqctJeqc.cpp new file mode 100644 index 0000000..de992ec --- /dev/null +++ b/MbDCode/DirectionCosineIeqctJeqc.cpp @@ -0,0 +1,14 @@ +#include "DirectionCosineIeqctJeqc.h" + +using namespace MbD; + +MbD::DirectionCosineIeqctJeqc::DirectionCosineIeqctJeqc() +{ + initialize(); +} + +void MbD::DirectionCosineIeqctJeqc::initialize() +{ + ppAijIeJepEIpt = std::make_shared>(4); + ppAijIeJepEJpt = std::make_shared>(4); +} diff --git a/MbDCode/DirectionCosineIeqctJeqc.h b/MbDCode/DirectionCosineIeqctJeqc.h new file mode 100644 index 0000000..c730035 --- /dev/null +++ b/MbDCode/DirectionCosineIeqctJeqc.h @@ -0,0 +1,19 @@ +#pragma once + +#include "DirectionCosineIeqcJeqc.h" + +namespace MbD { + class DirectionCosineIeqctJeqc : public DirectionCosineIeqcJeqc + { + //pAijIeJept ppAijIeJepEIpt ppAijIeJepEJpt ppAijIeJeptpt + public: + DirectionCosineIeqctJeqc(); + void initialize(); + + double pAijIeJept; + FRowDsptr ppAijIeJepEIpt; + FRowDsptr ppAijIeJepEJpt; + double ppAijIeJeptpt; + }; +} + diff --git a/MbDCode/EndFramec.cpp b/MbDCode/EndFramec.cpp index bffca47..d583628 100644 --- a/MbDCode/EndFramec.cpp +++ b/MbDCode/EndFramec.cpp @@ -1,3 +1,5 @@ +#include + #include "EndFramec.h" using namespace MbD; @@ -18,3 +20,20 @@ void EndFramec::setMarkerFrame(MarkerFrame* markerFrm) { markerFrame = markerFrm; } + +MarkerFrame* EndFramec::getMarkerFrame() +{ + return markerFrame; +} + +void EndFramec::initializeLocally() +{ +} + +void EndFramec::initializeGlobally() +{ +} + +void MbD::EndFramec::EndFrameqctFrom(std::shared_ptr& newFrmI) +{ +} diff --git a/MbDCode/EndFramec.h b/MbDCode/EndFramec.h index 44f3623..dcbbdcf 100644 --- a/MbDCode/EndFramec.h +++ b/MbDCode/EndFramec.h @@ -1,6 +1,9 @@ #pragma once + +#include + #include "CartesianFrame.h" -#include "MarkerFrame.h" +//#include "MarkerFrame.h" #include "FullColumn.h" #include "FullMatrix.h" @@ -15,10 +18,15 @@ namespace MbD { EndFramec(const char* str); void initialize(); void setMarkerFrame(MarkerFrame* markerFrm); + MarkerFrame* getMarkerFrame(); + void initializeLocally() override; + void initializeGlobally() override; + virtual void EndFrameqctFrom(std::shared_ptr& frm); MarkerFrame* markerFrame; - FullColDptr rOeO = std::make_shared>(3); - FullMatDptr aAOe = std::make_shared>(3, 3); + FColDsptr rOeO = std::make_shared>(3); + FMatDsptr aAOe = std::make_shared>(3, 3); }; + using EndFrmcptr = std::shared_ptr; } diff --git a/MbDCode/EndFrameqc.cpp b/MbDCode/EndFrameqc.cpp index 4e8dab5..1a82319 100644 --- a/MbDCode/EndFrameqc.cpp +++ b/MbDCode/EndFrameqc.cpp @@ -1,4 +1,9 @@ +#include + #include "EndFrameqc.h" +#include "EndFrameqct.h" +#include "Variable.h" +#include "MarkerFrame.h" using namespace MbD; @@ -12,4 +17,41 @@ EndFrameqc::EndFrameqc(const char* str) : EndFramec(str) { void EndFrameqc::initialize() { + prOeOpE = std::make_shared>(3, 4); + pprOeOpEpE = std::make_shared>>>(4, 4); + pAOepE = std::make_shared>>>(4); + ppAOepEpE = std::make_shared>>>(4, 4); +} + +void EndFrameqc::initializeLocally() +{ + if (endFrameqct) { + endFrameqct->initializeLocally(); + } +} + +void EndFrameqc::initializeGlobally() +{ + if (endFrameqct) { + endFrameqct->initializeGlobally(); + } + else { + pprOeOpEpE = markerFrame->pprOmOpEpE; + ppAOepEpE = markerFrame->ppAOmpEpE; + } +} + +void MbD::EndFrameqc::EndFrameqctFrom(EndFrmcptr& frm) +{ + endFrameqct = std::make_shared(); +} + +void MbD::EndFrameqc::setrmemBlks(std::shared_ptr>> xyzBlks) +{ + std::static_pointer_cast(endFrameqct)->rmemBlks = xyzBlks; +} + +void MbD::EndFrameqc::setphiThePsiBlks(std::shared_ptr>> xyzRotBlks) +{ + std::static_pointer_cast(endFrameqct)->phiThePsiBlks = xyzRotBlks; } diff --git a/MbDCode/EndFrameqc.h b/MbDCode/EndFrameqc.h index 524b2f5..f962584 100644 --- a/MbDCode/EndFrameqc.h +++ b/MbDCode/EndFrameqc.h @@ -1,10 +1,9 @@ #pragma once + #include "EndFramec.h" -#include "FullColumn.h" -#include "FullMatrix.h" namespace MbD { - class EndFramec; + class Symbolic; class EndFrameqc : public EndFramec { @@ -13,13 +12,17 @@ namespace MbD { EndFrameqc(); EndFrameqc(const char* str); void initialize(); - FullMatDptr prOeOpE = std::make_shared>(3, 4); - //std::shared_ptr>>> pprOeOpEpE = std::make_shared>>>(3, 4); - std::shared_ptr>>> pAOepE = std::make_shared>>>(4); - //std::shared_ptr>>> ppAOepEpE = std::make_shared>>>(4, 4); - //FullMatrix>* pprOeOpEpE1 = new FullMatrix>(3, 4); - //FullColumn>* pAOepE1 = new FullColumn>(4); - //FullMatrix>* ppAOepEpE1 = new FullMatrix>(4, 4); + void initializeLocally() override; + void initializeGlobally() override; + void EndFrameqctFrom(EndFrmcptr& frm) override; + void setrmemBlks(std::shared_ptr>> xyzBlks); + void setphiThePsiBlks(std::shared_ptr>> xyzRotBlks); + + FMatDsptr prOeOpE; + std::shared_ptr>>> pprOeOpEpE; + std::shared_ptr>>> pAOepE; + FMatFMatDsptr ppAOepEpE; + std::shared_ptr endFrameqct; }; } diff --git a/MbDCode/EndFrameqct.cpp b/MbDCode/EndFrameqct.cpp index 2398841..889a6d6 100644 --- a/MbDCode/EndFrameqct.cpp +++ b/MbDCode/EndFrameqct.cpp @@ -1 +1,75 @@ #include "EndFrameqct.h" +#include "System.h" + +using namespace MbD; + +EndFrameqct::EndFrameqct() { + initialize(); +} + +EndFrameqct::EndFrameqct(const char* str) : EndFrameqc(str) { + initialize(); +} + +void EndFrameqct::initialize() +{ + rmem = std::make_shared>(3); + prmempt = std::make_shared>(3); + pprmemptpt = std::make_shared>(3); + aAme = std::make_shared>(3, 3); + pAmept = std::make_shared>(3, 3); + ppAmeptpt = std::make_shared>(3, 3); + pprOeOpEpt = std::make_shared>(3, 4); + pprOeOptpt = std::make_shared>(3); + ppAOepEpt = std::make_shared>>>(4); + ppAOeptpt = std::make_shared>(3, 3); +} + +void EndFrameqct::initializeLocally() +{ + if (!rmemBlks) { + rmem->zeroSelf(); + prmempt->zeroSelf(); + pprmemptpt->zeroSelf(); + } + if (!phiThePsiBlks) { + aAme->identity(); + pAmept->zeroSelf(); + ppAmeptpt->zeroSelf(); + } +} + +void EndFrameqct::initializeGlobally() +{ + if (!rmemBlks) { + initprmemptBlks(); + initpprmemptptBlks(); + } + if (!phiThePsiBlks) { + initpPhiThePsiptBlks(); + initppPhiThePsiptptBlks(); + } +} + +void MbD::EndFrameqct::initprmemptBlks() +{ + auto time = System::getInstance().time; + prmemptBlks = std::make_shared< FullColumn>>(3); + for (int i = 0; i < 3; i++) { + auto disp = rmemBlks->at(i); + auto vel = (disp->differentiateWRT(time))->simplified(); + prmemptBlks->at(i) = vel; + } +} + +void MbD::EndFrameqct::initpprmemptptBlks() +{ +} + +void MbD::EndFrameqct::initpPhiThePsiptBlks() +{ +} + +void MbD::EndFrameqct::initppPhiThePsiptptBlks() +{ +} diff --git a/MbDCode/EndFrameqct.h b/MbDCode/EndFrameqct.h index 4f12da6..1fd80a0 100644 --- a/MbDCode/EndFrameqct.h +++ b/MbDCode/EndFrameqct.h @@ -2,14 +2,32 @@ #include "EndFrameqc.h" namespace MbD { - class EndFrameqct : public EndFrameqc - { - //time rmemBlks prmemptBlks pprmemptptBlks phiThePsiBlks pPhiThePsiptBlks ppPhiThePsiptptBlks - //rmem prmempt pprmemptpt aAme pAmept ppAmeptpt prOeOpt pprOeOpEpt pprOeOptpt pAOept ppAOepEpt ppAOeptpt - public: - double time; - FullColDptr rmem, prmempt, pprmemptpt; - FullMatDptr aAme, pAmept, ppAmeptpt; - }; + + class Symbolic; + + class EndFrameqct : public EndFrameqc + { + //time rmemBlks prmemptBlks pprmemptptBlks phiThePsiBlks pPhiThePsiptBlks ppPhiThePsiptptBlks + //rmem prmempt pprmemptpt aAme pAmept ppAmeptpt prOeOpt pprOeOpEpt pprOeOptpt pAOept ppAOepEpt ppAOeptpt + public: + EndFrameqct(); + EndFrameqct(const char* str); + void initialize(); + void initializeLocally() override; + void initializeGlobally() override; + void initprmemptBlks(); + void initpprmemptptBlks(); + void initpPhiThePsiptBlks(); + void initppPhiThePsiptptBlks(); + + double time; + std::shared_ptr>> rmemBlks, prmemptBlks, pprmemptptBlks; + std::shared_ptr>> phiThePsiBlks, pPhiThePsiptBlks, ppPhiThePsiptptBlks; + FColDsptr rmem, prmempt, pprmemptpt, pprOeOptpt; + FMatDsptr aAme, pAmept, ppAmeptpt, ppAOeptpt; + FMatDsptr pprOeOpEpt; + std::shared_ptr>>> ppAOepEpt; + }; + using EndFrmqctptr = std::shared_ptr; } diff --git a/MbDCode/EulerConstraint.cpp b/MbDCode/EulerConstraint.cpp index 9bc40c0..bbe18af 100644 --- a/MbDCode/EulerConstraint.cpp +++ b/MbDCode/EulerConstraint.cpp @@ -5,12 +5,14 @@ using namespace MbD; EulerConstraint::EulerConstraint() { + initialize(); } -MbD::EulerConstraint::EulerConstraint(const char* str) : Constraint(str) +EulerConstraint::EulerConstraint(const char* str) : Constraint(str) { } -void MbD::EulerConstraint::initialize() +void EulerConstraint::initialize() { + pGpE = std::make_shared>(4); } diff --git a/MbDCode/EulerConstraint.h b/MbDCode/EulerConstraint.h index a3e121a..5e3d167 100644 --- a/MbDCode/EulerConstraint.h +++ b/MbDCode/EulerConstraint.h @@ -14,7 +14,7 @@ namespace MbD { EulerConstraint(const char* str); void initialize(); - FullRowDptr pGpE = std::make_shared>(4); //partial derivative of G wrt pE + FRowDsptr pGpE;//partial derivative of G wrt pE int iqE = -1; }; } diff --git a/MbDCode/EulerParameters.cpp b/MbDCode/EulerParameters.cpp index dfac4f9..cfac1cf 100644 --- a/MbDCode/EulerParameters.cpp +++ b/MbDCode/EulerParameters.cpp @@ -6,9 +6,7 @@ using namespace MbD; -//typedef std::shared_ptr>>> FMatFColDptr; - -std::shared_ptr>>> EulerParameters::ppApEpEtimesColumn(FullColDptr col) +std::shared_ptr>>> EulerParameters::ppApEpEtimesColumn(FColDsptr col) { double a2c1 = 2 * col->at(0); double a2c2 = 2 * col->at(1); @@ -32,17 +30,17 @@ std::shared_ptr>>> EulerParameters row1->at(1) = col12; row1->at(2) = col13; row1->at(3) = col14; - auto row2 = answer->at(0); + auto row2 = answer->at(1); row2->at(0) = col12; row2->at(1) = col22; row2->at(2) = col23; row2->at(3) = col24; - auto row3 = answer->at(0); + auto row3 = answer->at(2); row3->at(0) = col13; row3->at(1) = col23; row3->at(2) = col33; row3->at(3) = col34; - auto row4 = answer->at(0); + auto row4 = answer->at(3); row4->at(0) = col14; row4->at(1) = col24; row4->at(2) = col34; @@ -50,16 +48,16 @@ std::shared_ptr>>> EulerParameters return answer; } -std::shared_ptr>>> EulerParameters::ppApEpEtimesMatrix(FullMatDptr mat) +std::shared_ptr>>> EulerParameters::ppApEpEtimesMatrix(FMatDsptr mat) { - FullRowDptr a2m1 = mat->at(0)->times(2.0); - FullRowDptr a2m2 = mat->at(1)->times(2.0); - FullRowDptr a2m3 = mat->at(2)->times(2.0); - FullRowDptr m2m1 = a2m1->negated(); - FullRowDptr m2m2 = a2m2->negated(); - FullRowDptr m2m3 = a2m3->negated(); + FRowDsptr a2m1 = mat->at(0)->times(2.0); + FRowDsptr a2m2 = mat->at(1)->times(2.0); + FRowDsptr a2m3 = mat->at(2)->times(2.0); + FRowDsptr m2m1 = a2m1->negated(); + FRowDsptr m2m2 = a2m2->negated(); + FRowDsptr m2m3 = a2m3->negated(); auto aaaa = std::make_shared>(3, 0.0); - FullRowDptr zero = std::make_shared>(3, 0.0); + FRowDsptr zero = std::make_shared>(3, 0.0); auto mat11 = std::make_shared>(ListFRD{ a2m1, m2m2, m2m3 }); auto mat12 = std::make_shared>(ListFRD{ a2m2, a2m1, zero }); auto mat13 = std::make_shared>(ListFRD{ a2m3, zero, a2m1 }); diff --git a/MbDCode/EulerParameters.h b/MbDCode/EulerParameters.h index 65b25dc..30eee56 100644 --- a/MbDCode/EulerParameters.h +++ b/MbDCode/EulerParameters.h @@ -8,11 +8,9 @@ namespace MbD { { //aA aB aC pApE public: - static std::shared_ptr>>> ppApEpEtimesColumn(FullColDptr col); - static std::shared_ptr>>> ppApEpEtimesMatrix(FullMatDptr col); + static std::shared_ptr>>> ppApEpEtimesColumn(FColDsptr col); + static std::shared_ptr>>> ppApEpEtimesMatrix(FMatDsptr col); }; - - //typedef std::shared_ptr>>> FMatFColDptr; } diff --git a/MbDCode/ExpressionX.cpp b/MbDCode/ExpressionX.cpp new file mode 100644 index 0000000..c2be36f --- /dev/null +++ b/MbDCode/ExpressionX.cpp @@ -0,0 +1 @@ +#include "ExpressionX.h" diff --git a/MbDCode/ExpressionX.h b/MbDCode/ExpressionX.h new file mode 100644 index 0000000..0a7e4d0 --- /dev/null +++ b/MbDCode/ExpressionX.h @@ -0,0 +1,10 @@ +#pragma once + +#include "FunctionX.h" + +namespace MbD { + class ExpressionX : public FunctionX + { + }; +} + diff --git a/MbDCode/FullColumn.h b/MbDCode/FullColumn.h index cc548de..bb938b4 100644 --- a/MbDCode/FullColumn.h +++ b/MbDCode/FullColumn.h @@ -25,8 +25,7 @@ namespace MbD { return ss.str(); } }; - - typedef std::shared_ptr> FullColDptr; - //typedef std::shared_ptr>>> FullColFMptr; + using FColDsptr = std::shared_ptr>; + //using FColFMatDsptr = std::shared_ptr>>>; } diff --git a/MbDCode/FullMatrix.h b/MbDCode/FullMatrix.h index 5be785b..51b6627 100644 --- a/MbDCode/FullMatrix.h +++ b/MbDCode/FullMatrix.h @@ -1,12 +1,11 @@ #pragma once #include -#include "RowTypeMatrix.h" #include "FullColumn.h" +#include "RowTypeMatrix.h" #include "FullRow.h" namespace MbD { - //class FullColumn; template class FullMatrix : public RowTypeMatrix>> @@ -32,13 +31,18 @@ namespace MbD { this->push_back(row); } } + void identity(); }; - - typedef std::initializer_list> ListListD; - typedef std::initializer_list ListFRD; - typedef std::shared_ptr> FullMatDptr; - //typedef std::shared_ptr>>> FMatFColDptr; - typedef std::shared_ptr>>> FMatFMatDptr; - + template <> + inline void FullMatrix::identity() { + this->zeroSelf(); + for (int i = 0; i < this->size(); i++) { + this->at(i)->at(i) = 1.0; + } + } + using FMatDsptr = std::shared_ptr>; + using FMatDsptr = std::shared_ptr>; + //using FMatFColDsptr = std::shared_ptr>>>; + using FMatFMatDsptr = std::shared_ptr>>>; } diff --git a/MbDCode/FullRow.h b/MbDCode/FullRow.h index 9204e7b..65979e3 100644 --- a/MbDCode/FullRow.h +++ b/MbDCode/FullRow.h @@ -13,7 +13,6 @@ namespace MbD { std::shared_ptr> negated(); }; - typedef std::shared_ptr> FullRowDptr; template inline std::shared_ptr> FullRow::times(double a) @@ -30,5 +29,7 @@ namespace MbD { { return this->times(-1.0); } + using ListFRD = std::initializer_list>>; + using FRowDsptr = std::shared_ptr>; } diff --git a/MbDCode/Function.cpp b/MbDCode/Function.cpp new file mode 100644 index 0000000..c72491e --- /dev/null +++ b/MbDCode/Function.cpp @@ -0,0 +1 @@ +#include "Function.h" diff --git a/MbDCode/Function.h b/MbDCode/Function.h new file mode 100644 index 0000000..d7f9ff5 --- /dev/null +++ b/MbDCode/Function.h @@ -0,0 +1,10 @@ +#pragma once + +#include "Symbolic.h" + +namespace MbD { + class Function : public Symbolic + { + }; +} + diff --git a/MbDCode/FunctionWithManyArgs.cpp b/MbDCode/FunctionWithManyArgs.cpp new file mode 100644 index 0000000..0b1df70 --- /dev/null +++ b/MbDCode/FunctionWithManyArgs.cpp @@ -0,0 +1,27 @@ +#include "FunctionWithManyArgs.h" +#include "Symbolic.h" + +using namespace MbD; + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term) +{ + terms = std::make_shared>>(); + terms->push_back(term); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term) +{ + terms->push_back(term1); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1) +{ + terms->push_back(term2); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr>> _terms) { + terms = std::make_shared>>(); + for (int i = 0; i < _terms->size(); i++) + terms->push_back(_terms->at(i)); +} + diff --git a/MbDCode/FunctionWithManyArgs.h b/MbDCode/FunctionWithManyArgs.h new file mode 100644 index 0000000..0fb6b74 --- /dev/null +++ b/MbDCode/FunctionWithManyArgs.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Function.h" + +namespace MbD { + class FunctionWithManyArgs : public Function + { + //terms + public: + FunctionWithManyArgs(std::shared_ptr term); + FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1); + FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2); + FunctionWithManyArgs(std::shared_ptr>> _terms); + + std::shared_ptr>> terms; + }; +} + diff --git a/MbDCode/FunctionX.cpp b/MbDCode/FunctionX.cpp new file mode 100644 index 0000000..d59434a --- /dev/null +++ b/MbDCode/FunctionX.cpp @@ -0,0 +1 @@ +#include "FunctionX.h" diff --git a/MbDCode/FunctionX.h b/MbDCode/FunctionX.h new file mode 100644 index 0000000..239d397 --- /dev/null +++ b/MbDCode/FunctionX.h @@ -0,0 +1,10 @@ +#pragma once + +#include "Function.h" + +namespace MbD { + class FunctionX : public Function + { + }; +} + diff --git a/MbDCode/Item.cpp b/MbDCode/Item.cpp index b792fa1..79534ef 100644 --- a/MbDCode/Item.cpp +++ b/MbDCode/Item.cpp @@ -2,6 +2,19 @@ using namespace MbD; +Item::Item() { + initialize(); +} + +Item::Item(const char* str) : name(str) +{ + initialize(); +} + +void Item::initialize() +{ +} + void Item::setName(std::string& str) { name = str; @@ -11,3 +24,11 @@ const std::string& Item::getName() const { return name; } + +void Item::initializeLocally() +{ +} + +void Item::initializeGlobally() +{ +} diff --git a/MbDCode/Item.h b/MbDCode/Item.h index 473562a..9533f9c 100644 --- a/MbDCode/Item.h +++ b/MbDCode/Item.h @@ -6,10 +6,14 @@ namespace MbD { { //name public: - Item() {} - Item(const char* str) : name(str) {} + Item(); + Item(const char* str); + virtual void initialize(); + virtual void initializeLocally(); + virtual void initializeGlobally(); void setName(std::string& str); const std::string& getName() const; + private: std::string name; }; diff --git a/MbDCode/Joint.cpp b/MbDCode/Joint.cpp index b35cb7c..e6ddd9e 100644 --- a/MbDCode/Joint.cpp +++ b/MbDCode/Joint.cpp @@ -1,3 +1,5 @@ +#include + #include "Joint.h" using namespace MbD; @@ -12,10 +14,10 @@ Joint::Joint(const char* str) : Item(str) { void Joint::initialize() { - constraints = std::make_unique>>(); + constraints = std::make_shared>>(); } -void Joint::connectsItoJ(std::shared_ptr frmi, std::shared_ptr frmj) +void Joint::connectsItoJ(EndFrmcptr frmi, EndFrmcptr frmj) { frmI = frmi; frmJ = frmj; @@ -23,8 +25,10 @@ void Joint::connectsItoJ(std::shared_ptr frmi, std::shared_ptrbegin(), constraints->end(), [](const auto& constraint) { constraint->initializeLocally(); }); } void Joint::initializeGlobally() { + std::for_each(constraints->begin(), constraints->end(), [](const auto& constraint) { constraint->initializeGlobally(); }); } diff --git a/MbDCode/Joint.h b/MbDCode/Joint.h index ef4b1a9..f769805 100644 --- a/MbDCode/Joint.h +++ b/MbDCode/Joint.h @@ -2,13 +2,15 @@ #include #include +//#include "typedef.h" #include "Item.h" #include "EndFramec.h" #include "Constraint.h" namespace MbD { - class EndFramec; + //class EndFramec; class Constraint; + //using EndFrmcptr = std::shared_ptr; class Joint : public Item { @@ -17,13 +19,13 @@ namespace MbD { Joint(); Joint(const char* str); void initialize(); - virtual void connectsItoJ(std::shared_ptr frmI, std::shared_ptr frmJ); - void initializeLocally(); - void initializeGlobally(); + virtual void connectsItoJ(EndFrmcptr frmI, EndFrmcptr frmJ); + void initializeLocally() override; + void initializeGlobally() override; - std::shared_ptr frmI; - std::shared_ptr frmJ; - std::unique_ptr>> constraints; + EndFrmcptr frmI; + EndFrmcptr frmJ; + std::shared_ptr>> constraints; }; } diff --git a/MbDCode/KinematicIeJe.cpp b/MbDCode/KinematicIeJe.cpp new file mode 100644 index 0000000..481ec42 --- /dev/null +++ b/MbDCode/KinematicIeJe.cpp @@ -0,0 +1,11 @@ +#include "KinematicIeJe.h" + +using namespace MbD; + +MbD::KinematicIeJe::KinematicIeJe() +{ +} + +MbD::KinematicIeJe::KinematicIeJe(EndFrmcptr frmi, EndFrmcptr frmj) : frmI(frmi), frmJ(frmj) +{ +} diff --git a/MbDCode/KinematicIeJe.h b/MbDCode/KinematicIeJe.h new file mode 100644 index 0000000..6964104 --- /dev/null +++ b/MbDCode/KinematicIeJe.h @@ -0,0 +1,18 @@ +#pragma once + +//#include "typedef.h" +#include "Item.h" +#include "EndFramec.h" + +namespace MbD { + class KinematicIeJe : public Item + { + //frmI frmJ + public: + KinematicIeJe(); + KinematicIeJe(EndFrmcptr frmi, EndFrmcptr frmj); + + EndFrmcptr frmI, frmJ; + }; +} + diff --git a/MbDCode/MarkerFrame.cpp b/MbDCode/MarkerFrame.cpp index bb0341a..763aa69 100644 --- a/MbDCode/MarkerFrame.cpp +++ b/MbDCode/MarkerFrame.cpp @@ -1,7 +1,10 @@ +#include + #include "PartFrame.h" #include "MarkerFrame.h" #include "EndFramec.h" #include "EndFrameqc.h" +#include "EulerParameters.h" using namespace MbD; @@ -10,14 +13,15 @@ MarkerFrame::MarkerFrame() initialize(); } -MbD::MarkerFrame::MarkerFrame(const char* str) : CartesianFrame(str) { +MarkerFrame::MarkerFrame(const char* str) : CartesianFrame(str) { initialize(); } -void MbD::MarkerFrame::initialize() +void MarkerFrame::initialize() { - partFrame = nullptr; - endFrames = std::make_unique>>(); + prOmOpE = std::make_shared>(3, 4); + pAOmpE = std::make_shared>>>(4); + endFrames = std::make_shared>(); auto endFrm = std::make_shared("EndFrame1"); this->addEndFrame(endFrm); } @@ -31,17 +35,29 @@ PartFrame* MarkerFrame::getPartFrame() { return partFrame; } -void MarkerFrame::setrpmp(FullColDptr x) +void MarkerFrame::setrpmp(FColDsptr x) { rpmp->copy(x); } -void MarkerFrame::setaApm(FullMatDptr x) +void MarkerFrame::setaApm(FMatDsptr x) { aApm->copy(x); } -void MarkerFrame::addEndFrame(std::shared_ptr endFrm) +void MarkerFrame::addEndFrame(EndFrmcptr endFrm) { endFrm->setMarkerFrame(this); endFrames->push_back(endFrm); } + +void MarkerFrame::initializeLocally() +{ + pprOmOpEpE = EulerParameters::ppApEpEtimesColumn(rpmp); + ppAOmpEpE = EulerParameters::ppApEpEtimesMatrix(aApm); + std::for_each(endFrames->begin(), endFrames->end(), [](const auto& endFrame) { endFrame->initializeLocally(); }); +} + +void MarkerFrame::initializeGlobally() +{ + std::for_each(endFrames->begin(), endFrames->end(), [](const auto& endFrame) { endFrame->initializeGlobally(); }); +} diff --git a/MbDCode/MarkerFrame.h b/MbDCode/MarkerFrame.h index aac4d6b..af22c4e 100644 --- a/MbDCode/MarkerFrame.h +++ b/MbDCode/MarkerFrame.h @@ -10,6 +10,7 @@ namespace MbD { class PartFrame; class EndFramec; + using EndFrmcptr = std::shared_ptr; class MarkerFrame : public CartesianFrame { @@ -20,18 +21,22 @@ namespace MbD { void initialize(); void setPartFrame(PartFrame* partFrm); PartFrame* getPartFrame(); - void setrpmp(FullColDptr x); - void setaApm(FullMatDptr x); - void addEndFrame(std::shared_ptr x); + void setrpmp(FColDsptr x); + void setaApm(FMatDsptr x); + void addEndFrame(EndFrmcptr x); + void initializeLocally() override; + void initializeGlobally() override; PartFrame* partFrame; - FullColDptr rpmp = std::make_shared>(3); - FullMatDptr aApm = std::make_shared>(3, 3); - FullColDptr rOmO = std::make_shared>(3); - FullMatDptr aAOm = std::make_shared>(3, 3); - FullMatDptr prOmOpE = std::make_shared>(3, 4); - FullColumn>* pAOmpE = new FullColumn>(4); - std::unique_ptr>> endFrames; + FColDsptr rpmp = std::make_shared>(3); + FMatDsptr aApm = std::make_shared>(3, 3); + FColDsptr rOmO = std::make_shared>(3); + FMatDsptr aAOm = std::make_shared>(3, 3); + FMatDsptr prOmOpE; + std::shared_ptr>>> pAOmpE; + std::shared_ptr>>> pprOmOpEpE; + FMatFMatDsptr ppAOmpEpE; + std::shared_ptr> endFrames; }; } diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index f453f8d..eaa6abe 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -6,6 +6,7 @@ #include #include "System.h" +#include "Constant.h" #include "FullColumn.h" #include "FullMatrix.h" #include "Part.h" @@ -14,6 +15,8 @@ #include "RevoluteJoint.h" #include "ZRotation.h" #include "EndFrameqc.h" +#include "EndFrameqct.h" +#include "Product.h" #include "MbDCode.h" using namespace MbD; @@ -21,17 +24,32 @@ using namespace MbD; int main() { std::cout << "Hello World!\n"; - //System& TheSystem = System::getInstance(); System& TheSystem = System::getInstance("TheSystem"); std::cout << "TheSystem.getName() " << TheSystem.getName() << std::endl; + auto systemSolver = TheSystem.systemSolver; + systemSolver->errorTolPosKine = 1.0e-6; + systemSolver->errorTolAccKine = 1.0e-6; + systemSolver->iterMaxPosKine = 25; + systemSolver->iterMaxAccKine = 25; + systemSolver->tstart = 0; + systemSolver->tend = 25.0; + systemSolver->hmin = 2.5e-8; + systemSolver->hmax = 25.0; + systemSolver->hout = 1.0; + systemSolver->corAbsTol = 1.0e-6; + systemSolver->corRelTol = 1.0e-6; + systemSolver->intAbsTol = 1.0e-6; + systemSolver->intRelTol = 1.0e-6; + systemSolver->iterMaxDyn = 4; + systemSolver->orderMax = 5; + systemSolver->translationLimit = 9.6058421285615e9; + systemSolver->rotationLimit = 0.5; + std::string str; - FullColDptr qX, qE; - FullColDptr rpmp; - FullMatDptr aApm; - FullRowDptr fullRow; - auto row = std::make_shared>(ListD{ 0.0, 0.0, 0.0, 1.0 }); - fullRow = std::make_shared>(4); - fullRow->copy(row); + FColDsptr qX, qE; + FColDsptr rpmp; + FMatDsptr aApm; + FRowDsptr fullRow; // auto assembly1 = std::make_shared("Assembly1"); std::cout << "assembly1->getName() " << assembly1->getName() << std::endl; @@ -66,15 +84,16 @@ int main() marker2->setaApm(aApm); partFrame->addMarkerFrame(marker2); } + assembly1->asFixed(); // - auto part1 = std::make_shared("Part1"); + auto crankPart1 = std::make_shared("Part1"); qX = std::make_shared>(ListD{ 0.38423366582893, 6.8384291794733e-9, -0.048029210642807 }); qE = std::make_shared>(ListD{ 0.0, 0.0, 1.4248456266393e-10, 1.0 }); - part1->setqX(qX); - part1->setqE(qE); - TheSystem.parts->push_back(part1); + crankPart1->setqX(qX); + crankPart1->setqE(qE); + TheSystem.parts->push_back(crankPart1); { - auto partFrame = part1->partFrame; + auto partFrame = crankPart1->partFrame; auto marker1 = std::make_shared("Marker1"); rpmp = std::make_shared>(ListD{ -0.38423368514246, -2.6661567755108e-17, 0.048029210642807 }); marker1->setrpmp(rpmp); @@ -98,14 +117,14 @@ int main() partFrame->addMarkerFrame(marker2); } // - auto part2 = std::make_shared("Part2"); + auto conrodPart2 = std::make_shared("Part2"); qX = std::make_shared>(ListD{ 0.38423366582893, 0.49215308269277, 0.048029210642807 }); qE = std::make_shared>(ListD{ 0.0, 0.0, 0.89871701272344, 0.4385290538168 }); - part2->setqX(qX); - part2->setqE(qE); - TheSystem.parts->push_back(part2); + conrodPart2->setqX(qX); + conrodPart2->setqE(qE); + TheSystem.parts->push_back(conrodPart2); { - auto partFrame = part2->partFrame; + auto partFrame = conrodPart2->partFrame; auto marker1 = std::make_shared("Marker1"); rpmp = std::make_shared>(ListD{ -0.6243797383565, 1.1997705489799e-16, -0.048029210642807 }); marker1->setrpmp(rpmp); @@ -129,14 +148,14 @@ int main() partFrame->addMarkerFrame(marker2); } // - auto part3 = std::make_shared("Part3"); + auto pistonPart3 = std::make_shared("Part3"); qX = std::make_shared>(ListD{ -1.284772285311e-18, 1.4645982581368, -4.788228906425e-17 }); qE = std::make_shared>(ListD{ 0.70710678118655, 0.70710678118655, 0.0, 0.0 }); - part3->setqX(qX); - part3->setqE(qE); - TheSystem.parts->push_back(part3); + pistonPart3->setqX(qX); + pistonPart3->setqE(qE); + TheSystem.parts->push_back(pistonPart3); { - auto partFrame = part3->partFrame; + auto partFrame = pistonPart3->partFrame; auto marker1 = std::make_shared("Marker1"); rpmp = std::make_shared>(ListD{ -0.48029210642807, 7.6201599718927e-18, -2.816737703896e-17 }); marker1->setrpmp(rpmp); @@ -161,23 +180,26 @@ int main() } // auto cylJoint4 = std::make_shared("CylJoint4"); - cylJoint4->connectsItoJ(part3->partFrame->endFrame("Marker2"), assembly1->partFrame->endFrame("Marker1")); + cylJoint4->connectsItoJ(pistonPart3->partFrame->endFrame("Marker2"), assembly1->partFrame->endFrame("Marker1")); TheSystem.jointsMotions->push_back(cylJoint4); auto revJoint3 = std::make_shared("RevJoint3"); - revJoint3->connectsItoJ(part2->partFrame->endFrame("Marker2"), part3->partFrame->endFrame("Marker1")); + revJoint3->connectsItoJ(conrodPart2->partFrame->endFrame("Marker2"), pistonPart3->partFrame->endFrame("Marker1")); TheSystem.jointsMotions->push_back(revJoint3); auto revJoint2 = std::make_shared("RevJoint2"); - revJoint2->connectsItoJ(part1->partFrame->endFrame("Marker2"), part2->partFrame->endFrame("Marker1")); + revJoint2->connectsItoJ(crankPart1->partFrame->endFrame("Marker2"), conrodPart2->partFrame->endFrame("Marker1")); TheSystem.jointsMotions->push_back(revJoint2); auto revJoint1 = std::make_shared("RevJoint1"); - revJoint1->connectsItoJ(assembly1->partFrame->endFrame("Marker2"), part1->partFrame->endFrame("Marker1")); + revJoint1->connectsItoJ(assembly1->partFrame->endFrame("Marker2"), crankPart1->partFrame->endFrame("Marker1")); TheSystem.jointsMotions->push_back(revJoint1); auto rotMotion1 = std::make_shared("RotMotion1"); - rotMotion1->connectsItoJ(assembly1->partFrame->endFrame("Marker2"), part1->partFrame->endFrame("Marker1")); + rotMotion1->connectsItoJ(assembly1->partFrame->endFrame("Marker2"), crankPart1->partFrame->endFrame("Marker1")); + auto omega = std::make_shared(6.2831853071796); + auto timeScale = std::make_shared(0.04); + rotMotion1->phiBlk = std::make_shared(omega, timeScale, TheSystem.time); TheSystem.jointsMotions->push_back(rotMotion1); // TheSystem.runKINEMATICS(); diff --git a/MbDCode/MbDCode.vcxproj b/MbDCode/MbDCode.vcxproj index 5d578e7..e90b03a 100644 --- a/MbDCode/MbDCode.vcxproj +++ b/MbDCode/MbDCode.vcxproj @@ -129,28 +129,42 @@ + + + + + + + + + + + + + + @@ -158,11 +172,12 @@ + - + @@ -170,28 +185,42 @@ + + + + + + + + + + + + + + @@ -199,11 +228,13 @@ + - + + diff --git a/MbDCode/MbDCode.vcxproj.filters b/MbDCode/MbDCode.vcxproj.filters index 7fc0f3d..e0b657c 100644 --- a/MbDCode/MbDCode.vcxproj.filters +++ b/MbDCode/MbDCode.vcxproj.filters @@ -129,7 +129,52 @@ Source Files - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + Source Files @@ -248,7 +293,55 @@ Header Files - + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + Header Files diff --git a/MbDCode/NewtonRaphson.h b/MbDCode/NewtonRaphson.h index e6b411a..e1402fc 100644 --- a/MbDCode/NewtonRaphson.h +++ b/MbDCode/NewtonRaphson.h @@ -1,8 +1,18 @@ #pragma once + +#include + #include "Solver.h" + +#include "FullColumn.h" + namespace MbD { class NewtonRaphson : public Solver { + //system xold x dx dxNorm dxNorms dxTol y yNorm yNormOld yNorms yNormTol pypx iterNo iterMax nDivergence nBackTracking twoAlp lam + public: + std::shared_ptr> xold, x, dx, dxTol, y; + double dxNorm, yNorm, yNormOld, yNormTol, twoAlp, lam; }; } diff --git a/MbDCode/Part.cpp b/MbDCode/Part.cpp index 0d60e8b..3c409b4 100644 --- a/MbDCode/Part.cpp +++ b/MbDCode/Part.cpp @@ -16,21 +16,24 @@ void Part::initialize() { partFrame = std::make_shared(); partFrame->setPart(this); + pTpE = std::make_shared>(4); + ppTpEpE = std::make_shared>(4, 4); + ppTpEpEdot = std::make_shared>(4, 4); } -void Part::setqX(FullColDptr x) { +void Part::setqX(FColDsptr x) { partFrame->setqX(x); } -FullColDptr Part::getqX() { +FColDsptr Part::getqX() { return partFrame->getqX(); } -void Part::setqE(FullColDptr x) { +void Part::setqE(FColDsptr x) { partFrame->setqE(x); } -FullColDptr Part::getqE() { +FColDsptr Part::getqE() { return partFrame->getqE(); } @@ -39,10 +42,17 @@ void Part::setSystem(System& sys) //May be needed in the future } +void MbD::Part::asFixed() +{ + partFrame->asFixed(); +} + void Part::initializeLocally() { + partFrame->initializeLocally(); } void Part::initializeGlobally() { + partFrame->initializeGlobally(); } diff --git a/MbDCode/Part.h b/MbDCode/Part.h index b150aef..d02a199 100644 --- a/MbDCode/Part.h +++ b/MbDCode/Part.h @@ -5,6 +5,7 @@ #include "System.h" #include "PartFrame.h" #include "FullColumn.h" +#include "DiagonalMatrix.h" namespace MbD { class System; @@ -17,15 +18,30 @@ namespace MbD { Part(); Part(const char* str); void initialize(); - void setqX(FullColDptr x); - FullColDptr getqX(); - void setqE(FullColDptr x); - FullColDptr getqE(); + void initializeLocally() override; + void initializeGlobally() override; + void setqX(FColDsptr x); + FColDsptr getqX(); + void setqE(FColDsptr x); + FColDsptr getqE(); void setSystem(System& sys); - void initializeLocally(); - void initializeGlobally(); + void asFixed(); + int ipX; + int ipE; + double m; + std::shared_ptr> aJ; std::shared_ptr partFrame; + FColDsptr pX; + FColDsptr pXdot; + FColDsptr pE; + FColDsptr pEdot; + std::shared_ptr> mX; + std::shared_ptr> mE; + FMatDsptr mEdot; + FColDsptr pTpE; + FMatDsptr ppTpEpE; + FMatDsptr ppTpEpEdot; }; } diff --git a/MbDCode/PartFrame.cpp b/MbDCode/PartFrame.cpp index e13094a..950d2b1 100644 --- a/MbDCode/PartFrame.cpp +++ b/MbDCode/PartFrame.cpp @@ -1,3 +1,5 @@ +#include + #include "Part.h" #include "PartFrame.h" #include "EulerConstraint.h" @@ -7,28 +9,30 @@ using namespace MbD; PartFrame::PartFrame() +{ + initialize(); +} +PartFrame::PartFrame(const char* str) : CartesianFrame(str) +{ + initialize(); +} +void PartFrame::initialize() { aGeu = std::make_shared("EulerCon"); aGeu->setOwner(this); - aGabs = std::make_unique>>(); - markerFrames = std::make_unique>>(); + aGabs = std::make_shared>>(); + markerFrames = std::make_shared>>(); } -MbD::PartFrame::PartFrame(const char* str) : CartesianFrame(str) -{ -} -void MbD::PartFrame::initialize() -{ -} -void PartFrame::setqX(FullColDptr x) { +void PartFrame::setqX(FColDsptr x) { qX->copy(x); } -FullColDptr PartFrame::getqX() { +FColDsptr PartFrame::getqX() { return qX; } -void PartFrame::setqE(FullColDptr x) { +void PartFrame::setqE(FColDsptr x) { qE->copy(x); } -FullColDptr PartFrame::getqE() { +FColDsptr PartFrame::getqE() { return qE; } void PartFrame::setPart(Part* x) { @@ -44,8 +48,31 @@ void PartFrame::addMarkerFrame(std::shared_ptr markerFrame) markerFrames->push_back(markerFrame); } -std::shared_ptr PartFrame::endFrame(std::string name) +EndFrmcptr PartFrame::endFrame(std::string name) { auto match = std::find_if(markerFrames->begin(), markerFrames->end(), [&](auto mkr) {return mkr->getName() == name; }); return (*match)->endFrames->at(0); } + +void MbD::PartFrame::asFixed() +{ + for (int i = 0; i < 6; i++) { + auto con = std::make_shared(i); + con->setOwner(this); + aGabs->push_back(con); + } +} + +void PartFrame::initializeLocally() +{ + std::for_each(markerFrames->begin(), markerFrames->end(), [](const auto& markerFrame) { markerFrame->initializeLocally(); }); + aGeu->initializeLocally(); + std::for_each(aGabs->begin(), aGabs->end(), [](const auto& aGab) { aGab->initializeLocally(); }); +} + +void PartFrame::initializeGlobally() +{ + std::for_each(markerFrames->begin(), markerFrames->end(), [](const auto& markerFrame) { markerFrame->initializeGlobally(); }); + aGeu->initializeGlobally(); + std::for_each(aGabs->begin(), aGabs->end(), [](const auto& aGab) { aGab->initializeGlobally(); }); +} diff --git a/MbDCode/PartFrame.h b/MbDCode/PartFrame.h index e7b3f26..4008c58 100644 --- a/MbDCode/PartFrame.h +++ b/MbDCode/PartFrame.h @@ -14,6 +14,7 @@ namespace MbD { class Part; class MarkerFrame; class EndFramec; + using EndFrmcptr = std::shared_ptr; class PartFrame : public CartesianFrame { @@ -22,23 +23,30 @@ namespace MbD { PartFrame(); PartFrame(const char* str); void initialize(); + void initializeLocally() override; + void initializeGlobally() override; + void asFixed(); - void setqX(FullColDptr x); - FullColDptr getqX(); - void setqE(FullColDptr x); - FullColDptr getqE(); + void setqX(FColDsptr x); + FColDsptr getqX(); + void setqE(FColDsptr x); + FColDsptr getqE(); void setPart(Part* x); Part* getPart(); void addMarkerFrame(std::shared_ptr x); - std::shared_ptr endFrame(std::string name); + EndFrmcptr endFrame(std::string name); Part* part; int iqX, iqE; //Position index of frame variables qX and qE in system list of variables - FullColDptr qX = std::make_shared>(3); - FullColDptr qE = std::make_shared>(4); + FColDsptr qX = std::make_shared>(3); + FColDsptr qE = std::make_shared>(4); + FColDsptr qXdot = std::make_shared>(3); + FColDsptr qEdot = std::make_shared>(4); + FColDsptr qXddot = std::make_shared>(3); + FColDsptr qEddot = std::make_shared>(4); std::shared_ptr aGeu; - std::unique_ptr>> aGabs; - std::unique_ptr>> markerFrames; + std::shared_ptr>> aGabs; + std::shared_ptr>> markerFrames; }; } diff --git a/MbDCode/PrescribedMotion.cpp b/MbDCode/PrescribedMotion.cpp index c4782e1..c06fb98 100644 --- a/MbDCode/PrescribedMotion.cpp +++ b/MbDCode/PrescribedMotion.cpp @@ -1,9 +1,11 @@ +#include #include #include #include #include "PrescribedMotion.h" #include "EndFrameqct.h" +#include "Constant.h" using namespace MbD; @@ -17,15 +19,16 @@ PrescribedMotion::PrescribedMotion(const char* str) : Joint(str) { void PrescribedMotion::initialize() { + xBlk = std::make_shared(0.0); + yBlk = std::make_shared(0.0); + zBlk = std::make_shared(0.0); + phiBlk = std::make_shared(0.0); + theBlk = std::make_shared(0.0); + psiBlk = std::make_shared(0.0); } -void PrescribedMotion::connectsItoJ(std::shared_ptr frmi, std::shared_ptr frmj) +void PrescribedMotion::connectsItoJ(EndFrmcptr frmi, EndFrmcptr frmj) { Joint::connectsItoJ(frmi, frmj); - if (typeid(frmI).name() != "EndFrameqct") { - std::shared_ptr newFrmI; - newFrmI = std::make_shared(); - std::swap(frmI, newFrmI); - assert(typeid(frmI).name() != "EndFrameqct"); - } + frmI->EndFrameqctFrom(frmI); } diff --git a/MbDCode/PrescribedMotion.h b/MbDCode/PrescribedMotion.h index cd866fc..6236c96 100644 --- a/MbDCode/PrescribedMotion.h +++ b/MbDCode/PrescribedMotion.h @@ -2,6 +2,9 @@ #include "Joint.h" namespace MbD { + + class Symbolic; + class PrescribedMotion : public Joint { //xBlk yBlk zBlk phiBlk theBlk psiBlk @@ -9,7 +12,14 @@ namespace MbD { PrescribedMotion(); PrescribedMotion(const char* str); void initialize(); - void connectsItoJ(std::shared_ptr frmI, std::shared_ptr frmJ) override; + void connectsItoJ(EndFrmcptr frmI, EndFrmcptr frmJ) override; + + std::shared_ptr xBlk; + std::shared_ptr yBlk; + std::shared_ptr zBlk; + std::shared_ptr phiBlk; + std::shared_ptr theBlk; + std::shared_ptr psiBlk; }; } diff --git a/MbDCode/Product.cpp b/MbDCode/Product.cpp new file mode 100644 index 0000000..149c119 --- /dev/null +++ b/MbDCode/Product.cpp @@ -0,0 +1,10 @@ +#include "Product.h" + +using namespace MbD; + +double MbD::Product::getValue() +{ + double answer = 1.0; + for (int i = 0; i < terms->size(); i++) answer *= terms->at(i)->getValue(); + return answer; +} diff --git a/MbDCode/Product.h b/MbDCode/Product.h new file mode 100644 index 0000000..2b9ca7a --- /dev/null +++ b/MbDCode/Product.h @@ -0,0 +1,16 @@ +#pragma once + +#include "FunctionWithManyArgs.h" + +namespace MbD { + class Product : public FunctionWithManyArgs + { + public: + Product(std::shared_ptr term) : FunctionWithManyArgs(term) {} + Product(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term, term1) {} + Product(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1, term2) {} + Product(std::shared_ptr>> _terms) : FunctionWithManyArgs(_terms) {} + double getValue() override; + }; +} + diff --git a/MbDCode/RowTypeMatrix.h b/MbDCode/RowTypeMatrix.h index c3cf077..39b8598 100644 --- a/MbDCode/RowTypeMatrix.h +++ b/MbDCode/RowTypeMatrix.h @@ -1,6 +1,10 @@ #pragma once + #include "Array.h" +#include "FullRow.h" + namespace MbD { + template class RowTypeMatrix : public Array { @@ -8,6 +12,7 @@ namespace MbD { RowTypeMatrix() {} RowTypeMatrix(std::initializer_list list) : Array{ list } {} void copy(std::shared_ptr> x); + void zeroSelf(); }; template @@ -17,5 +22,11 @@ namespace MbD { this->at(i)->copy(x->at(i)); } } + template <> + inline void RowTypeMatrix< std::shared_ptr>>::zeroSelf() { + for (int i = 0; i < this->size(); i++) { + this->at(i)->zeroSelf(); + } + } } diff --git a/MbDCode/Solver.h b/MbDCode/Solver.h index 01e7b97..6e1ae32 100644 --- a/MbDCode/Solver.h +++ b/MbDCode/Solver.h @@ -2,6 +2,9 @@ namespace MbD { class Solver { + public: + virtual void initializeLocally() = 0; + virtual void initializeGlobally() = 0; }; } diff --git a/MbDCode/SparseMatrix.h b/MbDCode/SparseMatrix.h index 017a6d9..bffe854 100644 --- a/MbDCode/SparseMatrix.h +++ b/MbDCode/SparseMatrix.h @@ -15,8 +15,5 @@ namespace MbD { } } }; - typedef std::shared_ptr> SpMatDptr; - typedef std::initializer_list>> ListListPairD; -} - - + using SpMatDptr = std::shared_ptr>; +} \ No newline at end of file diff --git a/MbDCode/SparseRow.h b/MbDCode/SparseRow.h index 3d7e0f8..4a632de 100644 --- a/MbDCode/SparseRow.h +++ b/MbDCode/SparseRow.h @@ -13,6 +13,6 @@ namespace MbD { SparseRow(std::initializer_list> list) : SparseVector{ list } {} SparseRow(std::initializer_list> list) : SparseVector{ list } {} }; - typedef std::shared_ptr> SpRowDptr; + using SpRowDptr = std::shared_ptr>; } diff --git a/MbDCode/Sum.cpp b/MbDCode/Sum.cpp new file mode 100644 index 0000000..b39a51f --- /dev/null +++ b/MbDCode/Sum.cpp @@ -0,0 +1,10 @@ +#include "Sum.h" + +using namespace MbD; + +double MbD::Sum::getValue() +{ + double answer = 0.0; + for (int i = 0; i < terms->size(); i++) answer += terms->at(i)->getValue(); + return answer; +} diff --git a/MbDCode/Sum.h b/MbDCode/Sum.h new file mode 100644 index 0000000..3ce07f4 --- /dev/null +++ b/MbDCode/Sum.h @@ -0,0 +1,16 @@ +#pragma once + +#include "FunctionWithManyArgs.h" + +namespace MbD { + class Sum : public FunctionWithManyArgs + { + public: + Sum(std::shared_ptr term) : FunctionWithManyArgs(term) {} + Sum(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term, term1) {} + Sum(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1, term2) {} + Sum(std::shared_ptr>> _terms) : FunctionWithManyArgs(_terms) {} + double getValue() override; + }; +} + diff --git a/MbDCode/Symbolic.cpp b/MbDCode/Symbolic.cpp index 07d21ec..fc72fa9 100644 --- a/MbDCode/Symbolic.cpp +++ b/MbDCode/Symbolic.cpp @@ -1 +1,42 @@ +#include +#include +#include + #include "Symbolic.h" +#include "Constant.h" + +using namespace MbD; + +Symbolic::Symbolic() +{ + initialize(); +} + +void Symbolic::initialize() +{ +} + +std::shared_ptr MbD::Symbolic::differentiateWRT(std::shared_ptr var) +{ + return std::shared_ptr(); +} + +std::shared_ptr MbD::Symbolic::simplified() +{ + //Debug + auto set = nullptr; + //Debug auto set = std::make_shared>(); + auto answer = expandUntil(set); + auto set1 = nullptr; //std::make_shared>(); + return answer->simplifyUntil(set1); +} + +std::shared_ptr MbD::Symbolic::expandUntil(std::shared_ptr> set) +{ + return std::make_shared(0.0); +} + +std::shared_ptr MbD::Symbolic::simplifyUntil(std::shared_ptr> set) +{ + return std::make_shared(0.0); +} diff --git a/MbDCode/Symbolic.h b/MbDCode/Symbolic.h index d916207..f48b118 100644 --- a/MbDCode/Symbolic.h +++ b/MbDCode/Symbolic.h @@ -1,7 +1,20 @@ #pragma once + +#include +#include + namespace MbD { + class Symbolic { + public: + Symbolic(); + void initialize(); + virtual std::shared_ptr differentiateWRT(std::shared_ptr var); + virtual std::shared_ptr simplified(); + virtual std::shared_ptr expandUntil(std::shared_ptr> set); + virtual std::shared_ptr simplifyUntil(std::shared_ptr> set); + virtual double getValue() = 0; }; } diff --git a/MbDCode/System.cpp b/MbDCode/System.cpp index 840fea9..423d2b3 100644 --- a/MbDCode/System.cpp +++ b/MbDCode/System.cpp @@ -5,17 +5,17 @@ using namespace MbD; System::System() { - time = std::make_unique