13 import rocon_utilities.console
as console
14 import visualization_msgs.msg
as visualization_msgs
15 from std_msgs.msg
import Float32
47 self.
subscriber = rospy.Subscriber(
'/visualization_marker', visualization_msgs.Marker, self.
callback)
51 b = self.
baseline/2 + (self.left_marker.distance*self.left_marker.distance - self.right_marker.distance*self.right_marker.distance)/(2*self.
baseline)
53 a = math.sqrt(self.left_marker.distance*self.left_marker.distance - b*b)
55 print(
"Value error: measured_distance=%s, b=%s" % (self.left_marker.distance, b))
57 print(console.cyan +
" a" + console.reset +
" : " + console.yellow +
"%s" % a + console.reset)
58 print(console.cyan +
" b" + console.reset +
" : " + console.yellow +
"%s" % b + console.reset)
63 alpha = math.atan2(self.left_marker.x, self.left_marker.z)
64 alpha_degrees = alpha*180.0/math.pi
66 beta = math.atan2(self.right_marker.x, self.right_marker.z)
67 beta_degrees = beta*180.0/math.pi
69 theta = math.atan2((self.left_marker.z - self.right_marker.z), (self.right_marker.x - self.left_marker.x))
70 theta_degrees = theta*180.0/math.pi
72 print(console.cyan +
" alpha" + console.reset +
" : " + console.yellow +
"%s" % alpha_degrees +
" degrees" + console.reset)
73 print(console.cyan +
" beta" + console.reset +
" : " + console.yellow +
"%s" % beta_degrees +
" degrees" + console.reset)
74 print(console.cyan +
" theta" + console.reset +
" : " + console.yellow +
"%s" % theta_degrees +
" degrees" + console.reset)
83 target_x = self.left_marker.x + (self.right_marker.x - self.left_marker.x)/2 - 0.4*math.sin(theta)
84 target_z = self.left_marker.z + (self.right_marker.z - self.left_marker.z)/2 - 0.4*math.cos(theta)
85 target_heading = math.atan2(target_x, target_z)
86 target_heading_degrees = target_heading*180.0/math.pi
88 print(console.cyan +
" target" + console.reset +
" : " + console.yellow +
"(x=%s, z=%s, heading=%s)" % (target_x, target_z, target_heading_degrees) + console.reset)
89 self.x_publisher.publish(Float32(target_x))
90 self.z_publisher.publish(Float32(target_z))
91 self.heading_publisher.publish(Float32(target_heading_degrees))
95 self.right_marker.update(data.pose.position.x, data.pose.position.y, data.pose.position.z)
97 print(console.cyan +
"r: [x, y, z]" + console.reset +
" : " + console.yellow +
"[%s, %s, %s]" % (self.right_marker.x, self.right_marker.y, self.right_marker.z) + console.reset)
98 print(console.cyan +
"r: d" + console.reset +
" : " + console.yellow +
"%s" % self.right_marker.distance + console.reset)
101 self.left_marker.update(data.pose.position.x, data.pose.position.y, data.pose.position.z)
102 print(console.cyan +
"l: [x, y, z]" + console.reset +
" : " + console.yellow +
"[%s, %s, %s]" % (self.left_marker.x, self.left_marker.y, self.left_marker.z) + console.reset)
103 print(console.cyan +
"l: d" + console.reset +
" : " + console.yellow +
"%s" % self.left_marker.distance + console.reset)
113 if __name__ ==
'__main__':
115 rospy.init_node(
'roles_and_apps')
def update(self, x, y, z)
def print_pythags_results(self)
def __init__(self, id, x, y, z)
def print_pose_results(self)