Skip to content

Commit 33a2101

Browse files
committed
Set IMU timestamp to time of validity vs. data ready. Tweaked Ubx PPS output
1 parent 8e491b0 commit 33a2101

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

boards/varmint_h7/common/drivers/Adc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,11 @@ void Adc::endDma(ADC_HandleTypeDef * hadc)
188188
double vcc = p.vRef;
189189
#endif
190190
for (int i = 0; i < ADC_CHANNELS; i++) {
191-
// p.volts[i] = ((double)(adc_counts[i]&0xFFFF)/65535.0 - cfg_[i].offset) * p.vRef * cfg_[i].scaleFactor;
192-
p.volts[i] = ((double) (adc_counts[i] & 0xFFFF) / 65535.0 * p.vRef - vcc * cfg_[i].offset) * cfg_[i].scaleFactor;
191+
p.volts[i] = ((double) (adc_counts[i] & 0xFFFF) / 65535.0 * p.vRef - cfg_[i].offset) * cfg_[i].scaleFactor;
193192
}
194193

195-
p.header.timestamp = drdy_;
196194
p.header.complete = time64.Us();
195+
p.header.timestamp = (drdy_+p.header.complete)/2;
197196
write((uint8_t *) &p, sizeof(p));
198197
ext_read = 0;
199198
int_read = 0;

