Cannot run node with rosrun but only python
Hello,
I have an arm based system, with ubuntu 18.04 running melodic
. I have a sample code to run a node that only publishes an array defied in a custom message:
import rospy
from dma.msg import dma_data
def dma_loop():
pub = rospy.Publisher('DMA_output', dma_data, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(2) # 10hz
vec = dma_data()
num = 0
while not rospy.is_shutdown():
#hello_str = "hello world %s" % rospy.get_time()
#rospy.loginfo(hello_str)
#pub.publish(hello_str)
num = num + 1
if num>251:
num=0
vec.array = [num, num, num, num, num]
#for i in range(5):
# vec.array[i] = num
pub.publish(vec)
rate.sleep()
if __name__ == '__main__':
try:
dma_loop()
except rospy.ROSInterruptException:
pass
After running catkin_make
and sourcing devel/setup.bash
if I run rosrun, I get:
xilinx@pynq:~$ rosrun dma loop.py
/home/xilinx/catkin_ws/src/dma/scripts/loop.py: line 1: import: command not found
from: can't read /var/mail/dma.msg
/home/xilinx/catkin_ws/src/dma/scripts/loop.py: line 4: syntax error near unexpected token `('
/home/xilinx/catkin_ws/src/dma/scripts/loop.py: line 4: `def dma_loop():'
However, if I execute it directly with python it works and I can echo the topic that it publishes. Is there something else to do?
Thank you.