| 
   
    MIDI Control Surface library for Arduino 
   | 
 
 
 
 
Go to the documentation of this file.
    6 #include <AH/Arduino-Wrapper.h> // Print 
    9 #include <AH/STL/cmath>          
   10 #include <AH/STL/limits>         
   70     Quaternion(
float w, 
float x, 
float y, 
float z) : w(w), x(x), y(y), z(z) {}
 
   75         return *
this = hamiltonianProduct(*
this, rhs);
 
   80         return hamiltonianProduct(*
this, rhs);
 
  132     float normSquared()
 const { 
return w * w + x * x + y * y + z * z; }
 
  134     float norm()
 const { 
return std::sqrt(normSquared()); }
 
  162         float M11 = 1.0 - 2.0 * q.
y * q.
y - 2.0 * q.
z * q.
z;
 
  163         float M12 = 2.0 * (q.
x * q.
y - q.
w * q.
z);
 
  164         float M13 = 2.0 * (q.
x * q.
z + q.
w * q.
y);
 
  165         float M21 = 2.0 * (q.
x * q.
y + q.
w * q.
z);
 
  166         float M22 = 1.0 - 2.0 * q.
x * q.
x - 2.0 * q.
z * q.
z;
 
  167         float M23 = 2.0 * (q.
y * q.
z - q.
w * q.
x);
 
  168         float M31 = 2.0 * (q.
x * q.
z - q.
w * q.
y);
 
  169         float M32 = 2.0 * (q.
y * q.
z + q.
w * q.
x);
 
  170         float M33 = 1.0 - 2.0 * q.
x * q.
x - 2.0 * q.
y * q.
y;
 
  173             M11 * v.
x + M12 * v.
y + M13 * v.
z,
 
  174             M21 * v.
x + M22 * v.
y + M23 * v.
z,
 
  175             M31 * v.
x + M32 * v.
y + M33 * v.
z,
 
  181         return this->w == rhs.
w && this->x == rhs.
x && this->y == rhs.
y &&
 
  209         float eps = std::numeric_limits<float>::epsilon();
 
  212         float v_norm = v.
norm();
 
  217         float x = v.
x / v_norm;
 
  218         float y = v.
y / v_norm;
 
  221         if (std::abs(x) <= eps && std::abs(y) <= eps)
 
  226         Vec2f cross = {-y, x};
 
  227         float crossNorm = 
min(cross.
norm(), 1);
 
  231         float angle = std::asin(crossNorm);
 
  233             angle = M_PI - angle;
 
  238             std::sin(angle / 2) * cross.
x, 
 
  239             std::sin(angle / 2) * cross.
y, 
 
  263         return Quaternion::fromDirection(v);
 
  269             r.
w * q.
w - r.
x * q.
x - r.
y * q.
y - r.
z * q.
z,
 
  270             r.
w * q.
x + r.
x * q.
w - r.
y * q.
z + r.
z * q.
y,
 
  271             r.
w * q.
y + r.
x * q.
z + r.
y * q.
w - r.
z * q.
x,
 
  272             r.
w * q.
z - r.
x * q.
y + r.
y * q.
x + r.
z * q.
w,
 
  280     return {lhs * rhs.
w, lhs * rhs.
x, lhs * rhs.
y, lhs * rhs.
z};
 
  301         : yaw(yaw), pitch(pitch), roll(roll) {}
 
  310         return this->yaw == rhs.
yaw && this->pitch == rhs.
pitch &&
 
  311                this->roll == rhs.
roll;
 
  323         float phi = std::atan2(2.0 * (q.
w * q.
x + q.
y * q.
z),
 
  324                                1.0 - 2.0 * (q.
x * q.
x + q.
y * q.
y));
 
  325         float theta = std::asin(2.0 * (q.
w * q.
y - q.
z * q.
x));
 
  326         float psi = std::atan2(2.0 * (q.
w * q.
z + q.
x * q.
y),
 
  327                                1.0 - 2.0 * (q.
y * q.
y + q.
z * q.
z));
 
  328         return {psi, theta, phi};
 
  335         float cy = std::cos(eulerAngles.
yaw / 2);
 
  336         float sy = std::sin(eulerAngles.
yaw / 2);
 
  337         float cp = std::cos(eulerAngles.
pitch / 2);
 
  338         float sp = std::sin(eulerAngles.
pitch / 2);
 
  339         float cr = std::cos(eulerAngles.
roll / 2);
 
  340         float sr = std::sin(eulerAngles.
roll / 2);
 
  343             cy * cp * cr + sy * sp * sr,
 
  344             cy * cp * sr - sy * sp * cr,
 
  345             sy * cp * sr + cy * sp * cr,
 
  346             sy * cp * cr - cy * sp * sr,
 
  355 std::ostream &
