# Unit6 : total\_distance calculation from grader bot

**URL:** <https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296>\
**Category:** ROS2 Basics in 5 Days Humble (C++)\
**Created:** [January 9, 2025, 7:05pm UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296 "2025-01-09T19:05:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vadhrivenkat](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vadhrivenkat](https://get-help.theconstruct.ai/u/vadhrivenkat)\
**Post date:** [January 9, 2025, 7:05pm UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/1 "2025-01-09T19:05:37Z")

</div>

Hello @girishkumar.kannan , @bayodesegun

I am getting a feedback from gradebot for chapter 6 as below.  
The total distance calcualted is not correct.

I am using odometry callbacks as below. Can you please tell me where i could look more for this item ? Thanks for your time in adv.

```auto
void odometry_callback(const nav_msgs::msg::Odometry::SharedPtr msg) {
double current_x = msg->pose.pose.position.x;
double current_y = msg->pose.pose.position.y;

if (last_x_ == 0.0 && last_y_ == 0.0) {
    last_x_ = current_x;
    last_y_ = current_y;
    return; 
}

double delta_x = current_x - last_x_;
double delta_y = current_y - last_y_;

double delta_distance = std::sqrt(delta_x * delta_x + delta_y * delta_y);

total_distance_ += delta_distance;

last_x_ = current_x;
last_y_ = current_y;
}

```

I am having a simulation loading issue with Unit 6 which is why it gives 0 for distance.  
Unit 5 simulation gives me numbers correctly - please check the video below !!

Thanks,  
Venkat

---

<div class="post-metadata">

**Author:** ![albertoezquerro](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/albertoezquerro/32/7031_2.png) [@albertoezquerro](https://get-help.theconstruct.ai/u/albertoezquerro)\
**Post date:** [January 13, 2025, 11:08am UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/2 "2025-01-13T11:08:49Z")

</div>

Hello @vadhrivenkat ,

Your code looks correct, and from the video you shared, it seems to be working as intended. Therefore, I believe the issue lies with the simulation. I tested the Unit simulation, and it appears to be working fine on my end. It’s possible that you encountered an isolated issue while trying to correct your quiz. I recommend resubmitting your quiz for revision and ensuring that the simulation is functioning as expected beforehand.

Best,

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [January 13, 2025, 11:23am UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/3 "2025-01-13T11:23:36Z")

</div>

@vadhrivenkat  
Adding to @albertoezquerro’s post above,

I have just changed the simulation to a faster one (the same one used in unit 5). Please try submitting again on unit 6, after the simulation has loaded.

---

<div class="post-metadata">

**Author:** ![vadhrivenkat](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vadhrivenkat](https://get-help.theconstruct.ai/u/vadhrivenkat)\
**Post date:** [January 13, 2025, 12:05pm UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/4 "2025-01-13T12:05:10Z")

</div>

Hello @albertoezquerro @bayodesegun  
I can load the simulation now,  
The bot is put into motion with the keyboard. ( or its equivalent by the grader bot ). The client submitted only submits the goal. is that the right understanding ? when i run the grader bot i dont see the robot moving in the background ( i got 8 pts - i crossed section - but just to keep you posted. )

Running independently in the console ( without grader bot ) - looks fine.

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/4/4ec5565831e7b9aa3eb941a4509de7d0ac1f115b.png)

can you please confirm ?

Thanks,  
Venkat

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [January 14, 2025, 11:01am UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/5 "2025-01-14T11:01:44Z")

</div>

> [@vadhrivenkat](#):
>
> when i run the grader bot i dont see the robot moving in the background

The robot only moves when checking distance calculation, and the robot position is reset afterward. Therefore, you may not have noticed the movement (I did check keenly and noticed it).

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [January 19, 2025, 11:02am UTC](https://get-help.theconstruct.ai/t/unit6-total-distance-calculation-from-grader-bot/34296/6 "2025-01-19T11:02:14Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
