import rospy
from geometry_msgs.msg import Twist
def doMsg(data):
rospy.loginfo(data.linear.x)
if __name__ == "__main__":
rospy.init_node("listener_p")
sub = Subscriber("cmd_vel", Twist, doMsg, queue_size=1)
rospy.spin()
catkin_make 时没有问题,rosrun时出现如下问题未预期的符号‘(‘附近有语法错误。
查了好长时间,发现语法并没有任何问题,后来发现在代码首行加入#!/usr/bin/env python
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
def doMsg(data):
rospy.loginfo(data.linear.x)
if __name__ == "__main__":
rospy.init_node("listener_p")
sub = Subscriber("cmd_vel", Twist, doMsg, queue_size=1)
rospy.spin()