本文整理汇总了Python中geometry_msgs.msg.Quaternion.y方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.y方法的具体用法?Python Quaternion.y怎么用?Python Quaternion.y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geometry_msgs.msg.Quaternion
的用法示例。
在下文中一共展示了Quaternion.y方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quaternion_product
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def quaternion_product(q1, q2):
q_prod = Quaternion()
a1 = q1.w
b1 = q1.x
c1 = q1.y
d1 = q1.z
a2 = q2.w
b2 = q2.x
c2 = q2.y
d2 = q2.z
q_prod.w = a1 * a2 - b1 * b2 - c1 * c2 - d1 * d2
q_prod.x = a1 * b2 + b1 * a2 + c1 * d2 - d1 * c2
q_prod.y = a1 * c2 - b1 * d2 + c1 * a2 + d1 * b2
q_prod.z = a1 * d2 + b1 * c2 - c1 * b2 + d1 * a2
# This is exactly the same quaternion as before, but with positive
# real part (seems to be the standard for ROS TF)
if q_prod.w < 0.0:
q_prod.x = -q_prod.x
q_prod.y = -q_prod.y
q_prod.z = -q_prod.z
q_prod.w = -q_prod.w
return q_prod
示例2: sense
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def sense(self):
""" collects sensor data from the Neato and publishes
it to the neatoSensors topic
"""
# receive and publish sensor data
self.fields = self.neato.state.keys() # update sensor fields
sensor_data = NeatoSensors() # see NOTE above
for field in self.fields:
try:
sensor_data.__setattr__(field, self.neato.state[field])
except:
pass
self.sensorPub.publish(sensor_data)
# receive and publish laser range data
range_data = LaserRangeData()
range_data.__setattr__("range_data", self.neato.range_data)
self.rangePub.publish(range_data)
# odomemtry in testing
self.odomUpdate()
# transform position into tf frame
quaternionOdom = Quaternion()
quaternionOdom.x = 0.0
quaternionOdom.y = 0.0
quaternionOdom.z = sin(self.theta/2)
quaternionOdom.w = -cos(self.theta/2)
quaternionLL = Quaternion()
quaternionLL.x = 0.0
quaternionLL.y = 0.0
quaternionLL.z = 0.0
quaternionLL.w = 1.0
# base_link -> base_laser transformation
self.odomBroadcaster.sendTransform(
(0.0, -0.1, 0.0),
(quaternionLL.x, quaternionLL.y, quaternionLL.z, quaternionLL.w),
rospy.Time.now(),
"/base_laser",
"/base_link")
# odom -> base_link transformation
self.odomBroadcaster.sendTransform(
(self.x/1000, self.y/1000, 0),
(quaternionOdom.x, quaternionOdom.y, quaternionOdom.z, quaternionOdom.w),
rospy.Time.now(),
"/base_link",
"/odom")
示例3: Publish
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def Publish(self, broadcaster, orientation, x_dist, y_dist, linear_speed, angular_speed, use_pose_ekf=False):
ros_now = rospy.Time.now()
quat = Quaternion()
# Orientation can be one of two things:
# Euler Angles or Quaternion
# Orientation is a dictionary keyed by 'euler' and 'quaternion'
if orientation.has_key('euler'):
euler = orientation['euler']
# Note: Euler values are in degrees
roll = euler['roll']
pitch = euler['pitch']
yaw = euler['yaw']
q = transformations.quaternion_from_euler(roll, pitch, yaw)
quat.x = q[0]
quat.y = q[1]
quat.z = q[2]
quat.w = q[3]
elif orientation.has_key('quaternion'):
quat.x = orientation['quaternion']['x']
quat.y = orientation['quaternion']['y']
quat.z = orientation['quaternion']['z']
quat.w = orientation['quaternion']['w']
# Publish the transform from frame odom to frame base_link over tf
# Note: pose ekf is how turtlebot does its thing. If there is an imu and/or gyro, it might be best to take
# this approach
if use_pose_ekf:
# This transform conflicts with transforms built into the Turtle stack
# http://wiki.ros.org/tf/Tutorials/Writing%20a%20tf%20broadcaster%20%28Python%29
# This is done in/with the robot_pose_ekf because it can integrate IMU/gyro data
# using an "extended Kalman filter"
# REMOVE this "line" if you use robot_pose_ekf
pass
else:
broadcaster.sendTransform(
(x_dist, y_dist, 0),
(quat.x, quat.y, quat.z, quat.w),
ros_now,
"base_footprint",
"odom"
)
self._publisher.publish(self._msg(quat, x_dist, y_dist, linear_speed, angular_speed, ros_now, use_pose_ekf))
示例4: publish
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def publish(self, data):
q = data.getOrientation()
roll, pitch, yaw = euler_from_quaternion([q.w, q.x, q.y, q.z])
# print "Before ", "Yaw: " + str(yaw * 180 / pi), "Roll: " + str(roll * 180 / pi), "pitch: " + str(pitch * 180 / pi), "\n\n"
array = quaternion_from_euler(roll, pitch, yaw + (self._angle * pi / 180))
res = Quaternion()
res.w = array[0]
res.x = array[1]
res.y = array[2]
res.z = array[3]
roll, pitch, yaw = euler_from_quaternion([q.w, q.x, q.y, q.z])
# print "after ", "Yaw: " + str(yaw * 180 / pi), "Roll: " + str(roll * 180 / pi), "pitch: " + str(pitch * 180 / pi), "\n\n"
msg = Imu()
msg.header.frame_id = self._frameId
msg.header.stamp = rospy.get_rostime()
msg.orientation = res
msg.linear_acceleration = data.getAcceleration()
msg.angular_velocity = data.getVelocity()
magMsg = MagneticField()
magMsg.header.frame_id = self._frameId
magMsg.header.stamp = rospy.get_rostime()
magMsg.magnetic_field = data.getMagnetometer()
self._pub.publish(msg)
self._pubMag.publish(magMsg)
示例5: rotateQuaternion
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def rotateQuaternion(q_orig, yaw):
"""
Converts a basic rotation about the z-axis (in radians) into the
Quaternion notation required by ROS transform and pose messages.
:Args:
| q_orig (geometry_msgs.msg.Quaternion): to be rotated
| yaw (double): rotate by this amount in radians
:Return:
| (geometry_msgs.msg.Quaternion) q_orig rotated yaw about the z axis
"""
# Create a temporary Quaternion to represent the change in heading
q_headingChange = Quaternion()
p = 0
y = yaw / 2.0
r = 0
sinp = math.sin(p)
siny = math.sin(y)
sinr = math.sin(r)
cosp = math.cos(p)
cosy = math.cos(y)
cosr = math.cos(r)
q_headingChange.x = sinr * cosp * cosy - cosr * sinp * siny
q_headingChange.y = cosr * sinp * cosy + sinr * cosp * siny
q_headingChange.z = cosr * cosp * siny - sinr * sinp * cosy
q_headingChange.w = cosr * cosp * cosy + sinr * sinp * siny
# Multiply new (heading-only) quaternion by the existing (pitch and bank)
# quaternion. Order is important! Original orientation is the second
# argument rotation which will be applied to the quaternion is the first
# argument.
return multiply_quaternions(q_headingChange, q_orig)
示例6: get_ros_quaternion
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def get_ros_quaternion(self, almath_quaternion):
output = Quaternion()
output.w = almath_quaternion.w
output.x = almath_quaternion.x
output.y = almath_quaternion.y
output.z = almath_quaternion.z
return output
示例7: quaternion_to_msg
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def quaternion_to_msg(q):
msg = Quaternion()
msg.x = q[0]
msg.y = q[1]
msg.z = q[2]
msg.w = q[3]
return msg
示例8: array_to_quaternion
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def array_to_quaternion(nparr):
quat = Quaternion()
quat.x = nparr[0]
quat.y = nparr[1]
quat.z = nparr[2]
quat.w = nparr[3]
return quat
示例9: convert_planar_phi_to_quaternion
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def convert_planar_phi_to_quaternion(phi):
quaternion = Quaternion()
quaternion.x = 0
quaternion.y = 0
quaternion.z = math.sin(phi / 2)
quaternion.w = math.cos(phi / 2)
return quaternion
示例10: __init__
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def __init__(self):
position=Point()
rotation=Quaternion()
rospy.init_node('tf_listener')
self.pub = rospy.Publisher('robot_odom', robot_odom, queue_size=10)
self.now=rospy.Time()
self.tf_listener=tf.TransformListener()
rospy.sleep(0.5)
frame='/odom'
wantedframe = self.frame_checker(frame)
while not rospy.is_shutdown():
(po,ro)=self.get_odom(frame,wantedframe)
position.x=po[0]
position.y=po[1]
position.z=po[2]
rotation.x=ro[0]
rotation.y=ro[1]
rotation.z=ro[2]
rotation.w=ro[3]
#rospy.sleep()
self.publish(position,rotation,wantedframe)
#print 'position: \n',position,'\n','rotation: \n',self.quat_to_angle(rotation),'time: ', self.robot_odom.header.stamp
print self.robot_odom,'\nangular: ',self.quat_to_angle(self.robot_odom.rotation)#self.normalize_angle(self.quat_to_angle(self.robot_odom.rotation))
示例11: list_to_dict
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def list_to_dict(lst):
"""
Convert a list to a pose dictionary, assuming it is in the order
x, y, z, orientation x, orientation y, orientation z[, orientation w].
"""
if len(lst) == 6:
qtn = tf.transformations.quaternion_from_euler(lst[3], lst[4], lst[5])
elif len(lst) == 7:
qtn = Quaternion()
qtn.x = lst[3]
qtn.y = lst[4]
qtn.z = lst[5]
qtn.w = lst[6]
else:
raise MoveItCommanderException("""Expected either 6 or 7 elements
in list: (x,y,z,r,p,y) or (x,y,z,qx,qy,qz,qw)""")
pnt = Point()
pnt.x = lst[0]
pnt.y = lst[1]
pnt.z = lst[2]
pose_dict = {
'position': pnt,
'orientation': qtn
}
return pose_dict
示例12: getOrientation
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def getOrientation(self):
ort = Quaternion()
ort.x = self._orientationX
ort.y = self._orientationY
ort.z = self._orientationZ
ort.w = self._orientationW
return ort
示例13: poll
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def poll(self):
(x, y, theta) = self.arduino.arbot_read_odometry()
quaternion = Quaternion()
quaternion.x = 0.0
quaternion.y = 0.0
quaternion.z = sin(theta / 2.0)
quaternion.w = cos(theta / 2.0)
# Create the odometry transform frame broadcaster.
now = rospy.Time.now()
self.odomBroadcaster.sendTransform(
(x, y, 0),
(quaternion.x, quaternion.y, quaternion.z, quaternion.w),
now,
"base_link",
"odom"
)
odom = Odometry()
odom.header.frame_id = "odom"
odom.child_frame_id = "base_link"
odom.header.stamp = now
odom.pose.pose.position.x = x
odom.pose.pose.position.y = y
odom.pose.pose.position.z = 0
odom.pose.pose.orientation = quaternion
odom.twist.twist.linear.x = self.forwardSpeed
odom.twist.twist.linear.y = 0
odom.twist.twist.angular.z = self.angularSpeed
self.arduino.arbot_set_velocity(self.forwardSpeed, self.angularSpeed)
self.odomPub.publish(odom)
示例14: compare_all
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def compare_all(data):
global k
last_row = csv_data[k-frequency_offset]
diff = Quaternion()
diff.x = round(float(last_row[1])-convert_ppm(data.channels[3]),4)
diff.y = round(float(last_row[2])-convert_ppm(data.channels[1]),4)
diff.z = round(float(last_row[4])-convert_ppm(data.channels[0]),4)
diff.w = round(float(last_row[5])+convert_ppm(data.channels[2]),4)
testing_pub.publish(diff)
if (k < len(csv_data)):
row = csv_data[k]
#log for post processing
#joystick log
c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/gps_joy.csv", "ab"))
c.writerow([data.header.stamp.secs,row[1],row[2],row[4],row[5]])
#rc Inn log
c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/rc_in.csv", "ab"))
c.writerow([data.header.stamp.secs,convert_ppm(data.channels[3]),convert_ppm(data.channels[1]),convert_ppm(data.channels[0]),convert_ppm(data.channels[2])])
msg = Joy()
msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
k = k + 1
pub.publish(msg)
else:
#k = 0
print("Joystick & RC In data logged with GPS Time")
exit()
示例15: axis_angle_to_quaternion
# 需要导入模块: from geometry_msgs.msg import Quaternion [as 别名]
# 或者: from geometry_msgs.msg.Quaternion import y [as 别名]
def axis_angle_to_quaternion(axis, angle):
q = Quaternion()
q.x = axis.x * math.sin(angle / 2.0)
q.y = axis.y * math.sin(angle / 2.0)
q.z = axis.z * math.sin(angle / 2.0)
q.w = math.cos(angle / 2.0)
return q