Skip to content
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

ジャイロのデータが遅延してしまう #49

Closed
fig-shimooka opened this issue Dec 7, 2023 · 5 comments
Closed

ジャイロのデータが遅延してしまう #49

fig-shimooka opened this issue Dec 7, 2023 · 5 comments
Labels
Type: Bug Bug or Bug fixes

Comments

@fig-shimooka
Copy link

fig-shimooka commented Dec 7, 2023

タイトルの通りです。
ros2-develでimu/data_rawをpublishしていますが、IMUを傾けてもデータが0.5秒ぐらい遅延して出力されます。
そのため常に少し前のデータがpublishされています

publish_timer_ = create_wall_timer(10ms, std::bind(&Driver::on_publish_timer, this));

タイマーが早すぎるかと思い、on_publish_timerの頻度を10ms->50msに変更してみましたが、
ここを変更すると更に遅延が増えました。

おそらくバッファが溜まっているような挙動をしているのですが、都度最新のジャイロの値を取得することはできませんか?

@fig-shimooka fig-shimooka added the Type: Bug Bug or Bug fixes label Dec 7, 2023
@fig-shimooka
Copy link
Author

対応としてimu/data_rawをpublishする処理と
imuからデータを吸い上げる処理を別タイマーにすることで改善しましたが、これでよかったでしょうか?

  read_timer_ = create_wall_timer(5ms, std::bind(&Driver::on_read_timer, this));
  publish_timer_ = create_wall_timer(50ms, std::bind(&Driver::on_publish_timer, this));

void Driver::on_publish_timer(){
  if(!read_flg){
    return;
  }
  rclcpp::Time timestamp = this->now();
  imu_data_raw_msg_ = driver_->getImuRawDataUniquePtr(timestamp);
  modifyValue(imu_data_raw_msg_);
  imu_data_raw_pub_->publish(*imu_data_raw_msg_);
  imu_mag_pub_->publish(std::move(driver_->getImuMagUniquePtr(timestamp)));
  imu_temperature_pub_->publish(std::move(driver_->getImuTemperatureUniquePtr()));
  read_flg = false;
}

void Driver::on_read_timer()
{
  if (driver_->readSensorData()) {
    if (driver_->hasRefreshedImuData()) {
      read_flg = true;
    }
  } else {
    RCLCPP_ERROR(this->get_logger(), "readSensorData() returns false, please check your devices.");
  }
}

@ShotaAk
Copy link
Collaborator

ShotaAk commented Dec 13, 2023

ご連絡遅くなりました。ご報告ありがとうございます。
こちらでも動作確認するため、少々お待ちください。

@ShotaAk
Copy link
Collaborator

ShotaAk commented Dec 13, 2023

こちらでも再現確認できました。
また、実装の提案もありがとうございます。

最新データを取得できるかどうかが動作周期(on_publish_timer)に依存していました。
そのためこの実装を修正します。

レビュー段階ですが修正版のコードをアップロードしましたので、急ぎの場合はこちらのブランチをご使用ください。
#50

https://github.com/rt-net/rt_usb_9axisimu_driver/tree/fix_to_read_latest_value

@fig-shimooka
Copy link
Author

ありがとうございます。
今確認はできませんが、時間があるときに検証してみます。

@ShotaAk
Copy link
Collaborator

ShotaAk commented Aug 21, 2024

対応遅くなりました。

修正版をmainブランチにマージしました。
そのため、本Issueは一旦クローズします。

@ShotaAk ShotaAk closed this as completed Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants