Unit 5 Exercise 5.1 - is this correct?

I want to know if this is what is expected in exercise 5.1.

We define a private member variable
float *last_laser_ranges;

We initialize in the constructor
last_laser_ranges = new float[720];

We create a copy of the ranges in the callback
for (int i = 0; i < laser_msg->ranges.size(); i++) { last_laser_ranges[i] = laser_msg->ranges[i]; }

Is this the right thing to do?

Thank you!

Hi @tuf01133,

that is indeed what the 3rd point of that exercise asks:

  1. From every laser message that arrives at the callback, retrieve the ranges array from it, and copy it into a pointer to an array named last_laser_ranges, a member of the class

You are going in the right direction.

Cheers,

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