Students of the TU-Dresden can use the professional version of PyCharm (and most of the JetBrains products) for free for educational use. Go to Jetbrains-Students and fill out the form, note that you have to use your university email address (@tu-dresden.de or @mailbox.tu-dresden.de). You will receive your license key via email there. The following instructions assume that you are using the professional version of PyCharm and it might not work with the free versions.
This will section will show you how to register your robot as a SFTP-Server in PyCharm which will allow you to use the remote file-browser (Tools>Deployment>Browse Remote Host) and uploading your files to the robot (Tools>Deployment>Upload to…).
Select "Tools>Deployment>Configuration…" from the menu bar at the top.
In the newly created window, select "+" from the top left or press "Insert".
Choose any name for the server and select SFTP as type. Note that this name is only for your convenience.
Enter the IP (eg. 188.8.131.52) as the SFTP host. Port should remain 22.
Now enter your username (robot) and the password (select Auth type "Password" if it isn’t already selected). It is recommended to save the password.
Press "Test SFTP Connection" to ensure that the connection is working.
You can now either set the root path manually or press "Autodetect" and let PyCharm do its thing.
Select the tab Mappings and remove any mappings which are not related to your project and point your local "src" folder to "/src".
Open PyCharm (duh)
Open your project
In the newly opened window navigate to "Project: […]>Project Interpreter"
Click on the Gear-Button next to the selected project Interpreter and select "Add Remote"
Select "SSH Credentials"
Enter your credentials
Host: [The IP-address of the robot]
User name: robot
Auth type: Password
Password: [password, the default is "maker"]
Python interpreter path: /usr/bin/python3
Make sure that you can reach the robot (eg. that you are connected to the correct network). PyCharm will try to establish a connection to the robot.
PyCharm will probably start downloading the PyCharm-Helpers to the robot. This is a background process which needs to be completed before you can use the remote-interpreter, you can however continue with this tutorial while this runs.
Select the remote-interpreter as the Project Interpreter in the Settings-Menu and press Apply and OK.
PyCharm supports multiple "run-configurations". You can see the currently selected configuration (drop-down-Menu) next to the run-buttons on the top-right corner. Configurations can be used to switch between different "run-modes". You might add a configuration which uses your local interpreter to run some tests and another which runs your script on the robot. This section will guide you through the steps needed to add a new configuration.
Open PyCharm (like, obviously)
Click on the previously mentioned drop-down menu. Note that it might be empty if no configuration could be created automatically.
Select "Edit Configurations…"
Click on the green plus (or press Alt+Insert) and choose "Python"
Fill in the fields
Name: The text you want to see in the configuration drop-down menu. Common examples are "Remote main", "Local […]-test", …
Script path: The path to the file you want to execute. Note that you can set this with a file-browser by clicking on the three dots next to the field.
Parameters: If you don’t know what this is you wont need it. Sets the command-line arguments which can later be retrieved with sys.args
Environment variables: If you don’t know what this is, just leave it at "PYTHONUNBUFFERED=1".
Python interpreter: The interpreter you want to use to run the script-file. If you want to run the file locally, select a local interpreter, for remote execution select a remtoe interpreter (see "Remote Interpreter").
Interpreter options: Parameters for the interpreter. This can be used to leave the python-interpreter open after execution, but is not needed in most cases-
Working directory: The path in which the path which will be used when you enter relative path in your code (eg. "./planet.py" with WD "C:/Users/User/RoboLab" will become "C:/Users/User/RoboLab/planet.py")
Add content roots to PYTHONPATH: If you cant guess what this does, just leave it checked.
Add source roots to PYTHONPATH: If you cant guess what this does, just leave it checked.
Press Apply and OK
Select your new configuration from the drop-down-menu.
To start the program, press the green arrow. To enter debugging-mode, press the green ant next to it instead. Execution can be stopped with the red square which might transform into a skull while the process is stopping. The skull can be pressed again to kill the process.
This usually means that the project root is not the same as the source-root. To test this, try importing from "src.[filename]" or "[folder_name].src.[filename]". Note that this will still prevent the script from running correctly on the brick, so now we have to make the old import-statement work.
Open PyCharm (…) and your project
Go to "Project: [name]>Project Structure"
Navigate to the src folder of your project and select it.
Press "Sources" (blue folder) to mark the selected src-folder as a sources-folder.
Press Apply and OK, the modules should now also be found locally and offer correct auto-completion (might take some seconds or restarting PyCharm to update)
Description will be added soon.
Description will be added soon.