Rosject of ROS Basics in 5 Days

Could you please explain why we need step 4? How do you come up with index 270?
Why not simply turn left to 90 degrees?

2.1 Create Service Server
When the service is called, the robot must perform the following behavior:

  1. Identify which laser ray is the shortest one. Assume that this is the one pointing to a wall.
  2. Rotate the robot until the front of it is facing the wall. This can be done by publishing an angular velocity until front ray is the smallest one.
  3. Move the robot forward until the front ray is smaller than 30cm.
  4. Now rotate the robot again until ray number 270 of the laser ranges is pointing to the wall.
  5. At this point, consider that the robot is ready to start following the wall.
  6. Return the service message with True.

By turning reading the laser values you can control better that the robot is really turning 90 degrees. The 270 is basically the laser rays that correspond to the side of the robot. To get that just divide the number of rays by 1/4 of 360 and you will have the quarters of the laser. But essentially, it is more or less the laser ray that corresponds to the side

I assume when the tutorial mentioned ray number 270, it meant ranges index 270, which is not either left or right of the robot according to the following information.

Here is the information about the laser scan. It shows that the degree range is [-pi, pi], 360 degree covering. We can calculate the number of index is int((angle_max-angle_min)/angle_increment), which is 720. As we know front direction points to the x-axis, which means 0 degree, and front_index = 0, therefore, right_index=180, and left_index=540, back_index=0 or 719.

I cannot see anything related to index 270.

In addition, I think it is better to calculate the index dynamically instead of always hard coding these numbers…
PS: we have learned OOP but all the solutions still use procedure-oriented programming and even global variables, which are not good practice.

user:~/catkin_ws$ rostopic ec /scan -n1
header:
  seq: 32
  stamp:
    secs: 11
    nsecs: 420000000
  frame_id: "base_scan"
angle_min: -3.1415998935699463
angle_max: 3.1415998935699463
angle_increment: 0.008738803677260876
time_increment: 0.0
scan_time: 0.0
range_min: 0.11999999731779099
range_max: 3.5

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