Numero Uno / Mbed 2 deprecated MotorDriver

Dependencies:   HIDScope QEI mbed

Fork of BMT-K9_potmeter_fade by First Last

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Point.cpp Source File

Point.cpp

00001 // Example: data structs and functions
00002 #include <stdio.h>
00003 #include <math.h>
00004 
00005 const double M_PI =3.141592653589793238463;
00006 const float l = 10; // distance between the motors
00007 const float armlength=15; // length of the arms from the motor
00008     
00009 class Point
00010 {
00011     public:
00012     
00013     float posX;
00014     float posY;
00015     float rotA;
00016     float rotB;
00017 
00018     bool fromCarthesian(float x, float y)
00019     {
00020         posX = x;
00021         posY = y;
00022         rotA = atan(y/x)*180/M_PI;
00023         rotB = atan(y/(l-x))*180/M_PI;
00024         
00025         // function is done, return the struct type Point:
00026         return true;
00027     }
00028     bool fromRotational(float a, float b)
00029     {
00030         rotA = a*M_PI/180;
00031         rotB = b*M_PI/180;
00032         posX = (tan(rotB)*l)/(tan(rotA)+tan(rotB));
00033         posY = tan(rotA)*posX;
00034         
00035         return true;
00036         
00037     }
00038     bool checkbounds()
00039     {
00040         if (rotA <= 0 or rotB <= 0){
00041             return 0;
00042         }
00043         if (rotA > 90 or rotB > 90){
00044             return 0;
00045         }
00046         if (sqrt(pow(posX,2)+pow(posY,2)) > armlength){ // too far from left arm
00047             return 0;
00048         }
00049         if (sqrt(pow(l-posX,2)+pow(posY,2)) > armlength){ // too far from right arm
00050             return 0;
00051         }
00052         return true;
00053     }
00054 };
00055 
00056 
00057