4 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij 8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 12 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 14 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 from geometry_msgs.msg
import (Pose, Point, Quaternion)
28 from asr_next_best_view.msg
import RobotStateMessage
29 from asr_robot_model_services.srv
import GetPose
30 from sensor_msgs.msg
import JointState
35 Methods that are required for calculating and comparing the poses and states related to our robot during exploration. 39 Accessing tf via c++ since python access is not reliable. 45 rospy.wait_for_service(
'/asr_robot_model_services/GetCameraPose', timeout=5)
46 pose = rospy.ServiceProxy(
'/asr_robot_model_services/GetCameraPose',GetPose)
50 Old helper for python interface. Might be still used, know wraps c++ interface. 54 Returns current camera pose 75 Accessing tf via c++ since python access is not reliable. 81 rospy.wait_for_service(
'/asr_robot_model_services/GetRobotPose', timeout=5)
82 pose = rospy.ServiceProxy(
'/asr_robot_model_services/GetRobotPose',GetPose)
86 Old helper for python interface. Might be still used, know wraps c++ interface. 108 Returns the rotation in degrees from pose 110 pose.position.x = pose.position.x
111 pose.position.y = pose.position.y
118 (_, _, yaw) = tf.transformations.euler_from_quaternion(q)
129 self.ptu = data.position
133 Returns the current robot configuration consisting of position and ptu 137 sub_ptu = rospy.Subscriber(
'/asr_flir_ptu_driver/state', JointState, self.
ptu_callback)
140 while not self.
ptu and time() < future:
149 robot_state = RobotStateMessage()
150 robot_state.pan = self.
ptu[0]
151 robot_state.tilt = self.
ptu[1]
152 robot_state.x = pose.position.x
153 robot_state.y = pose.position.y
158 def approx_equal_robot_state(old_robot_pose, old_tilt, new_robot_pose, new_tilt, positionThreshold, orientationThreshold, tiltThreshold):
160 Checks if two robot states are approximately equal, i.e. disctance of all values are under 164 if not old_robot_pose
or not old_tilt
or not new_robot_pose
or not new_tilt:
return False 168 tiltDiff = abs(old_tilt - new_tilt)
170 if abs(positionDiff) < positionThreshold
and abs(orientationDiffInDegree) < orientationThreshold
and tiltDiff < tiltThreshold:
171 rospy.loginfo(
"Two robot states are approx equale.")
183 Checks if two poses are approximately equal, i.e. sum of all values is under 184 a specified threshold. 187 if not old_pose
or not new_pose:
return False 191 rospy.loginfo(
"Difference poses: " + str(diff))
192 return diff < threshold
197 pow(position1.x - position2.x, 2) + \
198 pow(position1.y - position2.y, 2) + \
199 pow(position1.z - position2.z, 2))
212 if numpy.linalg.norm(vector1) * numpy.linalg.norm(vector2) <= 0.00001:
215 cosOfAngle = numpy.dot(vector1, vector2) / (numpy.linalg.norm(vector1) * \
216 numpy.linalg.norm(vector2))
218 if cosOfAngle < -1.0: cosOfAngle = -1.0
219 if cosOfAngle > 1.0: cosOfAngle = 1.0
221 rad = math.acos(cosOfAngle)
223 return math.degrees(rad)
228 return tf.transformations.quaternion_multiply(
229 tf.transformations.quaternion_multiply(quaternion, q),
230 tf.transformations.quaternion_conjugate(quaternion)
235 return [quaternion.x, quaternion.y, quaternion.z, quaternion.w]
def approx_equal_robot_state(old_robot_pose, old_tilt, new_robot_pose, new_tilt, positionThreshold, orientationThreshold, tiltThreshold)
def get_rotation_from_pose(pose)
def get_robot_state(self)
def quaternion_to_list(quaternion)
def get_camera_pose_cpp()
def approx_equal_pose(old_pose, new_pose, threshold)
def euclidean_distance_3d(position1, position2)
def angle_between_quaternions(quaternion1, quaternion2)
def ptu_callback(self, data)
def angle_between_vectors(vector1, vector2)
def get_vector(quaternion)