Forums General General Chat Problems for controlling the arm by python

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

    Hi
    I followed the tutorial and tried to write codes on python to control the movement of the machine directly. However, I always failed to connect to the machine, since I got trouble in using Python API. In the file “niryo_one_api.py”, it mentions”import rospy”. I googled “rospy” and added all relevant files into the package of the project. It shows that there are so many unknown variables and I couldn’t find out where they are defined. I don’t know how to deal with this problem.

    Betegustaf
    Participant
    Post count: 14

    First thing that comes to my mind is : are you really running your code on the raspberry Pi (using SSH with putty for example) with your code inside the raspberry like a file : do_something.py ?
    On a remote machine you cant run it until you have everything set up exactly as the Niryo Raspberry Pi, for example you can’t run your code on a windows python shell with a local environment because no modules have been set up so nothing is defined.

    Thalia
    Participant
    Post count: 5

    Thanks for your reply. Actually, I connect the robot with my computer in “hotspot mode”, and then use putty with IP address”10.10.10.10″. Is it correct?

    Betegustaf
    Participant
    Post count: 14

    Seems good to me, it was the “added all relevant files into the package of the project” that triggered me to my reply.
    I got another idea try with a simple programm like:

    #!/usr/bin/env python
    from niryo_one_python_api.niryo_one_api import *
    import rospy
    import time
    rospy.init_node(‘niryo_one_example_python_api’)

    n = NiryoOne()

    n.set_arm_max_velocity(100)
    n.move_pose(0.2,0,0.15,0,0,0)

    And be sure that the #!/usr/bin/env python is here by reopenning your file, this is really important as it locates your python environment, I had issues with this line wich wasnt considered when you copy/paste your script.
    Just a tip: you can use winSCP this software alows you to explore files like the windows explorer wich is more convenient than with linux commands (but still you’ll have to check for the environment line when you will copy a file)

    Thalia
    Participant
    Post count: 5

    Hi Betegustaf
    Thanks a lot! I download WinSCP and put my code inside the folder”niryo_one_python_api”. Then, I wrote the command in putty to execute my code,but got errors(shown below)
    niryo@niryo-pc:~$ ssh niryo@10.10.10.10 ‘source~/catkin_ws/devel/setup.bash&&export PYTHONPATH=${PYTHONPATH}:/home/niryo/catkin_ws/src/niryo_one_python_api/src/ niryo_python_api && python touch_test_python_api.py’
    niryo@10.10.10.10‘s password:
    bash: source~/catkin_ws/devel/setup.bash: No such file or directory

    Have you ever been in a situation like this?
    And one more question is about”chmod+x”, how can we use this command to execute our code?
    Thanks again!

    Best wishes,
    Thalia

    Betegustaf
    Participant
    Post count: 14

    You don’t have to put your code inside the niryo_one_python_api folder, in fact you can put it wherever you want, the thing that matter is the python path wich is guiding python to its environment so having it or not inside this specific folder doesnt change anything to the problem.
    The command that you are trying to use has to be used from your own computer (without putty) this command approximately mean :
    connect by ssh to user ‘niryo’ at ‘ip-adress’
    command 1: source ..
    command 2: export …
    command 3: python test_python.py
    So this single command is actually composed of 4 commands gathered by && separator, and if you understood this you might have already noticed that you were trying to make an ssh connection from the raspberry pi to 10.10.10.10 : ssh inside the ssh (ssh-ception^^).

    Now what you have to do is connecting you to the raspberry with putty, then from putty type the other commands one by one :

    source ~/catkin_ws/devel/setup.bash
    export PYTHONPATH=${PYTHONPATH}:/home/niryo/catkin_ws/src/niryo_one_python_api/src/niryo_python_api
    python my_test_python_api.py

    To make things more convenient if you don’t want to type the first 2 commands you can add them to your bashrc
    The command “chmod +x my_file.py” make the file executable, you only have to use it once (using “ls” you will see that your file color has changed), then you can launch your program from its own repertory with “./my_file.py”

    Thalia
    Participant
    Post count: 5

    I really appreciate your help. It works now! Many thanks.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.