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

Fixed Odometry step_time calculation #951

Open
wants to merge 2 commits into
base: humble-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions turtlebot3_node/include/turtlebot3_node/odometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Odometry

double wheels_separation_;
double wheels_radius_;
uint32_t last_time_;


std::string frame_id_of_odometry_;
std::string child_frame_id_of_odometry_;
Expand Down
10 changes: 4 additions & 6 deletions turtlebot3_node/src/odometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ Odometry::Odometry(

void Odometry::joint_state_callback(const sensor_msgs::msg::JointState::SharedPtr joint_state_msg)
{
static rclcpp::Time last_time = joint_state_msg->header.stamp;
rclcpp::Duration duration(rclcpp::Duration::from_nanoseconds(
joint_state_msg->header.stamp.nanosec - last_time.nanoseconds()));
joint_state_msg->header.stamp.nanosec - last_time_));

update_joint_state(joint_state_msg);
calculate_odometry(duration);
publish(joint_state_msg->header.stamp);

last_time = joint_state_msg->header.stamp;
last_time_ = joint_state_msg->header.stamp.nanosec;
}

void Odometry::joint_state_and_imu_callback(
Expand All @@ -129,16 +128,15 @@ void Odometry::joint_state_and_imu_callback(
joint_state_msg->header.stamp.nanosec,
imu_msg->header.stamp.nanosec);

static rclcpp::Time last_time = joint_state_msg->header.stamp;
rclcpp::Duration duration(rclcpp::Duration::from_nanoseconds(
joint_state_msg->header.stamp.nanosec - last_time.nanoseconds()));
joint_state_msg->header.stamp.nanosec - last_time_));

update_joint_state(joint_state_msg);
update_imu(imu_msg);
calculate_odometry(duration);
publish(joint_state_msg->header.stamp);

last_time = joint_state_msg->header.stamp;
last_time_ = joint_state_msg->header.stamp.nanosec;
}

void Odometry::publish(const rclcpp::Time & now)
Expand Down