00001
00002
00008
00009
00011
00012 #include "AttitudeHistory.h"
00013 namespace O_SESSAME {
00014
00015 AttitudeHistory::AttitudeHistory()
00016 {
00017 ResetHistory();
00018 m_AttitudeHistory.reserve(HISTORY_RESERVE_SIZE);
00019 m_AttitudeInterpolations.reserve(HISTORY_RESERVE_SIZE);
00020 }
00021
00022 AttitudeHistory::~AttitudeHistory()
00023 {
00024
00025 }
00026
00027 void AttitudeHistory::AppendHistory(const double &_appendTime, const Rotation &_appendRotation, const Vector &_appendAngVel)
00028 {
00029 AppendHistory(ssfTime(_appendTime), AttitudeState(_appendRotation, _appendAngVel));
00030 }
00031
00032 void AttitudeHistory::AppendHistory(const ssfTime &_appendTime, const Rotation &_appendRotation, const Vector &_appendAngVel)
00033 {
00034 History::AppendHistory(_appendTime);
00035 m_AttitudeHistory.push_back(AttitudeState(_appendRotation, _appendAngVel));
00036 return;
00037 }
00038
00039 void AttitudeHistory::AppendHistory(const double &_appendTime, const AttitudeState &_appendAttitudeState)
00040 {
00041 AppendHistory(ssfTime(_appendTime), _appendAttitudeState);
00042 }
00043
00044 void AttitudeHistory::AppendHistory(const ssfTime &_appendTime, const AttitudeState &_appendAttitudeState)
00045 {
00046 History::AppendHistory(_appendTime);
00047 m_AttitudeHistory.push_back(_appendAttitudeState);
00048 return;
00049 }
00050
00052 void AttitudeHistory::AppendHistory(const vector<ssfTime> &_appendTime, const vector<AttitudeState> &_appendAttitudeState)
00053 {
00054 vector<AttitudeState>::const_iterator iter = _appendAttitudeState.begin();
00055
00056 vector<ssfTime>::difference_type retDistance = History::AppendHistory(_appendTime);
00057
00058
00059 if(retDistance != 0)
00060 m_AttitudeHistory.erase(m_AttitudeHistory.end()-retDistance, m_AttitudeHistory.end());
00061
00062 for(iter = _appendAttitudeState.begin(); iter != _appendAttitudeState.end(); ++iter)
00063 m_AttitudeHistory.push_back(*iter);
00064
00065 return;
00066 }
00067
00069 void AttitudeHistory::AppendHistory(const vector<ssfTime> &_appendTime, const vector<Rotation> &_appendRotation, const vector<Vector> &_appendAngVel)
00070 {
00071 vector<ssfTime>::const_iterator iterTime;
00072 vector<Rotation>::const_iterator iterRot;
00073 iterRot = _appendRotation.begin();
00074 vector<Vector>::const_iterator iterVec;
00075 iterVec = _appendAngVel.begin();
00076
00077 for(iterTime = _appendTime.begin(); iterTime != _appendTime.end(); ++iterTime)
00078 {
00079 AppendHistory(*iterTime, *iterRot, *iterVec);
00080 ++iterRot;
00081 ++iterVec;
00082 }
00083 return;
00084 }
00085
00086 void AttitudeHistory::ResetHistory()
00087 {
00088 vector<AttitudeState> newAttitude(0);
00089 m_AttitudeHistory.swap(newAttitude);
00090 History::ResetHistory();
00091 return;
00092 }
00093
00094
00095 Matrix AttitudeHistory::GetHistory(const RotationType &_rotType)
00096 {
00097
00098
00099 int RotVectorSize = (m_AttitudeHistory.back()).GetRotation().GetRotation(_rotType).getIndexBound();
00100 int AngVelVectorSize = (m_AttitudeHistory.back()).GetAngularVelocity().getIndexBound();
00101 Matrix returnMatrix(m_TimeHistory.size(), 1 + RotVectorSize + AngVelVectorSize);
00102
00103 for(int ii = 0; ii < m_TimeHistory.size(); ii++)
00104 {
00105 returnMatrix(MatrixIndexBase + ii, MatrixIndexBase) = m_TimeHistory[ii].GetSeconds();
00106 returnMatrix(MatrixIndexBase + ii, _(MatrixIndexBase+1,MatrixIndexBase + RotVectorSize)) = ~m_AttitudeHistory[ii].GetRotation().GetRotation(_rotType);
00107 returnMatrix(MatrixIndexBase + ii, _(MatrixIndexBase + 1 + RotVectorSize, MatrixIndexBase + RotVectorSize + AngVelVectorSize)) = ~(m_AttitudeHistory[ii].GetAngularVelocity()(_));
00108 }
00109 return returnMatrix;
00110 }
00111
00112 AttitudeState AttitudeHistory::GetState(const ssfTime& _requestedTime)
00113 {
00114 Rotation tempRot;
00115 Vector tempAngVel(3);
00116 GetState(_requestedTime, tempRot, tempAngVel);
00117 return AttitudeState(tempRot, tempAngVel);
00118 }
00119 void AttitudeHistory::GetState(const ssfTime& _requestedTime, Rotation& _returnRotation, Vector& _returnAngVelVector)
00120 {
00121 int RotVectorSize = QUATERNION_SIZE;
00122 int AngVelVectorSize = (m_AttitudeHistory.back()).GetAngularVelocity().getIndexBound();
00123
00124
00125 vector<ssfTime>::difference_type nearestTimeIndex = History::GetState(_requestedTime);
00126
00127 int numDataPoints = 0;
00128 if(m_OriginalInterpolator)
00129 numDataPoints = m_OriginalInterpolator->GetNumberDataPoints();
00130 else
00131 return;
00132 Vector timeVector(numDataPoints);
00133 Matrix dataMatrix(numDataPoints, RotVectorSize+AngVelVectorSize);
00134 Vector tempVector(RotVectorSize+AngVelVectorSize);
00135
00136
00137 if(m_TimeHistory[nearestTimeIndex] != _requestedTime)
00138 {
00139
00140
00141 while(m_AttitudeInterpolations.capacity() < nearestTimeIndex)
00142 {
00143 m_AttitudeInterpolations.reserve(m_AttitudeHistory.capacity() + HISTORY_RESERVE_SIZE);
00144 }
00145
00146 if(!m_AttitudeInterpolations[nearestTimeIndex])
00147 {
00148
00149 for(int kk = m_AttitudeInterpolations.size(); kk < nearestTimeIndex; ++kk)
00150 m_AttitudeInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00151
00152 m_AttitudeInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00153 }
00154
00155 if(!m_AttitudeInterpolations[nearestTimeIndex]->GetValid())
00156 {
00157 for(int ii = 1; ii <= numDataPoints; ++ii)
00158 {
00159 timeVector(ii) = m_TimeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetSeconds();
00160 dataMatrix(ii,_(1,RotVectorSize)) = ~m_AttitudeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetRotation().GetRotation(Quaternion_Type);
00161 dataMatrix(ii,_(RotVectorSize+1,RotVectorSize+AngVelVectorSize)) = ~m_AttitudeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetAngularVelocity();
00162 }
00163
00164 m_AttitudeInterpolations[nearestTimeIndex]->Interpolate(timeVector, dataMatrix);
00165 }
00166
00167 tempVector = m_AttitudeInterpolations[nearestTimeIndex]->Evaluate(_requestedTime.GetSeconds());
00168 _returnRotation.Set(Quaternion(~tempVector(_(1,4))));
00169 _returnAngVelVector(_) = tempVector(_(5,7));
00170 }
00171 else
00172 {
00173 _returnRotation = m_AttitudeHistory[nearestTimeIndex].GetRotation();
00174 _returnAngVelVector = m_AttitudeHistory[nearestTimeIndex].GetAngularVelocity();
00175 }
00176
00177 return;
00178 }
00179
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214