Hi Tim. Instead of using the dt with the pause delay included did you try setting it up so at start of pause it saves the lastDt = dt and end of pause reset dt to lastDt seen?
Circular_Buffer<XXX, 16> myFloats;
myFloats.push_back(3.14159);
myFloats.push_back(12.3456);
myFloats.push_back(78.91234);
myFloats.push_back(7.91234);
myFloats.push_back(11.91234);
myFloats.push_back(58.91234);
myFloats.push_back(18.91234);
// myFloats.push_back(2.91234);
Serial.print("SUM: "); Serial.println(myFloats.sum(), 5);
Serial.print("MIN: "); Serial.println(myFloats.min(), 5);
Serial.print("MAX: "); Serial.println(myFloats.max(), 5);
Serial.print("MEDIAN: "); Serial.println(myFloats.median(1), 5);
uint8_t blah[5];
// qsort(blah, 5, sizeof(uint8_t), *(uint8_t*)a - *(uint8_t*)b);
Serial.print("AVG: "); Serial.println(myFloats.average(), 5);
uint8_t _size = myFloats.size();
Serial.print("Deviation: "); Serial.println(myFloats.deviation(), 8);
for ( uint8_t i = 0; i < _size; i++ ) {
Serial.print(myFloats.pop_front(), 5); Serial.print(" ");
} Serial.println();
while(1);
SUM: [COLOR="#FF0000"]192.04887[/COLOR]
MIN: 3.14159
MAX: 78.91234
MEDIAN: 12.34560
AVG: 27.43556
Deviation: [COLOR="#FF0000"]27.13280106[/COLOR]
3.14159 7.91234 11.91234 12.34560 18.91234 58.91234 78.91234
SUM: [COLOR="#FF0000"]192.04889[/COLOR]
MIN: 3.14159
MAX: 78.91234
MEDIAN: 12.34560
AVG: 27.43556
Deviation: [COLOR="#FF0000"]27.13280006[/COLOR]
3.14159 7.91234 11.91234 12.34560 18.91234 58.91234 78.91234
Tim - might be interesting to try, you took it to another level when I was only thinking about pause. Think you would have to becareful with dt though. Right now this is the only thing running on the Teensy, but if we start adding other code for other functions besides a AHRS/INS system dt may get screwy especially if you are talking about high data rates. You may be talking about just dedicating a single T3.5 for this function and another for other functions.probably better to skip and start fresh as something went wrong?
Tim - might be interesting to try, you took it to another level when I was only thinking about pause. Think you would have to becareful with dt though. Right now this is the only thing running on the Teensy, but if we start adding other code for other functions besides a AHRS/INS system dt may get screwy especially if you are talking about high data rates. You may be talking about just dedicating a single T3.5 for this function and another for other functions.
Don - didn't think the mag had a separate interrupt. You can always check out the FIFO option![]()
float This_Mag[4];
This_Mag[0] = Imu.getMagX_uT();
This_Mag[1] = Imu.getMagY_uT();
This_Mag[2] = Imu.getMagZ_uT();
This_Mag[3] = This_Mag[0] + This_Mag[1] + This_Mag[2];
if ( This_Mag[3] != Last_Mag ) Mcnt++;
else McntN++;
Last_Mag = This_Mag[3];
Filter.update(uBloxData.iTOW, uBloxData.velN, uBloxData.velE, uBloxData.velD,
uBloxData.lat * D2R, uBloxData.lon * D2R, uBloxData.hMSL,
Imu.getGyroX_rads(), Imu.getGyroY_rads(), Imu.getGyroZ_rads(),
Imu.getAccelX_mss(), Imu.getAccelY_mss(), Imu.getAccelZ_mss(),
This_Mag[0], This_Mag[1], This_Mag[2]);
// added to HEADER :: \libraries\MPU9250\MPU9250.h
void int readSensorPMD(float* ax, float* ay, float* az, float* gx, float* gy, float* gz, float* hx, float* hy, float* hz, bool* MagD);
// Added to \libraries\MPU9250\MPU9250.cpp
int MPU9250::readSensorPMD(float* ax, float* ay, float* az, float* gx, float* gy, float* gz, float* hx, float* hy, float* hz, bool* MagD)
{
_useSPIHS = true; // use the high speed SPI for data readout
// grab the data from the MPU9250
if (readRegisters(ACCEL_OUT, 21, _buffer) < 0) {
return -1;
}
// combine into 16 bit values
_axcounts = (((int16_t)_buffer[0]) << 8) | _buffer[1];
_aycounts = (((int16_t)_buffer[2]) << 8) | _buffer[3];
_azcounts = (((int16_t)_buffer[4]) << 8) | _buffer[5];
_tcounts = (((int16_t)_buffer[6]) << 8) | _buffer[7];
_gxcounts = (((int16_t)_buffer[8]) << 8) | _buffer[9];
_gycounts = (((int16_t)_buffer[10]) << 8) | _buffer[11];
_gzcounts = (((int16_t)_buffer[12]) << 8) | _buffer[13];
_hxcounts = (((int16_t)_buffer[15]) << 8) | _buffer[14];
_hycounts = (((int16_t)_buffer[17]) << 8) | _buffer[16];
_hzcounts = (((int16_t)_buffer[19]) << 8) | _buffer[18];
// transform and convert to float values
*ax = _ax = (((float)(tX[0] * _axcounts + tX[1] * _aycounts + tX[2] * _azcounts) * _accelScale) - _axb) * _axs;
*ay = _ay = (((float)(tY[0] * _axcounts + tY[1] * _aycounts + tY[2] * _azcounts) * _accelScale) - _ayb) * _ays;
*az = _az = (((float)(tZ[0] * _axcounts + tZ[1] * _aycounts + tZ[2] * _azcounts) * _accelScale) - _azb) * _azs;
*gx = _gx = ((float)(tX[0] * _gxcounts + tX[1] * _gycounts + tX[2] * _gzcounts) * _gyroScale) - _gxb;
*gy = _gy = ((float)(tY[0] * _gxcounts + tY[1] * _gycounts + tY[2] * _gzcounts) * _gyroScale) - _gyb;
*gz = _gz = ((float)(tZ[0] * _gxcounts + tZ[1] * _gycounts + tZ[2] * _gzcounts) * _gyroScale) - _gzb;
[B]*hx[/B] = (((float)(_hxcounts) * _magScaleX) - _hxb) * _hxs;
[B]*hy[/B] = (((float)(_hycounts) * _magScaleY) - _hyb) * _hys;
[B]*hz[/B] = (((float)(_hzcounts) * _magScaleZ) - _hzb) * _hzs;
if ( [COLOR="#FF0000"](*hx == _hx) && (*hy == _hy) && (*hz == _hz)[/COLOR] ) {
*MagD = false;
}
else {
*MagD = true;
[B] _hx = *hx;
_hy = *hy;
_hz = *hz;
[/B] }
_t = ((((float) _tcounts) - _tempOffset) / _tempScale) + _tempOffset;
return 1;
}
// read the IMU sensor
[COLOR="#FF0000"] // Imu.readSensor();
[/COLOR] [U]float ax; float ay; float az; float gx; float gy; float gz; float hx; float hy; float hz; bool MagD;[/U]
[B]Imu.readSensorPMD( &ax, &ay, &az, &gx, &gy, &gz, &hx, &hy, &hz, &MagD);[/B]
//Serial.println("IMU sensor read");
//Serial.println(Imu.getGyroX_rads()*R2D);
if ( MagD ) Mcnt++; // DEBUG print values showing when Mag Diff was detected!
else McntN++;
Filter.update(uBloxData.iTOW, uBloxData.velN, uBloxData.velE, uBloxData.velD,
uBloxData.lat * D2R, uBloxData.lon * D2R, uBloxData.hMSL,
ax, ay, az, gx, gy, gz, hx, hy, hz );
[COLOR="#FF0000"]// Imu.getGyroX_rads(), Imu.getGyroY_rads(), Imu.getGyroZ_rads(),
// Imu.getAccelX_mss(), Imu.getAccelY_mss(), Imu.getAccelZ_mss(),
// This_Mag[0], This_Mag[1], This_Mag[2]);
[/COLOR]
Don-Tim
I incorporated the changes from post #493 and all is running fine from my end. I am seeing a couple of things with this run:
...
Tim - from my point of view yes. I have used it for other purposes like sensor calibrations - there does tend to be a temp dependency for the gyro and a little for the accel. So from my point of view I would leave it in.
In Brian's old library there used to be a function call to readSensor9 just to get the accel/gyro/mag data.
BTW. To be honest I prefer your method to get the 9 values instead of the individual calls.
Mike