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

Wheel Ticks calculation code equation correction #222

Merged
merged 2 commits into from
Jan 13, 2024

Conversation

adnan-saood
Copy link
Contributor

@adnan-saood adnan-saood commented Dec 12, 2023

Description

I am trying to create my own odometry filter and I was using the simulation when I noticed that the ticks values were wrong.

In the code, file irobot_create_nodes\src\wheels_publisher.cpp, lines 79 and 82:

$$ \text{Ticks}_L = \frac{\theta_L}{2 \pi r} \times 508.8~~~~ \text{Ticks}_R = \frac{\theta_R}{2 \pi r} \times 508.8 $$

The correct formula is:

$$ \text{Ticks}_L = \frac{\theta_L}{2 \pi} \times 508.8~~~~ \text{Ticks}_R = \frac{\theta_R}{2 \pi} \times 508.8 $$

Without the $r$...

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I ran the simulation and compared the wheels rotation reported by the dynamic_joint_states topic and the wheels rotation calculated by the formula:

$$ \theta_{L|R} = \frac{\text{Ticks}_{L|R}}{508.8} \times 2\pi $$

# Run this command (Gazebo)
ros2 launch irobot_create_gazebo_bringup create3_gazebo.launch.py 

# Or (Ignition)
ros2 launch irobot_create_ignition_bringup create3_ignition.launch.py 

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas (No need)
  • I have made corresponding changes to the documentation (No need)

@alsora
Copy link
Contributor

alsora commented Dec 12, 2023

Hi @adnan-saood, thank you for your PR.
The first set of formulas that you wrote seem indeed wrong

$$ \text{Ticks}_L = \frac{\theta_L}{2 \pi r} \times 508.8~~~~ \text{Ticks}_R = \frac{\theta_R}{2 \pi r} \times 508.8 $$

If the wheel radius r is included in the formula, then the wheel rotation \theta should have been replaced with the linear distance travelled by the wheel d.

So the correct formulas are the following:

$$ \text{Ticks}_L = \frac{\theta_L}{2 \pi} \times 508.8 $$

or equivalently

$$ \text{Ticks}_L = \frac{d_L}{2 \pi r} \times 508.8 $$

After this premise, let's look at the simulation code.
The code is using get_dynamic_state_value("left_wheel_joint", "position"), so the question is whether the "position" of the joint represents d_L or \theta_L.
If it's d_L, then the formulas are correct, but if it's \theta_L, then they are wrong (and your PR fixes the issue).

I think that your PR is correct, but I don't know gazebo joints well enough to confirm this out of the top of my head.
Have you checked whether the returned value from that function is an angle or a linear distance?

@adnan-saood
Copy link
Contributor Author

Hi @alsora, thank you for your prompt reply.

Yes I have confirmed that they are angular values since it is from the diff_drive_controller.
Also, I confirmed that the reported ticks for $N$ wheel rotation is round($N\times508.8$).

@alsora alsora merged commit 4ea6457 into iRobotEducation:main Jan 13, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants