-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Gyro calibration #11
base: main
Are you sure you want to change the base?
Changes from 1 commit
4fc7d64
07c25ee
4d9f068
e4832d4
b5923dd
18ec3cd
104b900
5ca0384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -226,6 +226,47 @@ int Adis16448::signedWordToInt(const std::vector<byte> &word) { | |||||
return (((int) *(signed char *) (word.data())) * 1 << CHAR_BIT) | word[1]; | ||||||
} | ||||||
|
||||||
bool Adis16448::calibrateGyro(){ | ||||||
// set offsets to zero | ||||||
writeReg(0x1A, {0x00, 0x00}, "XGYRO_OFF"); | ||||||
writeReg(0x1C, {0x00, 0x00}, "YGYRO_OFF"); | ||||||
writeReg(0x1E, {0x00, 0x00}, "ZGYRO_OFF"); | ||||||
|
||||||
// read offsets | ||||||
auto xgyro_off = readReg(0x1A); | ||||||
auto ygyro_off = readReg(0x1C); | ||||||
auto zgyro_off = readReg(0x1E); | ||||||
|
||||||
std::cout << "Gyro offers after reset:\n" << xgyro_off[0] << " , " << xgyro_off[1] << " , " << ygyro_off[1] << " , " << zgyro_off[1] << std::endl; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use lpp
Suggested change
|
||||||
|
||||||
// Store sensitivity and sample period | ||||||
auto sens_avg = readReg(SENS_AVG); | ||||||
auto smpl_prd = readReg(SMPL_PRD); | ||||||
|
||||||
// Calibrate | ||||||
auto calib_sens_avg = sens_avg; | ||||||
auto calib_smpl_prd = smpl_prd; | ||||||
calib_sens_avg[0] = 0x01; // Set high sensitivity | ||||||
calib_smpl_prd[0] = 0x0F; // Sample for (2^15 / 819.2) = 40s | ||||||
std::cout << "Starting Gyro Calibration. Keep IMU steady and wait for 40s.." << std::endl; | ||||||
writeReg(SENS_AVG, calib_sens_avg, "CALIB_SENS_AVG"); | ||||||
writeReg(SMPL_PRD, calib_smpl_prd, "CALIB_SMPL_PRD"); | ||||||
usleep(40*1e6); // wait for next measurement | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of a fixed sleeping time, you can also poll the IMU and see if the value changes... But not sure how robust this is. Or calculate the sampling time from the register value to make it adaptable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea! |
||||||
writeReg(GLOB_CMD, {0x0, 1 << 0}, "GLOB_CMD"); // Set offsets | ||||||
usleep(ms_); | ||||||
|
||||||
ygyro_off = readReg(0x1C); | ||||||
xgyro_off = readReg(0x1A); | ||||||
zgyro_off = readReg(0x1E); | ||||||
std::cout << "Gyro offsets after calibration\n" << "[" << xgyro_off[0] << " , " << xgyro_off[1] << "]" << " , " << ygyro_off[1] << " , " << zgyro_off[1] << std::endl; | ||||||
|
||||||
// Reset sensitivity and sample period | ||||||
writeReg(SENS_AVG, sens_avg, "SENS_AVG"); | ||||||
writeReg(SMPL_PRD, smpl_prd, "SMPL_PRD"); | ||||||
|
||||||
return true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to configure the alarm on the IMU in case the platform is moved during calibration progress and then return false. |
||||||
} | ||||||
|
||||||
bool Adis16448::setBurstCRCEnabled(bool b) { | ||||||
if (b) { | ||||||
auto msc_ctrl = readReg(MSC_CTRL); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the command definitions, e.g.,