diff --git a/sensing/slam/laser_slam/script/laser_transfer.py b/sensing/slam/laser_slam/script/laser_transfer.py index 73cb3ec..f824256 100755 --- a/sensing/slam/laser_slam/script/laser_transfer.py +++ b/sensing/slam/laser_slam/script/laser_transfer.py @@ -2,7 +2,7 @@ import rospy from gazebo_msgs.srv import GetModelState from geometry_msgs.msg import PoseStamped from nav_msgs.msg import Odometry -import tf +from tf2_ros import TransformListener, Buffer import sys vehicle_type = sys.argv[1] @@ -10,6 +10,8 @@ vehicle_id = sys.argv[2] laser_slam_type = sys.argv[3] rospy.init_node(vehicle_type+vehicle_id+'_'+laser_slam_type+'_laser_transfer') pose_pub = rospy.Publisher(vehicle_type+'_'+ vehicle_id+"/mavros/vision_pose/pose", PoseStamped, queue_size=2) +tfBuffer = Buffer() +tflistener = TransformListener(tfBuffer) local_pose = PoseStamped() hector = PoseStamped() height = 0 @@ -17,11 +19,6 @@ height = 0 def odm_groundtruth_callback(msg): global height height = msg.pose.pose.position.z - -def odm_aloam_callback(msg): - global local_pose - local_pose.header.stamp = msg.header.stamp - local_pose.pose = msg.pose.pose def hector_callback(data): global hector @@ -39,18 +36,24 @@ def hector_slam(): def aloam(): global local_pose - rate = rospy.Rate(100) - while True: + rate = rospy.Rate(30) + while not rospy.is_shutdown(): + try: + tfstamped = tfBuffer.lookup_transform('camera_init', 'aft_mapped', rospy.Time(0)) + except: + continue + local_pose.header.stamp = rospy.Time().now() + local_pose.header.frame_id = 'map' + local_pose.pose.position = tfstamped.transform.translation + local_pose.pose.orientation = tfstamped.transform.rotation pose_pub.publish(local_pose) rate.sleep() if __name__ == '__main__': - if laser_slam_type == '2d': odom_groundtruth_sub = rospy.Subscriber('/xtdrone/'+vehicle_type+'_'+ vehicle_id+'/ground_truth/odom', Odometry, odm_groundtruth_callback) hector_slam() elif laser_slam_type == '3d': - odom_aloam_sub = rospy.Subscriber('/laser_odom_to_init', Odometry, odm_aloam_callback) aloam() else: print('input error') diff --git a/sensing/slam/laser_slam/script/laser_transfer_old.py b/sensing/slam/laser_slam/script/laser_transfer_old.py index 5b46dfd..88f8174 100644 --- a/sensing/slam/laser_slam/script/laser_transfer_old.py +++ b/sensing/slam/laser_slam/script/laser_transfer_old.py @@ -2,7 +2,7 @@ import rospy from gazebo_msgs.srv import GetModelState from geometry_msgs.msg import PoseStamped, Pose2D from nav_msgs.msg import Odometry -import tf +from tf2_ros import TransformListener, Buffer import sys vehicle_type = sys.argv[1] @@ -18,11 +18,6 @@ def odm_groundtruth_callback(msg): global local_pose local_pose.header.stamp = msg.header.stamp local_pose.pose.position.z = msg.pose.pose.position.z - -def odm_aloam_callback(msg): - global local_pose - local_pose.header.stamp = msg.header.stamp - local_pose.pose = msg.pose.pose def laser_scan_matcher_callback(data): global laser_scan @@ -46,8 +41,16 @@ def laser_scan_matcher(): def aloam(): global local_pose - rate = rospy.Rate(100) - while True: + rate = rospy.Rate(30) + while not rospy.is_shutdown(): + try: + tfstamped = tfBuffer.lookup_transform('camera_init', 'aft_mapped', rospy.Time(0)) + except: + continue + local_pose.header.stamp = rospy.Time().now() + local_pose.header.frame_id = 'map' + local_pose.pose.position = tfstamped.transform.translation + local_pose.pose.orientation = tfstamped.transform.rotation pose_pub.publish(local_pose) rate.sleep() @@ -57,7 +60,6 @@ if __name__ == '__main__': odom_groundtruth_sub = rospy.Subscriber('/xtdrone/'+vehicle_type+'_'+ vehicle_id+'/ground_truth/odom', Odometry, odm_groundtruth_callback) laser_scan_matcher() elif laser_slam_type == '3d': - odom_aloam_sub = rospy.Subscriber('/laser_odom_to_init', Odometry, odm_aloam_callback) aloam() else: print('input error') diff --git a/sitl_config/worlds/indoor1.world b/sitl_config/worlds/indoor1.world index 7c16b7b..1402b6c 100644 --- a/sitl_config/worlds/indoor1.world +++ b/sitl_config/worlds/indoor1.world @@ -11,7 +11,7 @@ 100 100 - + 100 @@ -25,7 +25,7 @@ - + 10 @@ -95,7 +95,7 @@ 10 - + @@ -106,7 +106,7 @@ - + -5.03 0.53 1.415 0 -0 0 @@ -116,7 +116,7 @@ 10 - + @@ -127,7 +127,7 @@ - + 4.24 -0.31 1.415 0 -0 0 @@ -137,7 +137,7 @@ 10 - + @@ -148,7 +148,7 @@ - + @@ -159,7 +159,7 @@ 10 - + @@ -170,7 +170,7 @@ - + 3.155 10.4 1.435 0 -0 0 @@ -180,7 +180,7 @@ 10 - + @@ -191,7 +191,7 @@ - + 0.615 -10.98 1.415 0 -0 0 @@ -201,7 +201,7 @@ 10 - + @@ -212,7 +212,7 @@ - + -4.62 -10.98 1.415 0 -0 0 @@ -222,7 +222,7 @@ 10 - + @@ -233,7 +233,7 @@ - + -3.61 -10.98 2.69 0 -0 0 @@ -243,7 +243,7 @@ 10 - + @@ -254,7 +254,7 @@ - + -4.385 0.26 0.95 0 -0 0 @@ -264,7 +264,7 @@ 10 - + @@ -275,7 +275,7 @@ - + @@ -320,7 +320,7 @@ -2.31327 0 1.425 0 -0 0 10 - + @@ -331,7 +331,7 @@ - + 1.18673 0 0.25 0 -0 0 @@ -359,7 +359,7 @@ 1.18673 0 0.25 0 -0 0 10 - + @@ -370,7 +370,7 @@ - + 2.68673 0 1.675 0 -0 0 @@ -398,7 +398,7 @@ 2.68673 0 1.675 0 -0 0 10 - + @@ -409,7 +409,7 @@ - + 0.37346 0 2.575 0 -0 0 @@ -437,7 +437,7 @@ 0.37346 0 2.575 0 -0 0 10 - + @@ -448,7 +448,7 @@ - + 0 0 @@ -482,7 +482,7 @@ -1.53914 0 1.425 0 -0 0 10 - + @@ -493,7 +493,7 @@ - + 1.69286 0 1.425 0 -0 0 @@ -521,7 +521,7 @@ 1.69286 0 1.425 0 -0 0 10 - + @@ -532,7 +532,7 @@ - + 0.153711 0 0 0 -0 0 @@ -560,7 +560,7 @@ 0.153711 0 0 0 -0 0 10 - + @@ -571,7 +571,7 @@ - + 0.153711 0 2.425 0 -0 0 @@ -599,7 +599,7 @@ 0.153711 0 2.425 0 -0 0 10 - + @@ -610,7 +610,7 @@ - + 0 0 @@ -773,27 +773,12 @@ 0.766851 -12.0385 1 0 -0 0 - - -2.25143 -7.57347 1 0 -0 0 - 2.80305 -7.33891 1.86283 -0.49865 0 0 0.076075 -5.91752 1 0 -0 0 - - -4.36942 -10.4942 1 0 -0 0 - - - -3.92433 -9.26622 1 0 -0 0 - - - -3.73468 -12.8798 1 0 -0 0 - - - -3.8302 -8.15565 1 0 -0 0 - 1 @@ -806,7 +791,7 @@ 10 - + @@ -817,7 +802,7 @@ - + 0 0 0.37 0 -0 0 @@ -827,7 +812,7 @@ 10 - + @@ -838,7 +823,7 @@ - + 0 0 0.02 0 -0 0 @@ -848,7 +833,7 @@ 10 - + @@ -859,7 +844,7 @@ - + @@ -902,7 +887,7 @@ 0.387354 0.387354 0.0254 - + 0.1 @@ -919,7 +904,7 @@ - + 10 @@ -929,7 +914,7 @@ 0.387354 0.387354 0.0254 - + 0.1 @@ -946,7 +931,7 @@ - + 10 @@ -956,7 +941,7 @@ 0.387354 0.020643 0.092075 - + 0.1 @@ -973,7 +958,7 @@ - + 10 @@ -983,7 +968,7 @@ 0.387354 0.020643 0.092075 - + 0.1 @@ -1000,7 +985,7 @@ - + 10 @@ -1010,7 +995,7 @@ 0.387354 0.0254 0.092075 - + 0.1 @@ -1027,7 +1012,7 @@ - + 10 0 @@ -1057,7 +1042,7 @@ model://coke_can/meshes/coke_can.dae - + 1 @@ -1076,7 +1061,7 @@ - + 10 @@ -1104,7 +1089,7 @@ 10 - + @@ -1115,7 +1100,7 @@ - + 0 0 0.37 0 -0 0 @@ -1125,7 +1110,7 @@ 10 - + @@ -1136,7 +1121,7 @@ - + 0 0 0.02 0 -0 0 @@ -1146,7 +1131,7 @@ 10 - + @@ -1157,7 +1142,7 @@ - + @@ -1194,7 +1179,7 @@ 10 - + @@ -1205,7 +1190,7 @@ - + 0 0.20063 0.3048 0 -0 0 @@ -1215,7 +1200,7 @@ 10 - + @@ -1226,7 +1211,7 @@ - + 0 -0.20063 0.3048 0 -0 0 @@ -1236,7 +1221,7 @@ 10 - + @@ -1247,7 +1232,7 @@ - + 0.32585 0 0.3048 0 -0 0 @@ -1257,7 +1242,7 @@ 10 - + @@ -1268,7 +1253,7 @@ - + -0.32585 0 0.3048 0 -0 0 @@ -1278,7 +1263,7 @@ 10 - + @@ -1289,7 +1274,7 @@ - + 0 -0.18 0.14155 0.061147 -0 0 @@ -1299,7 +1284,7 @@ 10 - + @@ -1310,7 +1295,7 @@ - + 0 0.18 0.14155 -0.061147 0 0 @@ -1320,7 +1305,7 @@ 10 - + @@ -1331,7 +1316,7 @@ - + 0.305 0 0.14155 0 0.061147 0 @@ -1341,7 +1326,7 @@ 10 - + @@ -1352,7 +1337,7 @@ - + -0.305 0 0.14155 0 -0.061147 0 @@ -1362,7 +1347,7 @@ 10 - + @@ -1373,7 +1358,7 @@ - + 0 0 0.01 0 -0 0 @@ -1383,7 +1368,7 @@ 10 - + @@ -1394,7 +1379,7 @@ - + 0.30202 -0.175 0.14155 0.061147 0.061147 -0 @@ -1405,7 +1390,7 @@ 10 - + @@ -1416,7 +1401,7 @@ - + -0.30202 -0.175 0.14155 0.061147 -0.061147 0 @@ -1427,7 +1412,7 @@ 10 - + @@ -1438,7 +1423,7 @@ - + -0.30202 0.175 0.14155 -0.061147 -0.061147 -0 @@ -1449,7 +1434,7 @@ 10 - + @@ -1460,7 +1445,7 @@ - + 0.30202 0.175 0.14155 -0.061147 0.061147 0 @@ -1471,7 +1456,7 @@ 10 - + @@ -1482,7 +1467,7 @@ - + @@ -1556,19 +1541,6 @@ 1 - - -2.25143 -7.57347 1 0 -0 0 - 0.5 0.5 0.5 1 - 0.1 0.1 0.1 1 - - 20 - 0.5 - 0.01 - 0.001 - - 0 - 0 0 -1 - 2.80305 -7.84683 1 0 -0 0 0.5 0.5 0.5 1 @@ -1621,58 +1593,6 @@ 0 0 0 -1 - - -4.36942 -10.4942 1 0 -0 0 - 0.5 0.5 0.5 1 - 0.1 0.1 0.1 1 - - 20 - 0.5 - 0.01 - 0.001 - - 0 - 0 0 -1 - - - -3.92433 -9.26622 1 0 -0 0 - 0.5 0.5 0.5 1 - 0.1 0.1 0.1 1 - - 20 - 0.5 - 0.01 - 0.001 - - 0 - 0 0 -1 - - - -3.73468 -12.8798 1 0 -0 0 - 0.5 0.5 0.5 1 - 0.1 0.1 0.1 1 - - 20 - 0.5 - 0.01 - 0.001 - - 0 - 0 0 -1 - - - -3.8302 -8.15565 1 0 -0 0 - 0.5 0.5 0.5 1 - 0.1 0.1 0.1 1 - - 20 - 0.5 - 0.01 - 0.001 - - 0 - 0 0 -1 - 1 @@ -1687,7 +1607,7 @@ 10 - + @@ -1698,7 +1618,7 @@ - + 0 0.005 0.6 0 -0 0 @@ -1722,7 +1642,7 @@ 10 - + @@ -1733,7 +1653,7 @@ - + 0.45 -0.195 0.6 0 -0 0 @@ -1757,7 +1677,7 @@ 10 - + @@ -1768,7 +1688,7 @@ - + -0.45 -0.195 0.6 0 -0 0 @@ -1792,7 +1712,7 @@ 10 - + @@ -1803,7 +1723,7 @@ - + 0 -0.195 0.03 0 -0 0 @@ -1827,7 +1747,7 @@ 10 - + @@ -1838,7 +1758,7 @@ - + 0 -0.195 1.19 0 -0 0 @@ -1862,7 +1782,7 @@ 10 - + @@ -1873,7 +1793,7 @@ - + 0 -0.195 0.43 0 -0 0 @@ -1897,7 +1817,7 @@ 10 - + @@ -1908,7 +1828,7 @@ - + 0 -0.195 0.8 0 -0 0 @@ -1944,7 +1864,7 @@ 10 - + @@ -1955,7 +1875,7 @@ - + 0 0.005 0.6 0 -0 0 @@ -1979,7 +1899,7 @@ 10 - + @@ -1990,7 +1910,7 @@ - + 0.45 -0.195 0.6 0 -0 0 @@ -2014,7 +1934,7 @@ 10 - + @@ -2025,7 +1945,7 @@ - + -0.45 -0.195 0.6 0 -0 0 @@ -2049,7 +1969,7 @@ 10 - + @@ -2060,7 +1980,7 @@ - + 0 -0.195 0.03 0 -0 0 @@ -2084,7 +2004,7 @@ 10 - + @@ -2095,7 +2015,7 @@ - + 0 -0.195 1.19 0 -0 0 @@ -2119,7 +2039,7 @@ 10 - + @@ -2130,7 +2050,7 @@ - + 0 -0.195 0.43 0 -0 0 @@ -2154,7 +2074,7 @@ 10 - + @@ -2165,7 +2085,7 @@ - + 0 -0.195 0.8 0 -0 0 @@ -2210,7 +2130,7 @@ 10 - + @@ -2221,7 +2141,7 @@ - + 0 0 0.01 0 -0 0 @@ -2245,7 +2165,7 @@ 10 - + @@ -2256,7 +2176,7 @@ - + 0.235 0 0.51 0 -0 0 @@ -2280,7 +2200,7 @@ 10 - + @@ -2291,7 +2211,7 @@ - + 0 0.235 0.51 0 -0 0 @@ -2315,7 +2235,7 @@ 10 - + @@ -2326,7 +2246,7 @@ - + 0 0 0.51 0 -0 0 @@ -2350,7 +2270,7 @@ 10 - + @@ -2361,7 +2281,7 @@ - + 0 -0.235 0.51 0 -0 0 @@ -2385,7 +2305,7 @@ 10 - + @@ -2396,7 +2316,7 @@ - + 0 0 1.01 0 -0 0 @@ -2429,7 +2349,7 @@ 0 0 1.25 0 -0 0 10 - + @@ -2440,7 +2360,7 @@ - + 0 0 1.25 0 -0 0 @@ -2474,7 +2394,7 @@ 0 0 1.25 0 -0 0 10 - + @@ -2485,7 +2405,7 @@ - + 0 0 1.25 0 -0 0