High CPU load on repeated battery read

Hi there,

I am using the C++ API to start streaming out sensor fusion data in the following way:

mbl_mw_sensor_fusion_set_mode(board, MBL_MW_SENSOR_FUSION_MODE_NDOF);
mbl_mw_sensor_fusion_set_acc_range(board, MBL_MW_SENSOR_FUSION_ACC_RANGE_16G);
mbl_mw_sensor_fusion_set_gyro_range(board, MBL_MW_SENSOR_FUSION_GYRO_RANGE_2000DPS);
mbl_mw_sensor_fusion_write_config(board);

MblMwDataSignal *quat_signal = mbl_mw_sensor_fusion_get_data_signal(board, MBL_MW_SENSOR_FUSION_DATA_QUATERION);
mbl_mw_dataprocessor_time_create(quat_signal, MBL_MW_TIME_ABSOLUTE, 40, C_MWC::c_processor_cb);

std::unique_lock<std::mutex> m_lock_for_proc_creation(m_proc_lock);
m_cv_for_proc_creation.wait(m_lock_for_proc_creation, [=] { return m_proc_creation_finished; });

mbl_mw_datasignal_subscribe((MblMwDataSignal*) m_quat_processor,
kinemic::device::ModuleFusion::quat_datasignal_listener);
mbl_mw_sensor_fusion_enable_data(board, MBL_MW_SENSOR_FUSION_DATA_QUATERION);

MblMwDataSignal *acc_signal = mbl_mw_acc_get_high_freq_acceleration_data_signal(board);
mbl_mw_datasignal_subscribe(acc_signal, kinemic::device::ModuleFusion::acc_datasignal_listener);

MblMwDataSignal *gyro_signal = mbl_mw_gyro_bmi160_get_high_freq_rotation_data_signal(board);
mbl_mw_datasignal_subscribe(gyro_signal, kinemic::device::ModuleFusion::gyro_datasignal_listener);
This is all working quite well, and I get the data I need. 
Additionally I wanted to get the current battery readings, therefore I added the following:
battery_signal = mbl_mw_settings_get_battery_state_data_signal(board);
mbl_mw_datasignal_subscribe(battery_signal, kinemic::device::ModuleBattery::datasignal_listener);
mbl_mw_datasignal_read(mbl_mw_settings_get_battery_state_data_signal(board));
m_update_thread = std::thread([=] {
while (m_update_thread_running) {
mbl_mw_datasignal_read(
battery_signal);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
});

This does in fact work in that I regulary get battery updates. 
Unfortunately, the update_thread I'm starting will at some point produce a load of 100% at one core.
Is a datasignal_read inside a thread valid? Or is the time between reads too short for battery readings?
Best regards,
Marcus
Tagged:

Comments

Sign In or Register to comment.