mirror of
https://github.com/sipeed/MaixCDK.git
synced 2026-11-09 17:04:38 -06:00
optimize imu init error and examples name
This commit is contained in:
@@ -172,7 +172,7 @@ public:
|
||||
/**
|
||||
* @brief Construct a new IMU object, will open IMU
|
||||
*
|
||||
* @param driver driver name, only support "qmi8656"
|
||||
* @param driver driver name, "default" means use onboard IMU according to board id, other values: ["qmi8656"]
|
||||
* @param i2c_bus i2c bus number. Automatically selects the on-board imu when -1 is passed in.
|
||||
* @param addr IMU i2c addr.
|
||||
* @param freq IMU freq
|
||||
@@ -182,6 +182,7 @@ public:
|
||||
* @param gyro_scale gyro scale, see @imu::GyroScale
|
||||
* @param gyro_odr gyro output data rate, see @imu::GyroOdr
|
||||
* @param block block or non-block, defalut is true
|
||||
* @throw if arg error or not find valid IMU, will throw err::Exception
|
||||
*
|
||||
* @maixpy maix.ext_dev.imu.IMU.__init__
|
||||
*/
|
||||
|
||||
@@ -93,11 +93,23 @@ IMU::IMU(std::string driver, int i2c_bus, int addr, int freq, imu::Mode mode, im
|
||||
imu_param_t *param = (imu_param_t *)malloc(sizeof(imu_param_t));
|
||||
err::check_null_raise(param, "Failed to malloc param");
|
||||
|
||||
if(driver == "qmi8658")
|
||||
bool found = false;
|
||||
|
||||
if(driver == "default")
|
||||
{
|
||||
if(sys::device_id() == "maixcam_pro")
|
||||
{
|
||||
param->type = driver_type::qmi8658;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
else if(driver == "qmi8658")
|
||||
{
|
||||
param->type = driver_type::qmi8658;
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
|
||||
if (!found)
|
||||
{
|
||||
free(param);
|
||||
throw err::Exception(err::ERR_ARGS, "not support " + driver);
|
||||
|
||||
@@ -151,21 +151,30 @@ int _main(int argc, char* argv[])
|
||||
std::vector<int> ret_btn_disp_pos = {0, disp.height() - 50, 100, 50};
|
||||
std::vector<int> dir_btn_disp_pos = {disp.width() / 2 - dir_font_size.width() / 2 - 10, disp.height() - 50, dir_font_size.width() + 20 , 50};
|
||||
|
||||
imu::IMU imu("qmi8658");
|
||||
imu::IMU *imu = nullptr;
|
||||
try
|
||||
{
|
||||
imu = new imu::IMU("default");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
log::error("init IMU failed");
|
||||
return 1;
|
||||
}
|
||||
ahrs::MahonyAHRS ahrs(kp, ki);
|
||||
if(calibrate == 1)
|
||||
{
|
||||
log::info("now calibrate, please don't move device");
|
||||
imu.calib_gyro(10000);
|
||||
imu->calib_gyro(10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
imu.load_calib_gyro();
|
||||
imu->load_calib_gyro();
|
||||
}
|
||||
char temp_char[64];
|
||||
double last_time = time::ticks_s();
|
||||
while (!app::need_exit()) {
|
||||
auto data = imu.read_all(true, true); // use calibrate value and unit rad/s.
|
||||
auto data = imu->read_all(true, true); // use calibrate value and unit rad/s.
|
||||
double t = time::ticks_s();
|
||||
float dt = t - last_time;
|
||||
auto angle = ahrs.get_angle(data.acc, data.gyro, data.mag, dt);
|
||||
@@ -224,7 +233,7 @@ int _main(int argc, char* argv[])
|
||||
log::info("now calibrate, please don't move device");
|
||||
std::string msg = "Calibrating, don't move, keep 10s";
|
||||
show_msg(disp, msg);
|
||||
imu.calib_gyro(10000);
|
||||
imu->calib_gyro(10000);
|
||||
ahrs.reset();
|
||||
last_time = time::ticks_s();
|
||||
}
|
||||
@@ -236,6 +245,7 @@ int _main(int argc, char* argv[])
|
||||
while(time::ticks_s() - last_time < 0.001)
|
||||
time::sleep_us(100);
|
||||
}
|
||||
delete imu;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user