c++ - Arduino, Calculating the resultant direction of the magnitude of three microphones -
i trying calculate direction theta range 0 - 2 pi indicate direction of resultant vector of 3 microphones placed @ 0 degree, 120, , 240 degree marks. of microphones working somehow can't seem correct degree values. can @ code?
void detdirection(){ //mic1 float x0 =0; float y0 =volts[0]; //serial.println(x0); // serial.println(y0); //mic2 float x1 =volts[1]*cos(120.0/360 * 2*pi); float y1 =volts[1]*sin(120.0/360 * 2*pi); // serial.println(x1); //serial.println(y1); //mic3 float x2 =volts[2]*cos(240.0/360 * 2*pi); float y2 = volts[2]*sin(240.0/360 * 2*pi); //serial.println(x2); //serial.println(y2); //calculate resultant float sumx = x0 + x1 + x2; float sumy = y0 + y1 + y2; //serial.println(sumx); //serial.println(sumy); float resultant = pow(pow(sumx,2)+pow(sumy,2),0.5); float degree = atan2(sumy,sumx); float fixdegree= 0 ; //fix degree if(!isneg(sumx) && !isneg(sumy)){ fixdegree = degree; } else if(isneg(sumx) && !isneg(sumy)){ fixdegree = pi - degree; } else if(isneg(sumx) && isneg(sumy)){ fixdegree = pi+ degree; } else if (!isneg(sumx) && isneg(sumy)){ fixdegree = 2*pi - degree; } string text = ""; text.concat(resultant); text.concat(" "); text.concat(fixdegree); text.concat(" "); //serial.println(text); }
well... i'm not sure but... if write
//mic2 float x1 =volts[1]*cos(120.0/360 * 2*pi); float y1 =volts[1]*sin(120.0/360 * 2*pi);
and
//mic3 float x2 =volts[2]*cos(240.0/360 * 2*pi); float y2 = volts[2]*sin(240.0/360 * 2*pi);
i suppose intention mic1 (x0
, y0
) was
//mic1 float x0 =volts[0]*cos(0.0/360 * 2*pi); float y0 =volts[0]*sin(0.0/360 * 2*pi);
that is
//mic1 float x0 =volts[0]*cos(0.0); float y0 =volts[0]*sin(0.0);
and, remembering cos(0.0)
1 ans sin(0.0)
0,
//mic1 float x0 =volts[0]; float y0 =0.0;
but in code see
//mic1 float x0 =0; float y0 =volts[0];
briefly, suspect you've switched x0
y0
.
p.s.: sorry bad english.