boards/varmint_h7/common/drivers/Adis165xx.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ uint32_t Adis165xx::init(
9292
htim_ = htim;
9393
htimChannel_ = htim_channel;
9494

95-
// groupDelay_ = (uint64_t) 1510
96-
// + (uint64_t) 500000 / sampleRateHz_; // us, Approximate, Accel is 1.57ms, Gyro x&y are 1.51ms, and Gyro z is 1.29ms.
95+
groupDelay_ = (uint64_t) 1510 + (uint64_t) 500000 / sampleRateHz_- 250;
96+
// us, Approximate, Accel is 1.57ms, Gyro x&y are 1.51ms, and Gyro z is 1.29ms.
9797

9898
HAL_GPIO_WritePin(spi_.port_, spi_.pin_, GPIO_PIN_SET);
9999
HAL_GPIO_WritePin(resetPort_, resetPin_, GPIO_PIN_SET);
@@ -224,6 +224,8 @@ bool Adis165xx::startDma(void) // called to start dma read
224224
void Adis165xx::endDma(void) // called when DMA data is ready
225225
{
226226
uint8_t * rx = spi_.endDma();
227+
ImuPacket p = {0};
228+
227229
if (sampleRateHz_ == 2000) {
228230
// compute checksum
229231
uint16_t sum = 0;
@@ -233,9 +235,7 @@ void Adis165xx::endDma(void) // called when DMA data is ready
233235
for (int i = 0; i < ADIS_BUFFBYTES16 / 2; i++)
234236
data[i] = (int16_t) rx[2 * i] << 8 | ((int16_t) rx[2 * i + 1] & 0x00FF);
235237
if (sum == data[10]) {
236-
ImuPacket p;
237-
p.header.timestamp = drdy_;
238-
p.header.complete = time64.Us(); p.header.status = (uint16_t) data[1];
238+
p.header.status = (uint16_t) data[1];
239239
p.gyro[0] = -(double) data[2] * 0.001745329251994; // rad/s, or use 0.1 deg/s
240240
p.gyro[1] = -(double) data[3] * 0.001745329251994; // rad/s, or use 0.1 deg/s
241241
p.gyro[2] = (double) data[4] * 0.001745329251994; // rad/s, or use 0.1 deg/s
@@ -244,7 +244,6 @@ void Adis165xx::endDma(void) // called when DMA data is ready
244244
p.accel[2] = (double) data[7] * 0.01225; // m/s^2
245245
p.temperature = (double) data[8] * 0.1 + 273.15; // K
246246
p.dataTime = (double) ((uint16_t) data[9]) / sampleRateHz_;
247-
if (p.header.status == ADIS_OK) write((uint8_t *) &p, sizeof(p));
248247
}
249248
} else {
250249
// compute checksum
@@ -256,9 +255,6 @@ void Adis165xx::endDma(void) // called when DMA data is ready
256255
data[i] = (int16_t) rx[2 * i] << 8 | ((int16_t) rx[2 * i + 1] & 0x00FF);
257256

258257
if (sum == data[16]) {
259-
ImuPacket p;
260-
p.header.timestamp = drdy_;
261-
p.header.complete = time64.Us();
262258
p.header.status = (uint16_t) data[1];
263259
p.gyro[0] = val(rx + 4) * 0.001745329251994; // rad/s, or use 0.1 deg/s
264260
p.gyro[1] = val(rx + 8) * 0.001745329251994; // rad/s, or use 0.1 deg/s
@@ -268,14 +264,17 @@ void Adis165xx::endDma(void) // called when DMA data is ready
268264
p.accel[2] = val(rx + 24) * 0.01225; // m/s^2
269265
p.temperature = (double) data[14] * 0.1 + 273.15; // K
270266
p.dataTime = (double) ((uint16_t) data[15]) / sampleRateHz_;
271-
if (p.header.status == ADIS_OK)
272-
{
273-
rotate(p.gyro);
274-
rotate(p.accel);
275-
write((uint8_t *) &p, sizeof(p));
276-
}
277267
}
278268
}
269+
if (p.header.status == ADIS_OK)
270+
{
271+
p.header.timestamp = drdy_-groupDelay_;
272+
rotate(p.gyro);
273+
rotate(p.accel);
274+
p.header.complete = time64.Us();
275+
write((uint8_t *) &p, sizeof(p));
276+
}
277+
279278
}
280279

281280
void Adis165xx::writeRegister(uint8_t address, uint16_t value)

boards/varmint_h7/common/drivers/Adis165xx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Adis165xx : public Status , public MiscRotatable
7878
DoubleBuffer double_buffer_;
7979

8080
uint16_t sampleRateHz_;
81+
uint64_t groupDelay_;
8182
// SPI Stuff
8283
Spi spi_;
8384
uint16_t drdyPin_;

boards/varmint_h7/common/drivers/Bmi088.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ uint32_t Bmi088::init(
9797
if (sampleRateHz_ <= 400) {
9898
sampleRateHz_ = 400;
9999
syncCfgMode_ = BMI08_ACCEL_DATA_SYNC_MODE_400HZ;
100-
// groupDelay_ = 7000;
100+
groupDelay_ = 7000;
101101
} else if (sampleRateHz_ <= 1000) {
102102
sampleRateHz_ = 1000;
103103
syncCfgMode_ = BMI08_ACCEL_DATA_SYNC_MODE_1000HZ;
104-
// groupDelay_ = 2500;
104+
groupDelay_ = 2500;
105105
} else if (sampleRateHz_ <= 2000) {
106106
sampleRateHz_ = 2000;
107107
syncCfgMode_ = BMI08_ACCEL_DATA_SYNC_MODE_2000HZ;
108-
// groupDelay_ = 1500;
108+
groupDelay_ = 1500;
109109
} else {
110110
sampleRateHz_ = 400;
111111
syncCfgMode_ = BMI08_ACCEL_DATA_SYNC_MODE_400HZ;
112-
// groupDelay_ = 7000;
112+
groupDelay_ = 7000;
113113
}
114114

115115
time64.dMs(50); // Some time to ensure power-on completed.
@@ -331,7 +331,7 @@ void Bmi088::endDma(void) // DMA complete routine
331331
p.gyro[2] = scale_factor * (double) data;
332332

333333
p.header.complete = time64.Us();
334-
p.header.timestamp = drdy_;
334+
p.header.timestamp = drdy_-groupDelay_;
335335

336336
rotate(p.gyro);
337337
rotate(p.accel);

boards/varmint_h7/common/drivers/Bmi088.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Bmi088 : public Status, public MiscRotatable
8282
bool write(uint8_t * data, uint16_t size) { return double_buffer_.write(data, size)==DoubleBufferStatus::OK; }
8383
DoubleBuffer double_buffer_;
8484
uint16_t sampleRateHz_;
85+
uint64_t groupDelay_;
8586
// SPI Stuff
8687
Spi spiA_;
8788
Spi spiG_;

boards/varmint_h7/common/drivers/Ubx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ uint16_t Ubx::cfgTp5(uint32_t hz)
471471
payload[3] = 0x00; // reserved
472472
SET(payload + 4, 0x0000, int16_t); // antenna delay
473473
SET(payload + 6, 0x0000, int16_t); // rf delay
474-
SET(payload + 8, 0, uint32_t); // frequency when not locked
474+
SET(payload + 8, hz, uint32_t); // frequency when not locked
475475
SET(payload + 12, hz, uint32_t); // frequency when locked
476-
SET(payload + 16, pulse_len_us, uint32_t); // pulse length (1ms)
477-
SET(payload + 20, pulse_len_us, uint32_t); // pulse length (1ms)
476+
SET(payload + 16, 0, uint32_t); // pulse length when not locked (1ms)
477+
SET(payload + 20, pulse_len_us, uint32_t); // pulse length when locked (1ms)
478478
SET(payload + 24, 0x0000, uint32_t); // delay
479479
SET(payload + 28, 0x007F, uint32_t); // 0x0111 1111
480480

boards/varmint_h7/pixracer_pro/specific/BoardConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "CommonConfig.h"
4242

4343
#define SANDBOX false
44-
#define BOARD_STATUS_PRINT false
44+
#define BOARD_STATUS_PRINT (false|SANDBOX)
4545
#define USE_TELEM 0 // 1 = use UART, 0 = use VCP for link to companion computer.
4646

4747
// UART used for printf's
@@ -264,7 +264,7 @@ extern PCD_HandleTypeDef hpcd_USB_OTG_FS; // USB FS (48 MB/s)
264264
{ \
265265
{ADC_REGULAR_RANK_1, ADC_CHANNEL_11, 1.000, 0.0}, /* ADC_RSSI_V */ \
266266
{ADC_REGULAR_RANK_2, ADC_CHANNEL_14, 12.62, 0.0}, /* ADC_BATTERY_VOLTS */ \
267-
{ADC_REGULAR_RANK_3, ADC_CHANNEL_15, 60.5, 0.0}, /* ADC_BATTERY_CURRENT */ \
267+
{ADC_REGULAR_RANK_3, ADC_CHANNEL_15, 60.5, 0.0747}, /* ADC_BATTERY_CURRENT */ \
268268
{ADC_REGULAR_RANK_4, ADC_CHANNEL_18, 2.000, 0.0}, /* ADC_5V0 */ \
269269
{ADC_REGULAR_RANK_1, ADC_CHANNEL_TEMPSENSOR, 1.000, 0.0}, /* ADC_STM_TEMPERATURE */ \
270270
{ADC_REGULAR_RANK_2, ADC_CHANNEL_VBAT, 4.000, 0.0}, /* ADC_STM_VBAT */ \

0 commit comments

Comments
 (0)