diff --git a/README.md b/README.md index 7a7a149406f8dae6cddf81505b68c93aa3c0e132..25d347ab65269f3956a0d72ef496dfb58e207dc1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ur-py-ctl +# ur_py_ctl [](https://pypi.org/project/ur-py-ctl/) [](https://gitlab.control.lth.se/robotlab/ur_py_ctl/-/pipelines) @@ -6,6 +6,10 @@ * [Documentation](https://ur-py-ctl.readthedocs.io/) +## Install + +[Installation instructions](https://ur-py-ctl.readthedocs.io/latest/installation.html) + ## Develop 1. [Install poetry](https://python-poetry.org/docs/#installation) diff --git a/docs/examples.md b/docs/examples.md index df635b4e61303f9498a7b2edbc413cd6df86f06d..832bdea87cac75eabc23b27a2a4963eb141612ec 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -1 +1,16 @@ # Examples + +## Generate URScript +```{literalinclude} examples/generate_urscript.py +``` + +## Send script without feedback + +```{literalinclude} examples/send_script_wo_feedback.py +``` + +## Send script with feedback + +```{note} +TODO: Make better version of [old send_file.py](https://gitlab.control.lth.se/robotlab/ur_py_ctl/-/blob/2a4119dd539067d3803b86e41e974813342a5d5a/ur_py_ctl/send_script.py) +``` diff --git a/docs/examples/generate_urscript.py b/docs/examples/generate_urscript.py new file mode 100644 index 0000000000000000000000000000000000000000..a8bb283a20054d29f62e171ae28606061b9b3ac5 --- /dev/null +++ b/docs/examples/generate_urscript.py @@ -0,0 +1,15 @@ +import math + +from ur_py_ctl import Motion, move_to_conf, move_to_pose + +# rotate joint0 to 45 degrees and the rest to zero moving 10 degrees/s +move_instruction1 = move_to_conf([math.pi / 2, 0, 0, 0, 0, 0], v=math.radians(10)) + +# move to coordinate .250, .500, .300 in a straight line with blend radius 1 cm +# and 250 mm/s +move_instruction2 = move_to_pose( + 0.25, 0.5, 0.3, 0, 0, 0, mode=Motion.LINEAR, r=0.01, v=0.25 +) + +print(move_instruction1) +print(move_instruction2) diff --git a/docs/examples/send_script_wo_feedback.py b/docs/examples/send_script_wo_feedback.py new file mode 100644 index 0000000000000000000000000000000000000000..a0f639cb6a2a23e001abb7dfa830fd9dbf5a91b8 --- /dev/null +++ b/docs/examples/send_script_wo_feedback.py @@ -0,0 +1,52 @@ +import logging +import socket + +import ur_py_ctl.urscript_commands as ur_cmd + +TAB = " " + +SERVER_ADRESS = "marius-vikarie.d.control.lth.se" +SERVER_PORT = 30002 + + +def get_script(): + script = "def program():\n" + script += TAB + ur_cmd.popup("Program starting.") + "\n" + + script += TAB + ur_cmd.set_tcp(0, 0, 0, 0, 0, 0) + "\n" + + for i in range(10): + + script += ( + TAB + + ur_cmd.move_to_pose( + -0.1 + i * 0.01, 0, 0.3, 0, 0, 0, v=50 / 1000, r=5 / 1000 + ) + + "\n" + ) + script += TAB + ur_cmd.text_msg(f"Sending command number: {i}") + "\n" + + script += ur_cmd.text_msg("End program") + script += "end\n\n" + script += "program()\n" + + return script.encode() + + +def send_script(): + + send_socket = socket.create_connection((SERVER_ADRESS, SERVER_PORT), timeout=2) + send_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + script = get_script() + + # send file + send_socket.send(script) + + send_socket.close() + + logging.debug("File sent") + + +if __name__ == "__main__": + send_script() diff --git a/docs/index.md b/docs/index.md index fa2a2b515a6d940cf3eba5f9d6bbfe23021c12a6..5903c3342c120598de437ee4a9f6bd4b4153a105 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,6 +5,7 @@ maxdepth: 1 caption: Contents --- +installation examples reference ``` diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000000000000000000000000000000000000..b34f51d28745bc2f47cca0974eeac5d64a6848ba --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,51 @@ +# Installation instructions + +This package is intended to be used as a library, and should be installed into +a python environment and imported into the users own code. + +Python includes a tool for creating environments called {py:mod}`venv`. +Anaconda is another alternative that is especially useful on Windows since it +does not only deal with Python dependencies but C/C++ dependencies and more. +Popular packages such as NumPy and OpenCV has non-Python deps that can be +managed using [Anaconda](https://www.anaconda.com/) or some other good package manager. + +```{tip} +Anaconda is cross platform and solves a lot of dependency headaches. Together +with an IDE like VS Code (also cross platform and well suited for Python) is a +good starting point. + +There is a very helpful guide to get started on VS Code's documentation website +titled +[Getting Started with Python in VS Code](https://code.visualstudio.com/docs/python/python-tutorial) +``` + +## Set up environment + +### Using Anaconda + +```bash +conda config --add channels conda-forge +conda create -n my_project python=3.10 +conda activate my_project +``` + +### Using `virtualenv` + +```bash +virtualenv --python=python3.8 {{path/to/venv}} +source {{path/to/venv}}/bin/activate +``` + +## Install package + +### Latest release + +```bash +pip install ur_py_ctl +``` + +### Latest commit + +```bash +pip install git+https://gitlab.control.lth.se/robotlab/ur_py_ctl +```