compass rotate
hi,
i'm building robot arduino mega , cmps03 12c.
i put robot in different place, , make sure rotates spesific amount of degrees (90, 45 , on). in program rotate robot cw or ccw (not based compass value, select direction each time in program).
i have no problem read compass value, don't know how handle logic behind it.
my compass between 0-360, there's no negative values.
so, example, want rotate robot 90 degress.
if compass starting value 0, wait until compass read grater 90.
but however, if compass no 280 deg, final reading should 10 deg (280+360-90=10) , that's why can't substract current , starting values, otherwise i'll
the robot in different angels want know if have suggestion of programing it.
i thought situation, i'm sure that's theres many more others didn't mind (like when want robot rotate ccw instead of cw).
again, don't have code currently, want understand logic behind it, i'm pretty sure soultion multiple if cases (currentvalue-startvalue >=180) cant figgured out.
thanks helpers
i'm building robot arduino mega , cmps03 12c.
i put robot in different place, , make sure rotates spesific amount of degrees (90, 45 , on). in program rotate robot cw or ccw (not based compass value, select direction each time in program).
i have no problem read compass value, don't know how handle logic behind it.
my compass between 0-360, there's no negative values.
so, example, want rotate robot 90 degress.
if compass starting value 0, wait until compass read grater 90.
but however, if compass no 280 deg, final reading should 10 deg (280+360-90=10) , that's why can't substract current , starting values, otherwise i'll
the robot in different angels want know if have suggestion of programing it.
i thought situation, i'm sure that's theres many more others didn't mind (like when want robot rotate ccw instead of cw).
again, don't have code currently, want understand logic behind it, i'm pretty sure soultion multiple if cases (currentvalue-startvalue >=180) cant figgured out.
thanks helpers
quote
my compass between 0-360, there's no negative values.easy subtract 180 value. want this.
always have setpoint zero
make adjustment value getting compass , use offset of zero
working example: balancing bot truing 90° every 5 seconds have turned angle here code pertaining turning:
code: [select]
//pid configuration in beginning of code uses pid_v1 library
double degsetpoint = 0; // degree setpoint should zero!
double yawinput; //(yawinput = yawmpu + yawoffset) rollover @ +-180°
double turn; // outout drive motors
double yconskp = 30, yconski = 0, yconskd = .1; // pid values turning these should good!
pid myturnpid(&yawinput, &turn, °setpoint, yconskp, yconski, yconskd, reverse); // make so
the math routine
void mpumath() {
mpu.dmpgetquaternion(&q, fifobuffer);
mpu.dmpgetgravity(&gravity, &q);
mpu.dmpgetyawpitchroll(ypr, &q, &gravity);
yawmpu = (ypr[0] * 180 / m_pi) ;
yawinput = yawmpu + yawoffset;
if (yawinput > 180) yawinput -= 360; // rollover negative
if (yawinput < -180) yawinput += 360; // rollover positive
yawinput = yawinput;
myturnpid.compute();// calculates amount of "turn" place motors. robot value of +-80 1 motor opposite other while balancing causing rotate pid adjusts power motors lands on new setpoint
directdrive(output, turn);
}
i use pid routine calculate how output directs robot point 0
the following code used in control robot's turning
code: [select]
static long qtimer = millis();
if ( (long)( millis() - qtimer ) >= 5000 ) {
qtimer = millis()
yawoffset += 90;
if (yawoffset > 180) yawoffset -= 360; // rollover negative
if (yawoffset < -180) yawoffset += 360; // rollover positive
}
Arduino Forum > Using Arduino > Programming Questions > compass rotate
arduino
Comments
Post a Comment