Skip to content

Commit

Permalink
Cleanup tests and tests utilities (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
SalvoVirga committed Sep 20, 2018
1 parent 4d85ef0 commit 37b4a3d
Show file tree
Hide file tree
Showing 35 changed files with 2,318 additions and 1,064 deletions.
2 changes: 2 additions & 0 deletions msgs/CMakeLists.txt
Expand Up @@ -48,6 +48,8 @@ set(SIMPLE_MSGS_SRCS
src/pose_stamped.cpp
src/rotation_matrix.cpp
src/rotation_matrix_stamped.cpp
src/transform.cpp
src/transform_stamped.cpp
)

# Generate the Flatbuffers headers.
Expand Down
11 changes: 11 additions & 0 deletions msgs/fbs/transform.fbs
@@ -0,0 +1,11 @@
// Schema for S.I.M.P.L.E. Homogeneous Transformation

namespace simple_msgs;

table TransformFbs {
point:[ubyte];
matrix:[ubyte];
}

root_type TransformFbs;
file_identifier "TRAN";
11 changes: 11 additions & 0 deletions msgs/fbs/transform_stamped.fbs
@@ -0,0 +1,11 @@
// Schema for S.I.M.P.L.E. Stamped Homogeneous Transformation

namespace simple_msgs;

table TransformStampedFbs {
transform:[ubyte];
header:[ubyte];
}

root_type TransformStampedFbs;
file_identifier "TRST";
2 changes: 2 additions & 0 deletions msgs/include/simple_msgs/all_messages.h
Expand Up @@ -28,5 +28,7 @@
#include "rotation_matrix.h"
#include "rotation_matrix_stamped.h"
#include "string.h"
#include "transform.h"
#include "transform_stamped.h"

#endif // SIMPLE_MSGS_ALL_H
4 changes: 2 additions & 2 deletions msgs/include/simple_msgs/rotation_matrix.h
Expand Up @@ -21,8 +21,8 @@
namespace simple_msgs {
/**
* @class RotationMatrix rotation_matrix.h.
* @brief Thread-safe wrapper for a Flatbuffers RotationMatrix message.
* It represents a 3x3 rotation matrix.
* @brief A thread-safe wrapper for a Flatbuffers RotationMatrix message.
* It represents a 3x3 rotation matrix stored in <b>row-major</b> order.
*/
class RotationMatrix : public GenericMessage {
public:
Expand Down
164 changes: 164 additions & 0 deletions msgs/include/simple_msgs/transform.h
@@ -0,0 +1,164 @@
/**
* S.I.M.P.L.E. - Smart Intuitive Messaging Platform with Less Effort
* Copyright (C) 2018 Salvatore Virga - salvo.virga@tum.de, Fernanda Levy
* Langsch - fernanda.langsch@tum.de
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#ifndef SIMPLE_MSGS_TRANSFORM_H
#define SIMPLE_MSGS_TRANSFORM_H

#include <array>
#include <ostream>

#include "generated/transform_generated.h"
#include "point.h"
#include "rotation_matrix.h"

namespace simple_msgs {
/**
* @class Transform transform.h.
* @brief Wrapper for a Flatbuffers Transform message.
* It represents a 4x4 homogeneous transformation, stored in <b>row-major</b> order.
*/
class Transform : public GenericMessage {
public:
Transform() = default;

/**
* @brief Construct a Transform message give its translation and its rotation part.
*/
Transform(const Point&, const RotationMatrix&);

/**
* @brief Construct a Transform message give its translation and its rotation part.
*/
Transform(Point&&, RotationMatrix&&);

/**
* @brief Construct a Transform message give a vector of 16 elements.
* The vector is expected to be in <b>row-major</b> order.
*/
Transform(const std::array<double, 16>&);

/**
* @brief Construct a Transform message give a vector of 16 elements.
* The vector is expected to be in <b>row-major</b> order.
*/
Transform(std::array<double, 16>&&) noexcept;

/**
* @brief Construct a Transform message using a raw memory coming from network.
*/
Transform(const void*);

/**
* @brief Copy constructor.
*/
Transform(const Transform&);

/**
* @brief Move constructor.
*/
Transform(Transform&&) noexcept;

/**
* @brief Copy assignment operator.
*/
Transform& operator=(const Transform&);

/**
* @brief Move assignment operator.
*/
Transform& operator=(Transform&&) noexcept;

/**
* @brief Copy assignment operator that uses raw memory coming from the network.
*/
Transform& operator=(std::shared_ptr<void*>);

/**
* @brief Returns true if lhs is equal to rhs, false otherwise.
*/
inline bool operator==(const Transform& rhs) const {
std::lock_guard<std::mutex> lock{mutex_};
return (point_ == rhs.point_ && matrix_ == rhs.matrix_);
}

/**
* @brief Returns true if lhs is not equal to rhs, false otherwise.
*/
inline bool operator!=(const Transform& rhs) const { return !(*this == rhs); }

/**
* @brief Stream extraction operator.
*/
friend std::ostream& operator<<(std::ostream&, const Transform&);

/**
* @brief Builds and returns the buffer accordingly to the values currently stored.
*/
std::shared_ptr<flatbuffers::DetachedBuffer> getBufferData() const override;

/**
* @brief Returns the rotational part of the homogeneous transformation.
*/
inline RotationMatrix& getRotation() {
std::lock_guard<std::mutex> lock{mutex_};
return matrix_;
}

/**
* @brief Returns the rotational part of the homogeneous transformation.
*/
inline const RotationMatrix& getRotation() const {
std::lock_guard<std::mutex> lock{mutex_};
return matrix_;
}

/**
* @brief Returns the translational part of the homogeneous transformation.
*/
inline Point& getTranslation() {
std::lock_guard<std::mutex> lock{mutex_};
return point_;
}

/**
* @brief Returns the translational part of the homogeneous transformation.
*/
inline const Point& getTranslation() const {
std::lock_guard<std::mutex> lock{mutex_};
return point_;
}

/**
* @brief Modifies the translational part of the Pose.
*/
void setTranslation(const Point&);

/**
* @brief Modifies the rotational part of the Pose.
*/
void setRotation(const RotationMatrix&);

/**
* @brief Returns an identifier of the message type generated by the flatbuffers.
*/
static inline std::string getTopic() { return TransformFbsIdentifier(); }

private:
//! Thread safe copy and move constructors.
Transform(const Transform& other, const std::lock_guard<std::mutex>&);
Transform(Transform&& other, const std::lock_guard<std::mutex>&) noexcept;

mutable std::mutex mutex_{};
Point point_{}; //! The translational part of the homogeneous transformation.
RotationMatrix matrix_{}; //! The rotational part of the homogeneous transformation.
};
} // Namespace simple_msgs.

#endif // SIMPLE_MSGS_TRANSFORM_H
152 changes: 152 additions & 0 deletions msgs/include/simple_msgs/transform_stamped.h
@@ -0,0 +1,152 @@
/**
* S.I.M.P.L.E. - Smart Intuitive Messaging Platform with Less Effort
* Copyright (C) 2018 Salvatore Virga - salvo.virga@tum.de, Fernanda Levy
* Langsch - fernanda.langsch@tum.de
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#ifndef SIMPLE_MSGS_TRANSFORM_STAMPED_H
#define SIMPLE_MSGS_TRANSFORM_STAMPED_H

#include <array>
#include <ostream>

#include "generated/transform_stamped_generated.h"
#include "header.h"
#include "transform.h"

namespace simple_msgs {
/**
* @class TransformStamped transform_stamped.h.
* @brief Thread-safe wrapper for a Flatbuffers TransformStamped message.
* It contains a Transform and a Header message.
*/
class TransformStamped : public GenericMessage {
public:
TransformStamped() = default;

/**
* @brief Construct a TransformStamped message given its Header and Transform.
*/
TransformStamped(const Header&, const Transform&);

/**
* @brief Construct a TransformStamped message given its Header and Transform.
*/
TransformStamped(Header&&, Transform&&);

/**
* @brief Construct a TransformStamped message using a raw memory coming from network.
*/
TransformStamped(const void*);

/**
* @brief Copy constructor.
*/
TransformStamped(const TransformStamped&);

/**
* @brief Move constructor.
*/
TransformStamped(TransformStamped&&) noexcept;

/**
* @brief Copy assignment operator.
*/
TransformStamped& operator=(const TransformStamped&);

/**
* @brief Move assignment operator.
*/
TransformStamped& operator=(TransformStamped&&) noexcept;

/**
* @brief Copy assignment operator that uses raw memory coming from the network.
*/
TransformStamped& operator=(std::shared_ptr<void*>);

/**
* @brief Returns true if lhs is equal to rhs, false otherwise.
*/
inline bool operator==(const TransformStamped& rhs) const {
std::lock_guard<std::mutex> lock{mutex_};
return (transform_ == rhs.transform_ && header_ == rhs.header_);
}

/**
* @brief Returns true if lhs is not equal to rhs, false otherwise.
*/
inline bool operator!=(const TransformStamped& rhs) const { return !(*this == rhs); }

/**
* @brief Stream extraction operator.
*/
friend std::ostream& operator<<(std::ostream&, const TransformStamped&);

/**
* @brief Builds and returns the buffer accordingly to the values currently stored.
*/
std::shared_ptr<flatbuffers::DetachedBuffer> getBufferData() const override;

/**
* @brief Returns the message Header.
*/
inline Header& getHeader() {
std::lock_guard<std::mutex> lock{mutex_};
return header_;
}

/**
* @brief Returns the message Header.
*/
inline const Header& getHeader() const {
std::lock_guard<std::mutex> lock{mutex_};
return header_;
}

/**
* @brief Returns the message Transform.
*/
inline Transform& getTransform() {
std::lock_guard<std::mutex> lock{mutex_};
return transform_;
}

/**
* @brief Returns the message Transform.
*/
inline const Transform& getTransform() const {
std::lock_guard<std::mutex> lock{mutex_};
return transform_;
}

/**
* @brief Modifies the message header.
*/
void setHeader(const Header&);

/**
* @brief Modifies the message Transform.
*/
void setTransform(const Transform&);

/**
* @brief Returns an identifier of the message type generated by the flatbuffers.
*/
static inline std::string getTopic() { return TransformStampedFbsIdentifier(); }

private:
//! Thread safe copy and move constructors.
TransformStamped(const TransformStamped& other, const std::lock_guard<std::mutex>&);
TransformStamped(TransformStamped&& other, const std::lock_guard<std::mutex>&) noexcept;

mutable std::mutex mutex_{};
Header header_{};
Transform transform_{};
};
} // Namespace simple_msgs.

#endif // SIMPLE_MSGS_TRANSFORM_STAMPED_H
8 changes: 4 additions & 4 deletions msgs/src/point_stamped.cpp
Expand Up @@ -77,14 +77,14 @@ std::shared_ptr<flatbuffers::DetachedBuffer> PointStamped::getBufferData() const
return std::make_shared<flatbuffers::DetachedBuffer>(builder.Release());
}

