#include <random>
#include <ros/ros.h>
{
static constexpr double minimum = -180;
static constexpr double supremum = 180;
};
template <class T>
void printit(const T& a, const std::string& name)
{
std::cout << name << ":\t" << std::left << std::showpos << std::setprecision(4) << a.value() << "\tin [ " << a.minimum << ",\t" << a.supremum << "\t["
<< std::endl;
}
template <class T>
void printcont(const T& cont, const std::string& name)
{
std::cout << name << ":\t";
for (const auto& el : cont)
std::cout << el << "\t";
std::cout << std::endl;
}
int main()
{
printit(a, "a");
printit(b, "b");
printit(c, "c");
printit(d, "d");
printit(e, "e");
printit(f, "f");
printit(g, "g");
printit(h, "h");
printit(WRONG1, "WRONG1");
double adouble = a.value();
double amin = a.minimum;
double asup = degrees::supremum;
std::cout << "adouble:" << std::left << std::showpos << std::setprecision(4) << adouble << "\tin [ " << amin << ",\t" << asup << "\t[\trange: " << aran
<< std::endl;
std::cout << "----------------------------------------------------------------" << std::endl;
double ang = 666;
{
std::cout << std::left << std::showpos << std::setprecision(4) << ang << "\tis not within [ " << degrees::minimum << ",\t" << degrees::supremum << "\t["
<< std::endl;
std::cout << std::left << std::showpos << std::setprecision(4) << ang << "\tafter wrapping: " << wang << std::endl;
}
std::vector<double> data = {0, 61, 122, 183, 244, 305, 6, 67, 128, 189};
printcont(data, "data before unwrapping");
for (size_t it = 1; it < data.size(); it++)
{
const auto prev = data.at(it - 1);
auto& cur = data.at(it);
}
printcont(data, "data after unwrapping");
for (auto& el : data)
printcont(data, "data after wrapping");
for (size_t it = 1; it < data.size(); it++)
{
const auto prev = data.at(it - 1);
auto& cur = data.at(it);
}
printcont(data, "data after unwrapping");
std::cout << "----------------------------------------------------------------" << std::endl;
std::cout << std::left << std::showpos << std::setprecision(4) << "A:\t" << A.value() << std::endl
<< "B:\t" << B.value() << std::endl
std::cout << std::left << std::showpos << std::setprecision(4) << "C:\t" << C.value() << std::endl
<< "D:\t" << D.value() << std::endl
std::cout << std::left << std::showpos << std::setprecision(4) << "E:\t" << E.value() << std::endl
<< "F:\t" << F.value() << std::endl
std::cout << "----------------------------------------------------------------" << std::endl;
double a1 = -359;
double a2 = -2;
double coeff = 1.0 / 3.0;
std::cout << std::left << std::showpos << std::setprecision(4) << "a1:\t" << a1 << std::endl
<< "a2:\t" << a2 << std::endl
<< "coeff:\t" << coeff << std::endl
<<
"interp(a1, a2, coeff):\t" <<
degrees::interp(a1, a2, coeff) << std::endl
return 0;
}
Defines the cyclic class for calculations with cyclic quantities.
Definition cyclic_example.cpp:23
Implementation of the a general cyclic value (such as angles in radians/degrees etc).
Definition cyclic.h:49
static float interpUnwrapped(const float from, const float to, const float coeff)
Interpolation between two circular quantities without wrapping of the result.
Definition cyclic.h:242
static float unwrap(const float what, const float from)
Returns value of the parameter what modified so that there is no "jump" between from and \t what.
Definition cyclic.h:157
static constexpr float range
Range of the valid interval of wrapped values (also the period of the cyclic quantity).
Definition cyclic.h:87
static float pdist(const float from, const float to)
Returns length of the shortest walk in the positive direction from the first parameter to the second ...
Definition cyclic.h:171
static other_t convert(const cyclic &what)
Conversion between two different circular quantities.
Definition cyclic.h:334
static float dist(const float from, const float to)
Returns the distance between the two circular values.
Definition cyclic.h:219
static float diff(const float minuend, const float subtrahend)
Returns the difference between the two circular values.
Definition cyclic.h:193
other_t convert() const
Conversion between two different circular quantities.
Definition cyclic.h:351
cyclic()
Default constructor.
Definition cyclic.h:55
static float wrap(const float val)
Returns val, converted to the valid interval of values.
Definition cyclic.h:114
static bool inRange(const float val)
Checks if val is within the valid interval of wrapped values.
Definition cyclic.h:100
static float interp(const float from, const float to, const float coeff)
Interpolation between two circular quantities.
Definition cyclic.h:264
Convenience specialization of the cyclic class for unsigned radians (from $0$ to $2\pi$).
Definition cyclic.h:490
Convenience specialization of the cyclic class for signed radians (from $-\pi$ to $\pi$).
Definition cyclic.h:500