該rosrun命令沒有執(zhí)行我的 python 文件。該命令只是被跳過。我已經(jīng)使用命令使 python 腳本可執(zhí)行 sudo chmod +x controller.py。我無法運行任何 python 文件或 rosrun 命令。即使是Python代碼也沒有錯誤??赡艿膯栴}是什么?我是ROS的新手,所以請指導(dǎo)我。controller.py包含以下代碼:import rospyfrom geometry_msgs.msg import Twist#from sensor_msgs.msg import LaserScanfrom nav_msgs.msg import Odometryfrom tf.transformations import euler_from_quaternionimport mathdef odom_callback(data):? ? global x,y,pose,ebot_theta? ? x? = data.pose.pose.orientation.x? ? y? = data.pose.pose.orientation.y? ? z = data.pose.pose.orientation.z? ? w = data.pose.pose.orientation.w? ? pose = [data.pose.pose.position.x, data.pose.pose.position.y, euler_from_quaternion([x,y,z,w])[2]]? ? ebot_theta=euler_from_quaternion([x,y,z,w])[2]#def laser_callback(msg):? ? #global regions? ? #regions = {? ? ?#? ?'bright':? ? ? ,? ? ? #? 'fright':? ,? ? ? ?# 'front':? ?,? ? ? ?# 'fleft':? ?,? ? ? ? #'bleft':? ? ? ?,? ? #}def Waypoints(t):? ? if t == 0:? ? ? ? h = 0.74? ? ? ? k = 0.488? ? elif t == 1:? ? ? ? h = 1.42? ? ? ? k = 1.289? ?? ? elif t == 2:? ? ? ? h = 1.911? ? ? ? k = 1.54? ? elif t == 3:? ? ? ? h = 2.45? ? ? ? k = 1.2? ? elif t == 4:? ? ? ? h = 3.141?? ? ? ? k = 0?? ? elif t == 5:? ? ? ? h = 3.91?? ? ? ? k = -1.289? ? elif t == 6:? ? ? ? h = 4.373? ? ? ? k = -1.54?? ? elif t == 7:? ? ? ? h = 5.02? ? ? ? k = -1.125? ? elif t == 8:? ? ? ? h = 5.72? ? ? ? k = -0.297? ? elif t == 9:? ? ? ? h = 6.283? ? ? ? k = 0?? ? else:? ? ? ? pass??? ? return [h,k]??def control_loop():? ? rospy.init_node('ebot_controller',anonymous=True)? ??? ? pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)? ? #rospy.Subscriber('/ebot/laser/scan', LaserScan, laser_callback)? ? rospy.Subscriber('/odom', Odometry, odom_callback)? ??? ? rate = rospy.Rate(10)?? ? velocity_msg = Twist()? ? velocity_msg.linear.x = 0? ? velocity_msg.angular.z = 0? ? pub.publish(velocity_msg)? ? i=0? ? while not rospy.is_shutdown() & i<10:? ? ? ??? ? ? ? [x1,y1]=[x,y]? ? ? ? [x2,y2]=Waypoints(i)
2 回答

慕勒3428872
TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊
你的 python 腳本實際上并沒有運行任何東西。可以說它的主要功能是空的。
if __name__ == '__control_loop__':
需要是
if __name__ == '__main__':
請參閱https://docs.python.org/3/library/__main__.html。
另一件錯誤的事情是你使用的&
時候你可能意味著and
:
>>> False & 0<10 True >>> False and 0<10 False
所以改變:
while not rospy.is_shutdown() & i<10:
到
while not rospy.is_shutdown() and i<10:
您還需要將 a 添加spin_once
到循環(huán)中。否則,不會處理任何 ROS 通信。
添加回答
舉報
0/150
提交
取消