ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Cannot run node with rosrun but only python

asked 2020-09-25 09:42:54 -0600

Ariel gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-25 10:47:08 -0600

gvdhoorn gravatar image

It's very likely your script is not executable.

It also doesn't have a shebang.

Run chmod +x loop.py and add #!/usr/bin/env python as the shebang.

edit flag offensive delete link more

Comments

And note: this is not ROS specific.

gvdhoorn gravatar image gvdhoorn  ( 2020-09-25 10:47:59 -0600 )edit

I missed the #!/usr/bin/env python. Thanks for the answer.

Ariel gravatar image Ariel  ( 2020-09-25 10:51:33 -0600 )edit

I don't know if I should open a new thread for this.... I want to include in the same python code that only works with sudo python3.6 script.py. That would not work here, right?

Ariel gravatar image Ariel  ( 2020-09-25 10:53:28 -0600 )edit

Please search for older Q&As around this topic (use Google: append site:answers.ros.org to your query).

The answer is not using sudo.

Give the user that starts the node access to the resource instead.

gvdhoorn gravatar image gvdhoorn  ( 2020-09-25 10:54:44 -0600 )edit

sudo could be circumvented if I understood what you mean by "Give the user that starts the node access to the resource instead.". But what about python3.6?

Ariel gravatar image Ariel  ( 2020-09-25 11:00:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-09-25 09:42:54 -0600

Seen: 1,693 times

Last updated: Sep 25 '20