mirror of
https://github.com/modelec/Modelec-ROS2.git
synced 2026-05-09 04:45:37 +02:00
Page:
modelec‐utils
No results
Table of Contents
Modelec is a team of student who are competiting in Coupe de France de Robotique
modelec-utils
Modelec utils package is used by all other package. It export some utility functions and some utility class
Config
Class to load config from .xml file
Definition
namespace Modelec
{
class Config
{
public:
static bool load(const std::string& filepath);
template<typename T>
static T get(const std::string& key, const T& default_value = T());
private:
static void parseNode(tinyxml2::XMLElement* element, const std::string& prefix);
static inline std::unordered_map<std::string, std::string> values_;
};
}
Point
Class to use the same Point def in all other packages
Defition
namespace Modelec
{
struct Point {
int x;
int y;
double theta;
Point() : x(0), y(0), theta(0) {}
Point(int x, int y, double theta) : x(x), y(y), theta(theta) {}
static double distance(const Point& p1, const Point& p2);
static double angleDiff(const Point& p1, const Point& p2);
double distance(const Point& p2) const;
double angleDiff(const Point& p2) const;
[[nodiscard]] Point GetTakePosition(int distance, double angle) const;
[[nodiscard]] Point GetTakePosition(int distance) const;
[[nodiscard]] Point GetTakeBasePosition() const;
[[nodiscard]] Point GetTakeClosePosition() const;
};
}
Utils
Utility function
Definition
namespace Modelec {
std::vector<std::string> split(const std::string &s, char delim);
std::string join(const std::vector<std::string> &v, const std::string &delim);
bool startsWith(const std::string &s, const std::string &prefix);
bool endsWith(const std::string &s, const std::string &suffix);
bool contains(const std::string &s, const std::string &substring);
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
T mapValue(T v, T v_min, T v_max, T v_min_prime, T v_max_prime) {
return v_min_prime + (((v - v_min) * (v_max_prime - v_min_prime)) / (v_max - v_min));
}
std::string trim(const std::string &s);
}