operator<<(std::ostream &os, Quaternion q);
 
  359 std::ostream &
operator<<(std::ostream &os, EulerAngles e);
 
  
float y
The y component of the vector.
 
static Quaternion fromDirection(Vec3f v)
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v....
 
Quaternion conjugated() const
Complex conjugate (doesn't change the original quaternion).
 
float yaw
Z : drone Z = world +Z.
 
static EulerAngles quat2eul(Quaternion q)
Convert the given quaternion to Euler angles.
 
Quaternion operator*(float lhs, Quaternion rhs)
Scalar multiplication.
 
float x
The x component of the vector.
 
Type for quaternions of floating point numbers.
 
bool operator==(EulerAngles rhs) const
Equality check.
 
Quaternion & operator-=(Quaternion rhs)
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b.
 
static Quaternion hamiltonianProduct(Quaternion q, Quaternion r)
Quaternion multiplication.
 
constexpr auto min(const T &a, const U &b) -> decltype(b< a ? b :a)
Return the smaller of two numbers/objects.
 
float z
Third vector (imaginary) component .
 
Quaternion operator-() const
Negated quaternion is its conjugate.
 
bool operator!=(EulerAngles rhs) const
Inequality check.
 
#define AH_DIAGNOSTIC_POP()
 
Type for 3D vectors of floating point numbers.
 
float y
Second vector (imaginary) component .
 
Quaternion & normalize()
Normalize this quaternion.
 
Vec3f rotate(Vec3f v) const
Rotate vector by this quaternion.
 
Struct for Euler angles of floating point numbers.
 
EulerAngles(float yaw, float pitch, float roll)
Create Euler angles with the given values for yaw, pitch and roll.
 
float x
The x component of the vector.
 
float w
Scalar (real) component.
 
static Quaternion identity()
Identity quaternion (1,0,0,0).
 
float roll
X": drone X = world +Y.
 
static Quaternion eul2quat(EulerAngles eulerAngles)
Convert the given Euler angles to a quaternion.
 
Quaternion()=default
Create a quaternion that is initialized to the identity quaternion.
 
EulerAngles(Quaternion q)
Create Euler angles from the given quaternion.
 
bool operator==(Quaternion rhs) const
Equality check.
 
float pitch
Y': drone Y = world -X.
 
Quaternion & operator/=(float rhs)
Scalar division.
 
Quaternion normalized() const
Normalize a copy of this quaternion (doesn't change the original quaternion).
 
Conversions between radians and degrees.
 
static Quaternion fromXYAngle(float xAngle, float yAngle)
Calculate the quaternion from a vector that makes a given angle with the XZ plane and a given angle w...
 
Quaternion & operator*=(float rhs)
Scalar multiplication.
 
Quaternion & operator+=(Quaternion rhs)
Sum of two quaterions uses quaternion multiplication.
 
Type for 2D vectors of floating point numbers.
 
Quaternion operator-(Quaternion rhs) const
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b.
 
EulerAngles()=default
Create Euler angles that are initialized to (0 0 0), or upright.
 
#define AH_DIAGNOSTIC_WERROR()
 
#define BEGIN_AH_NAMESPACE
 
float z
The z component of the vector.
 
float y
The y component of the vector.
 
Quaternion operator/(float rhs) const
Scalar division.
 
Quaternion operator+(Quaternion rhs) const
Sum of two quaternions uses quaternion multiplication.
 
bool operator!=(Quaternion rhs) const
Inequality check.
 
Quaternion operator*(float rhs) const
Scalar multiplication.
 
Print & operator<<(Print &os, Quaternion e)
Printing.
 
float x
First vector (imaginary) component .
 
float normSquared() const
Norm squared.
 
Definition of Vec2f and Vec3f.
 
Quaternion(float w, float x, float y, float z)
Create a quaterion with the given values for w, x, y and z.