Herowaree

class TurtlebotV2

Dec 9th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from sensor_msgs.msg import Image
  2. from nav_msgs.msg import Odometry
  3. from math import atan2
  4.  
  5. import numpy as np
  6. import rospy
  7.  
  8. class TurtlebotV2:
  9.  
  10. def __init__(self, namespace='/tb0', timeout=1.0):
  11. self.namespace = namespace
  12. self.timeout= timeout
  13.  
  14. def getRobotPose(self):
  15. rospy.init_node('get_odom')
  16. try:
  17. odom = rospy.wait_for_message(self.namespace + '/odom', Odometry, timeout=self.timeout)
  18. theta = 2*atan2(odom.pose.pose.orientation.z, odom.pose.pose.orientation.w)
  19. pose = [odom.pose.pose.position.x, odom.pose.pose.position.x, theta]
  20.  
  21. except rospy.ROSException:
  22. # Timeout
  23. pose = [0.0, 0.0, 0.0]
  24.  
  25. return pose
  26.  
  27. def getKinectRGBImage(self):
  28. try:
  29. rospy.init_node('get_image')
  30. rgb = rospy.wait_for_message(self.namespace + '/camera/rgb/image_color', Image, timeout=self.timeout)
  31. img = np.frombuffer(rgb.data, dtype=np.uint8).reshape(rgb.height, rgb.width, -1)
  32.  
  33. # Convert to cv2
  34.  
  35. except rospy.ROSException:
  36. # Timeout
  37. img = None
  38.  
  39. return img
Advertisement
Add Comment
Please, Sign In to add comment