Forums Niryo One Troubleshooting Starting Python Script on Startup

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • GoGoWe
    Participant
    Post count: 4

    Hello Niryo Community,

    After 4h of troubleshooting, I decided to describe my problem here.

    Short description:

    Script only works if it is NOT executed as sudo.
    I need an answer to: How can I execute myScript.py with sudo OR How can I execute myScript.py automatically on bootup

     

    Long description:

    I have a python Script (niryo_action.py) in my home directory (home/niryo).
    I connect to the Raspberry via SSH/PuTTY with the default niryo user and type in following command: “python niryo_action.py”
    The script executes and everything runs perfectly

    I want the script to run 1 minute after boot. So I write a small autostart.sh script with following code:
    sleep 1m
    cd /home/niryo
    python niryo_action.py

     

    If I start the script like this: “sh autostart.sh”, everything works fine.
    But if i try to start it via any autostart tool (crontab, rc.local, init.d) I always get the same error:
    Traceback (most recent call last):
    File “niryo_action.py”, line 2, in <module>
    from niryo_one_python_api.niryo_one_api import *
    ImportError: No module named niryo_one_python_api.niryo_one_api

    The error also appears if I use sudo to start the scripts (e.g “sudo sh autostart.sh” -> error, “sudo python niryo_action.py” -> error)

     

    I already tried the long command described in the documentation here. But this still did not help. If I type the command into a script it tells me there is no such command like “<span class=”fusion-highlight light rounded highlight1″>source </span>” and if I type the command directly into the console with sudo I get the same error.

     

    Thank you for your help

    S.Imura
    Participant
    Post count: 9

    Hi GoGoWe

    Please, make sure the below page.

    You can execute your python script on bootup without “sudo command or other file”.

    Let’s try it!

    cducatez
    Keymaster
    Post count: 10

    Hi,
    1) If you want to do the “sudo” way, the problem is that in “sudo mode”, the linux user change to ‘root’ for the execution so it’s not the same environment as ‘Niryo’ user, so the “export PYTHONPATH…” isn’t changing the root user environment but the Niryo env’.
    If you just set the PYTHONPATH temporary for each execution like this it should be fine:
    sudo PYTHONPATH=${PYTHONPATH}:/home/niryo/catkin_ws/src/niryo_one_python_api/src/niryo_python_api python your_script.py

    2) But for your case, it may be better to use the method described in the topics linked by S.Imura so your script is executed at the end of ROS loading and not after a “fixed” time of 1 minute

    Best regards

    GoGoWe
    Participant
    Post count: 4

    Hello,
    Thank you for your answers.

    The first method sounds easy and I wanted to try it out but unfortunately, I could not find any directory named “niryo_one_ros”.
    Only found those paths:
    “./sys/fs/cgroup/systemd/system.slice/niryo_one_ros.service”
    “./home/niryo/catkin_ws/src/niryo_one_rpi/scripts/niryo_one_ros_setup.pyc”
    “./home/niryo/catkin_ws/src/niryo_one_rpi/scripts/niryo_one_ros_setup.py”

    GoGoWe
    Participant
    Post count: 4

    PUSH(?)

    MorrisTaipei
    Participant
    Post count: 14

    Ha,

    I have the same issue that need to start py on boot.

    BUT I use work around solution to start our python code.

    1. prepare a WIN pc (can run putty to connect to your niryo) try lattepanda is a good board.
    2. use xx.bat (putty niryo@192.168.x.x:22 -pw robotics )
    3. download tiny task and record your activities into xx.exe (click xx.bat and keyin python urcode.py)
    4. put xx.exe into WIN startup (execute xx.exe on boot after 5mins-make sure niryo is running)

    turn on
    1.niryo
    2.win 10 pc(like lattepanda) inc xx.exe on boot

    all done well.
    YES, I knew your pain.
    Niryo is fine for “1 hr” education training only.

    MorrisTaipei
    Participant
    Post count: 14

    Just guess why startup script not working. JUST GUESS!!!

    It is because of Niryo “must doing Calibration before running your python code”.

    I try all linux startup code like /etc/rc.local NEVER working…

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.