void PointStamped::setHeader(const Header& h) {
void PointStamped::setHeader(const Header& header) {
std::lock_guard<std::mutex> lock{mutex_};
header_ = h;
header_ = header;
}

void PointStamped::setPoint(const Point& p) {
void PointStamped::setPoint(const Point& point) {
std::lock_guard<std::mutex> lock{mutex_};
point_ = p;
point_ = point;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions msgs/src/pose_stamped.cpp
Expand Up @@ -16,8 +16,7 @@ PoseStamped::PoseStamped(const Header& header, const Pose& pose) : header_{heade
PoseStamped::PoseStamped(Header&& header, Pose&& pose) : header_{std::move(header)}, pose_{std::move(pose)} {}

PoseStamped::PoseStamped(const void* data)
: header_{GetPoseStampedFbs(data)->header()->data()} // namespace simple_msgs
, pose_{GetPoseStampedFbs(data)->pose()->data()} {}
: header_{GetPoseStampedFbs(data)->header()->data()}, pose_{GetPoseStampedFbs(data)->pose()->data()} {}

PoseStamped::PoseStamped(const PoseStamped& other, const std::lock_guard<std::mutex>&)
: PoseStamped{other.header_, other.pose_} {}
Expand Down

0 comments on commit 37b4a3d

Please sign in to comment.