由于不同算法之间的坐标系不同,导致计算的结果混乱,该博客的目的是记录和统一不同算法之间的坐标系,保证坐标系的统一
import rospy
from geometry_msgs.msg import PoseStamped, Point
from nav_msgs.msg import Odometry
import math
from pyquaternion import Quaternion
import tf
import sysvehicle_type = sys.argv[1]
vehicle_id = sys.argv[2]
local_pose = PoseStamped()
local_pose.header.frame_id = 'world'
quaternion = tf.transformations.quaternion_from_euler(0, -math.pi/2, math.pi/2)
q = Quaternion([quaternion[3],quaternion[0],quaternion[1],quaternion[2]])def vins_callback(data): local_pose.pose.position.x = data.pose.pose.position.xlocal_pose.pose.position.y = data.pose.pose.position.ylocal_pose.pose.position.z = data.pose.pose.position.zq_= Quaternion([data.pose.pose.orientation.w,data.pose.pose.orientation.x,data.pose.pose.orientation.y,data.pose.pose.orientation.z])q_ = q_*qlocal_pose.pose.orientation.w = q_[0]local_pose.pose.orientation.x = q_[1]local_pose.pose.orientation.y = q_[2]local_pose.pose.orientation.z = q_[3]rospy.init_node(vehicle_type+"_"+vehicle_id+'_vins_transfer')
rospy.Subscriber("/vins_estimator/camera_pose", Odometry, vins_callback,queue_size=1)
position_pub = rospy.Publisher(vehicle_type+"_"+vehicle_id+"/mavros/vision_pose/pose", PoseStamped, queue_size=1)
rate = rospy.Rate(30) while not rospy.is_shutdown():if (local_pose.pose.position == Point()):continueelse:print("Vins pose received")local_pose.header.stamp = rospy.Time.now()position_pub.publish(local_pose) try:rate.sleep()except:continue
q = Quaternion([quaternion[3],quaternion[0],quaternion[1],quaternion[2]]) # 这是因为得到的是xyzw,但是要转为wxyz
q_= Quaternion([data.pose.pose.orientation.w,data.pose.pose.orientation.x,data.pose.pose.orientation.y,data.pose.pose.orientation.z]) q_ = q_*q # 这是让原有视觉WXYZ进行一个坐标转换,得到的转换结果