2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
24#include "core/clockwerkerrors.h"
25#include "core/vectormath.hpp"
26#include "data_management/GraphTreeObject.h"
27#include "data_management/DataIO.hpp"
35#define NUM_INTEGRATED_STATES 13
40 template <
typename T>
class Body;
41 template <
typename T>
class Node;
91 template <
typename T=
double>
98 Frame(
const std::string &name,
Frame<T>* par=
nullptr,
bool free =
false);
122
127 clockwerk::
DataIO<Quaternion<T>>(
nullptr,
"quat_f_p", Quaternion<T>());
177 Quaternion<T> rootRelQuaternion();
307 template <
typename T>
316 while(ptr !=
nullptr) {
328 if(new_parent !=
nullptr) {
337 if(new_parent->type() == NODE) {
344 if(new_parent->type() == FRAME || new_parent->type() == NODE) {
359 err =
_parent->removeChild(
this);
360 if(err) {
return err;}
365 if(new_parent !=
nullptr) {
366 err = new_parent->addChild(
this);
367 if(err) {
return err;}
375 _t_joint.setFreeAxes(
false,
false,
false);
376 _r_joint.setFreeAxes(
false,
false,
false);
391 template <
typename T>
396 return _parent->getFrameRootPointer();
400 template <
typename T>
403 if(
_r_joint.jointType() == FULLY_LOCKED) {
412 state_dot[6] = qdot_f_p[0][0];
413 state_dot[7] = qdot_f_p[1][0];
414 state_dot[8] = qdot_f_p[2][0];
415 state_dot[9] = qdot_f_p[3][0];
424 state_dot[10] = omega_dot[0];
425 state_dot[11] = omega_dot[1];
426 state_dot[12] = omega_dot[2];
430 if(
_t_joint.jointType() == FULLY_LOCKED) {
432 for(
unsigned int i = 0; i < 6; i++) {
453 v_dot = v_dot - dcm_p_root*
_parent->rootRelAcceleration();
464 v_dot = v_dot - cross(parent_omega, cross(parent_omega,
pos_f_p__p()));
467 v_dot.get(0, state_dot[3]);
468 v_dot.get(1, state_dot[4]);
469 v_dot.get(2, state_dot[5]);
473 template <
typename T>
477 Quaternion<T> tmp({state[6], state[7], state[8], state[9]});
483 template <
typename T>
507 template <
typename T>
512 pos_f_root__root.set(0, 0.0);
513 pos_f_root__root.set(1, 0.0);
514 pos_f_root__root.set(2, 0.0);
517 _parent->rootRelPosition(pos_f_root__root);
521 pos_f_root__root = pos_f_root__root + dcm_p_root.inverse()*
pos_f_p__p();
524 template <
typename T>
527 rootRelPosition(tmp);
531 template <
typename T>
536 vel_f_root__root.set(0, 0.0);
537 vel_f_root__root.set(1, 0.0);
538 vel_f_root__root.set(2, 0.0);
541 _parent->rootRelVelocity(vel_f_root__root);
545 if(
_t_joint.jointType() != FULLY_LOCKED) {
551 vel_f_root__root = vel_f_root__root + dcm_p_root.inverse()*frame_contrib__p;
554 template <
typename T>
557 rootRelVelocity(tmp);
561 template <
typename T>
566 acc_f_root__root.set(0, 0.0);
567 acc_f_root__root.set(1, 0.0);
568 acc_f_root__root.set(2, 0.0);
571 _parent->rootRelAcceleration(acc_f_root__root);
581 frame_contrib__p = frame_contrib__p
585 if(
_t_joint.jointType() != FULLY_LOCKED) {
591 acc_f_root__root = acc_f_root__root + dcm_p_root.inverse()*frame_contrib__p;
594 template <
typename T>
597 rootRelAcceleration(tmp);
601 template <
typename T>
606 w_f_root__f.set(0, 0.0);
607 w_f_root__f.set(1, 0.0);
608 w_f_root__f.set(2, 0.0);
611 _parent->rootRelAngularVelocity(w_f_root__f);
619 template <
typename T>
622 rootRelAngularVelocity(tmp);
626 template <
typename T>
631 alpha_f_root__f.set(0, 0.0);
632 alpha_f_root__f.set(1, 0.0);
633 alpha_f_root__f.set(2, 0.0);
636 _parent->rootRelAngularAcceleration(alpha_f_root__f);
643 template <
typename T>
646 rootRelAngularAcceleration(tmp);
650 template <
typename T>
653 rootRelDCM().toQuaternion(quat_f_root);
655 template <
typename T>
656 Quaternion<T>
Frame<T>::rootRelQuaternion() {
658 rootRelQuaternion(tmp);
662 template <
typename T>
667 dcm_f_root =
DCM<T>();
670 _parent->rootRelDCM(dcm_f_root);
676 template <
typename T>
683 template <
typename T>
688 if(
this->nChildren()) {
689 for(
unsigned int i = 0; i <
this->nChildren(); i++) {
693 if(ptr->type() == BODY) {
695 Body<T>* body_ptr = (Body<T>*)ptr;
696 body_ptr->calcFrameTreeExtForcesMoments();
700 ptr->calcFrameTreeExtForcesMoments();
711 template <
typename T>
717 if(
this->nChildren()) {
718 for(
unsigned int i = 0; i <
this->nChildren(); i++) {
722 if(ptr->type() == BODY) {
724 Body<T>* body_ptr = (Body<T>*)ptr;
725 body_ptr->calcFrameTreeExtAcceleration();
729 ptr->calcFrameTreeExtAcceleration();
740 template <
typename T>
754 template <
typename T>
772 template <
typename T>
781 DCM<T> dcm_f_p = quat_f_root.toDCM()*dcm_p_root.inverse();
787 template <
typename T>
#define NUM_INTEGRATED_STATES
Definition Frame.hpp:35
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Class defining a direction cosine matrix inherited from Matrix.
Definition DCM.hpp:71
Class for inter-object communication.
Definition DataIO.hpp:46
Frame class definition.
Definition Frame.hpp:92
clockwerk::DataIO< CartesianVector< T, 3 > > vel_f_p__p
Definition Frame.hpp:123
clockwerk::DataIO< Quaternion< T > > quat_f_p
Definition Frame.hpp:126
int setRootRelPosition(const CartesianVector< T, 3 > &pos_f_root__root)
Function to set the frame's position relative to root.
Definition Frame.hpp:741
CartesianVector< T, 3 > _acc_f_p__p
Internal variables to store accelerations applied to this frame. Note: these are not states....
Definition Frame.hpp:277
void integrator(void *integ_ptr)
Getter and setter for integrator pointer.
Definition Frame.hpp:220
CartesianVector< T, 3 > parentRelAcceleration()
Function to get the acceleration of the frame relative to parent expressed in parent coords.
Definition Frame.hpp:145
void getStateVectorDot(std::array< T, 13 > &state_dot)
Function to get the rate of change in the frame state vector.
Definition Frame.hpp:401
void setParentRelAngularAcceleration(CartesianVector< T, 3 > alpha)
Function to set parent relative angular acceleration.
Definition Frame.hpp:141
int calcFrameTreeExtForcesMoments()
Function to recurse through the body and its children to apply external forces and moments to the "co...
Definition Frame.hpp:684
clockwerk::DataIO< CartesianVector< T, 3 > > ang_vel_f_p__f
Definition Frame.hpp:129
void rootRelAngularAcceleration(CartesianVector< T, 3 > &alpha_f_root__f)
Returns the angular acceleration of the frame origin wrt the root, expressed in this frame's coordina...
Definition Frame.hpp:627
int setRootRelVelocity(const CartesianVector< T, 3 > &vel_f_root__root)
Function to set the frame's velocity relative to root.
Definition Frame.hpp:755
void setParentRelAcceleration(CartesianVector< T, 3 > accel)
Function to set parent relative acceleration of frame.
Definition Frame.hpp:137
Joint< T > _t_joint
Translational and rotational joints relating this frame to its parent. Set locked by default.
Definition Frame.hpp:282
CartesianVector< T, 3 > parentRelAngularAcceleration()
Function to get angular acceleration relative to parent in frame coords.
Definition Frame.hpp:149
void rootRelVelocity(CartesianVector< T, 3 > &vel_o_root__root)
Returns the velocity of the frame origin wrt the root origin, in root coordinates.
Definition Frame.hpp:532
int setRootRelAttitude(const Quaternion< T > &quat_f_root)
Function to set the frame's attitude relative to root.
Definition Frame.hpp:773
int parent(Frame< T > *new_parent)
Function to assign the frame's parent via pointer.
Definition Frame.hpp:308
clockwerk::DataIO< CartesianVector< T, 3 > > pos_f_p__p
Definition Frame.hpp:119
Frame< T > * getFrameRootPointer()
Function to get a pointer to this frame's root frame.
Definition Frame.hpp:392
void rootRelAcceleration(CartesianVector< T, 3 > &acc_o_root__root)
Returns the acceleration of the frame origin wrt the root origin, in root coordinates.
Definition Frame.hpp:562
int calcFrameTreeExtAcceleration()
Function to recurse through the body and its children to resolve applied external forces and moments ...
Definition Frame.hpp:712
void setStateFromStateVector(const std::array< T, 13 > &state_f_p__f)
Function to set frame state based on NUM_INTEGRATED_STATES-element state vector.
Definition Frame.hpp:474
void getStateAsStateVector(std::array< T, 13 > &state_f_p__f)
Function to return frame state as a NUM_INTEGRATED_STATES-element state vector.
Definition Frame.hpp:484
void rootRelAngularVelocity(CartesianVector< T, 3 > &w_f_root__f)
Returns the angular velocity of the frame origin wrt the root, expressed in this frame's coordinates.
Definition Frame.hpp:602
void rootRelPosition(CartesianVector< T, 3 > &pos_o_root__root)
Returns the position of the frame origin wrt the root origin, in root coordinates.
Definition Frame.hpp:508
Joint< T > & tJoint()
Function to get reference to the frame's translational joint.
Definition Frame.hpp:102
void rootRelDCM(DCM< T > &dcm_f_root)
Returns the DCM of the frame origin wrt the root frame.
Definition Frame.hpp:663
Joint< T > _r_joint
Translational.
Definition Frame.hpp:283
Frame(const std::string &name, Frame< T > *par=nullptr, bool free=false)
Constructor for the frame object.
Definition Frame.hpp:294
Frame< T > * _parent
Variable to hold our parent.
Definition Frame.hpp:290
void * _integrator_ptr
Rotational.
Definition Frame.hpp:287
void rootRelQuaternion(Quaternion< T > &quat_f_root)
Returns the quaternion representing the frame origin wrt the root frame.
Definition Frame.hpp:651
int setRootRelAngularVelocity(const CartesianVector< T, 3 > &w_f_root__f)
Function to set the frame's position relative to root.
Definition Frame.hpp:788
Joint< T > & rJoint()
Function to get reference to the frame's rotational joint.
Definition Frame.hpp:106
Base class for object organization.
Definition GraphTreeObject.h:87
void recalculateRank()
Function to recursively re-calculate the rank of a given node on the tree.
Definition GraphTreeObject.cpp:263
GraphTreeObject * parent()
Functions to get object's parent/children.
Definition GraphTreeObject.h:96
std::vector< GraphTreeObject * > _children
Pointers to the object's children – automatically set to an empty vector, and can be increased to any...
Definition GraphTreeObject.h:234
uint8_t _graph_tree_type
Variable to store graph tree object type.
Definition GraphTreeObject.h:251
Joint class defining relationship between frames.
Definition Joint.hpp:44
Matrix math implementation.
Definition Matrix.hpp:54
#define NO_ERROR
Definition clockwerkerrors.h:31
#define ERROR_FRAME_PARENT_TYPE
Definition clockwerkerrors.h:133
#define ERROR_CIRCULAR_REFERENCE
Definition clockwerkerrors.h:79
#define ERROR_PARENT_NOT_FRAME
Definition clockwerkerrors.h:120