ROS Answers: Open Source Q&A Forum - RSS feedhttps://answers.ros.org/questions/Open source question and answer forum written in Python and DjangoenROS Answers is licensed under Creative Commons Attribution 3.0Tue, 10 Aug 2021 19:08:56 -0500Getting rotation angle from laser datahttps://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.
My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.
![image description](/upfiles/16285528091874777.png)
To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.
I'm using the following to calculate the angle:
self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
However, my robot does not rotate.
If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?Mon, 09 Aug 2021 19:14:18 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/Comment by So Young for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384108#post-id-384108I'm not sure if I understood the diagram right, but isn't cosine = median/laser_right? and to get the theta angle , use arccos? let me know if I understood it worng. Also, have you checked your laser_right[0] and median_valuse has appropriate value?Mon, 09 Aug 2021 23:32:58 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384108#post-id-384108Comment by ijnek for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384111#post-id-384111In the code you provided, there is no code to make the robot "rotate". There is only code to stop the rotation. Would you be able to post where you're setting anglar.z to a value that is not zero?Tue, 10 Aug 2021 00:27:05 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384111#post-id-384111Comment by sisko for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384136#post-id-384136@So Young: I'm trying to use Oppsite/Hypotenus to get the angle. Regarding checking the values, yes there is data in the values being passed into my code but I do wonder if merely using the value in the first index is correct. That's why in the second part of my question I asked if it's possible to "view" the laser somehow in gazebo to confirm. I updated my code.Tue, 10 Aug 2021 04:52:59 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384136#post-id-384136Comment by sisko for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384137#post-id-384137@ijnek: I updated the question to include the code I use for rotation.Tue, 10 Aug 2021 04:53:52 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384137#post-id-384137Comment by sisko for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384139#post-id-384139@So Young: CORRECTION. I'm trying to calculate the angle using Adjacent/HypothenusTue, 10 Aug 2021 05:07:37 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384139#post-id-384139Comment by ijnek for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384163#post-id-384163In your code, you have
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
doesnt seem right. math.sin(θ) should take an **angle** θ. In your case, I think it should be
heading_error = math.acos(median/self.regions['starboard_abeam_bow'][0] )Tue, 10 Aug 2021 08:38:43 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384163#post-id-384163Comment by Mehdi. for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384165#post-id-384165Ransac, line detection representing the wall from the lidar points, get the relative angle from the line coefficients and adjust robot pose.Tue, 10 Aug 2021 08:44:31 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384165#post-id-384165Comment by sisko for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384166#post-id-384166@Mehdi: Can you please explain more ?Tue, 10 Aug 2021 08:46:59 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384166#post-id-384166Comment by So Young for <p>I need help finding the exact angle to rotate my robot so that it is directly facing an obstacle.</p>
<p>My thought process is to extract information from my laser readings which represent horizontal and diagonal distance to the obstacle, as illustrated below.</p>
<p><img src="/upfiles/16285528091874777.png" alt="image description"></p>
<p>To get the "green" distance I used the data in the first index of the right laser. For the "red" distance, I used the median value of the right laser.</p>
<p>I'm using the following to calculate the angle:</p>
<pre><code>self.kP = 0.5
.
.
sine = math.sin( median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :
move.angular.z = 0
rospy.logerr('Target Acuired!')
self.target_acquired = True
exit()
else :
move.angular.z = self.kP * (target - self.yaw)
rospy.loginfo('Target: %s, Yaw: %s', target, self.yaw)
</code></pre>
<p>However, my robot does not rotate.</p>
<p>If my process is wrong, can I get some advice on how to get the angle information ?
And, is there a way I can visualize both lines to confirm the triangle I am working with ?</p>
https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384199#post-id-384199I agree with @ijnek suggestion, acos should be used to calculate the heading error. also, regarding `self.yaw`, this should be accumulated angle (**how much it has moved since the rotation started**) not the robot's real yaw angle, since in your code (after getting heading error using acos) yaw is being compared to the target.
target = math.acos(median/self.regions['starboard_abeam_bow'][0] )
target = sine * math.pi/180 # converting degrees into radians
if format(target, '.2f') == format(self.yaw, '.2f') :Tue, 10 Aug 2021 19:08:56 -0500https://answers.ros.org/question/384104/getting-rotation-angle-from-laser-data/?comment=384199#post-id-384199