EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
helper.h
Go to the documentation of this file.
1#ifndef HELPER_H
2#define HELPER_H
3
4#include "encoder.h"
5#include "mbed.h"
6#include <functional>
7
17template <class T>
18constexpr const T &clamp(const T &v, const T &lo, const T &hi) {
19 return std::less<T>{}(v, lo) ? lo : std::less<T>{}(hi, v) ? hi
20 : v;
21}
22
30template <class T>
31constexpr const T speed_to_pps(const T &speed) {
32 return speed * 512 / Encoder::CIRCUMFERENCE;
33}
34
42template <class T>
43constexpr const T radiansToDegrees(const T &angle) {
44 return angle * 180.0 / M_PI;
45}
46
47#endif
static constexpr double CIRCUMFERENCE
Circumference of the wheel.
Definition: encoder.h:67
#define M_PI
Define M_PI on ArmC6.
Definition: encoder.h:21
constexpr const T radiansToDegrees(const T &angle)
Convert radians to degree.
Definition: helper.h:43
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Clamp the value between [lo,high].
Definition: helper.h:18
constexpr const T speed_to_pps(const T &speed)
Convert m/s to pulse per sec(PPS).
Definition: helper.h:31