Python Import not being recognized
Hi guys,
I'm currently working through a textbook call Programming Robots with ROS. There is a chapter that goes over a simple movement code for a turtlebot simulator. The code is pasted below.
# BEGIN ALL
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) #<1>
rospy.init_node('red_light_green_light')
red_light_twist = Twist() #<2>
green_light_twist = Twist()
green_light_twist.linear.x = 0.5 #<3>
driving_forward = False
light_change_time = rospy.Time.now()
rate = rospy.Rate(10)
while not rospy.is_shutdown():
if driving_forward:
cmd_vel_pub.publish(green_light_twist) #<4>
else:
cmd_vel_pub.publish(red_light_twist)
# BEGIN PART_1
if rospy.Time.now() > light_change_time: #<5>
driving_forward = not driving_forward
light_change_time = rospy.Time.now() + rospy.Duration(3)
# END PART_1
rate.sleep() #<6>
# END ALL
Nothing seems to be wrong with the code itself. However, when I run
chmod +x red_light_green_light.py
followed by
./red_light_green_light.py cmd_vel:=cmd_vel_mux/input/teleop
I receive the following errors:
./red_light_green_light.py: line 3: import: command not found
from: can't read /var/mail/geometry_msgs.msg
./red_light_green_light.py: line 6: syntax error near unexpected token `('
./red_light_green_light.py: line 6: `cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) #<1>'
I'm not clear to the second and third error, but the firs error is claiming to not be able to find import rospy. Any assistance would be greatly appreciated.
Cheers,