Commit e3470f14 authored by Jordan Lack's avatar Jordan Lack

More reference frame pointer conversions

parent 99d92f0d
Pipeline #55623086 (#920) failed with stages
in 3 minutes and 57 seconds
......@@ -28,11 +28,7 @@ namespace RobotDynamics
class FrameObject : public ReferenceFrameHolder
{
public:
explicit FrameObject(ReferenceFrame* referenceFrame) : referenceFrame(referenceFrame)
{
}
explicit FrameObject(ReferenceFramePtr referenceFrame) : referenceFrame(referenceFrame.get())
explicit FrameObject(ReferenceFramePtr referenceFrame) : referenceFrame(referenceFrame)
{
}
......@@ -47,46 +43,28 @@ class FrameObject : public ReferenceFrameHolder
* @brief Change the ReferenceFrame this FrameObject is expressed in.
* @param desiredFrame A pointer to the ReferenceFrame this FrameObject is to be transformed to
*/
virtual void changeFrame(ReferenceFrame* desiredFrame);
/**
* @brief Change the ReferenceFrame this FrameObject is expressed in
* @param desiredFrame A shared pointer to the ReferenceFrame this FrameObject is to be transformed to
*/
inline void changeFrame(ReferenceFramePtr desiredFrame)
{
this->changeFrame(desiredFrame.get());
}
virtual void changeFrame(ReferenceFramePtr desiredFrame);
/**
* @brief Get a pointer to the reference frame this FrameObject is expressed in
* @return Pointer to the ReferenceFrame this FrameObject is expressed in
*/
inline ReferenceFrame* getReferenceFrame() const
inline ReferenceFramePtr getReferenceFrame() const
{
return referenceFrame;
}
/**
* @brief Set frame objects internal reference frame
* @param frame Pointer to new frame
*/
inline void setReferenceFrame(ReferenceFrame* frame)
{
referenceFrame = frame;
}
/**
* @brief Set frame objects internal reference frame
* @param frame Pointer to new frame
*/
inline void setReferenceFrame(ReferenceFramePtr frame)
{
referenceFrame = frame.get();
referenceFrame = frame;
}
protected:
ReferenceFrame* referenceFrame /**< Pointer to a ReferenceFrame*/;
ReferenceFramePtr referenceFrame /**< Pointer to a ReferenceFrame*/;
/**
* @brief Pure virtual method that FrameObjects are required to implement so the FrameObject::changeFrame method is able
......
......@@ -34,11 +34,11 @@ class FrameOrientation : public FrameObject, public Quaternion
{
}
explicit FrameOrientation(ReferenceFrame* referenceFrame) : FrameObject(referenceFrame), Quaternion(0., 0., 0., 1.)
explicit FrameOrientation(ReferenceFramePtr referenceFrame) : FrameObject(referenceFrame), Quaternion(0., 0., 0., 1.)
{
}
FrameOrientation(ReferenceFrame* referenceFrame, Quaternion quat) : FrameObject(referenceFrame), Quaternion(quat)
FrameOrientation(ReferenceFramePtr referenceFrame, Quaternion quat) : FrameObject(referenceFrame), Quaternion(quat)
{
}
......@@ -46,10 +46,6 @@ class FrameOrientation : public FrameObject, public Quaternion
{
}
FrameOrientation(ReferenceFrame* referenceFrame, double x, double y, double z, double w) : FrameObject(referenceFrame), Quaternion(x, y, z, w)
{
}
/**
*
* @param referenceFrame
......@@ -57,7 +53,7 @@ class FrameOrientation : public FrameObject, public Quaternion
*
* @note assumes rotation is a valid, orthogonal rotation matrix
*/
FrameOrientation(ReferenceFrame* referenceFrame, const Matrix3d& E) : FrameObject(referenceFrame), Quaternion(E)
FrameOrientation(ReferenceFramePtr referenceFrame, const Matrix3d& E) : FrameObject(referenceFrame), Quaternion(E)
{
}
......@@ -66,34 +62,18 @@ class FrameOrientation : public FrameObject, public Quaternion
return this;
}
void setIncludingFrame(const Quaternion& q, ReferenceFrame* referenceFrame)
void setIncludingFrame(const Quaternion& q, ReferenceFramePtr referenceFrame)
{
this->referenceFrame = referenceFrame;
set(q);
}
FrameOrientation changeFrameAndCopy(ReferenceFrame* referenceFrame) const
FrameOrientation changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
{
FrameOrientation ret = *this;
ret.changeFrame(referenceFrame);
return ret;
}
void changeFrameAndCopy(ReferenceFrame* referenceFrame, FrameOrientation& frameOrientation) const
{
frameOrientation = *this;
frameOrientation.changeFrame(referenceFrame);
}
FrameOrientation changeFrameAndCopy(std::shared_ptr<ReferenceFrame> referenceFrame) const
{
return changeFrameAndCopy(referenceFrame.get());
}
void changeFrameAndCopy(std::shared_ptr<ReferenceFrame> referenceFrame, FrameOrientation& frameOrientation) const
{
changeFrameAndCopy(referenceFrame.get(), frameOrientation);
}
};
} // namespace Math
} // namespace RobotDynamics
......
......@@ -9,7 +9,7 @@
namespace RobotDynamics
{
void FrameObject::changeFrame(ReferenceFrame* desiredFrame)
void FrameObject::changeFrame(ReferenceFramePtr desiredFrame)
{
if (desiredFrame == nullptr || this->referenceFrame == nullptr)
{
......
......@@ -26,7 +26,7 @@ class FrameOrientationTest : public ::testing::Test
TEST_F(FrameOrientationTest, setters)
{
ReferenceFrame f1("f1", ReferenceFrame::getWorldFrame().get(), SpatialTransform(), true, 0);
ReferenceFrame f1("f1", ReferenceFrame::getWorldFrame(), SpatialTransform(), true, 0);
FrameOrientation orientation(&f1, Quaternion());
Quaternion q(1., 2., 3., 4.);
......@@ -51,7 +51,7 @@ TEST_F(FrameOrientationTest, setters)
TEST_F(FrameOrientationTest, changeFrame)
{
SpatialTransform X1 = Xrotz(M_PI_2);
ReferenceFrame f1("f1", ReferenceFrame::getWorldFrame().get(), X1, true, 0);
ReferenceFrame f1("f1", ReferenceFrame::getWorldFrame(), X1, true, 0);
SpatialTransform X2 = Xrotz(-M_PI_2);
ReferenceFrame f2("f2", &f1, X2, true, 1);
SpatialTransform X3 = Xrotz(-M_PI_2);
......@@ -79,13 +79,13 @@ TEST_F(FrameOrientationTest, changeFrame)
TEST_F(FrameOrientationTest, changeFrameAndCopy)
{
SpatialTransform X1 = Xrotz(M_PI_2);
std::shared_ptr<ReferenceFrame> f1(new ReferenceFrame("f1", ReferenceFrame::getWorldFrame().get(), X1, true, 0));
std::shared_ptr<ReferenceFrame> f1(new ReferenceFrame("f1", ReferenceFrame::getWorldFrame(), X1, true, 0));
SpatialTransform X2 = Xrotz(-M_PI_2);
std::shared_ptr<ReferenceFrame> f2(new ReferenceFrame("f2", f1.get(), X2, true, 1));
std::shared_ptr<ReferenceFrame> f2(new ReferenceFrame("f2", f1, X2, true, 1));
SpatialTransform X3 = Xrotz(-M_PI_2);
std::shared_ptr<ReferenceFrame> f3(new ReferenceFrame("f3", f2.get(), X3, true, 1));
std::shared_ptr<ReferenceFrame> f3(new ReferenceFrame("f3", f2, X3, true, 1));
FrameOrientation orientation(f2.get(), Quaternion());
FrameOrientation orientation(f2, Quaternion());
FrameOrientation orientation_copy = orientation.changeFrameAndCopy(f1);
Quaternion expected(Quaternion::fromMatrix(X2.E));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment