2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers supportfuncs.h Source File

supportfuncs.h

00001 #ifndef SUPPORTFUNCS_H
00002 #define SUPPORTFUNCS_H
00003 
00004 #include <cmath>
00005 #include "globals.h"
00006 #include "tvmet/Matrix.h"
00007 
00008 template <typename T> int sgn(T val) {
00009     return (T(0) < val) - (val < T(0));
00010 }
00011 
00012 //Constrains agles to +/- pi
00013 inline float constrainAngle(float x){
00014     x = fmod(x + PI, 2*PI);
00015     if (x < 0)
00016         x += 2*PI;
00017     return x - PI;
00018 }
00019 
00020 template <typename T>
00021 tvmet::Matrix <T, 2, 2> Rotmatrix(T theta) {
00022      tvmet::Matrix <T, 2, 2> outmatrix;
00023      outmatrix = cos(theta), -sin(theta),
00024                  sin(theta), cos(theta);
00025      return outmatrix;
00026 }
00027 
00028 #endif //SUPPORTFUNCS_H