Friday, February 15, 2019

Python and the EV3: Part 3 A Development Environment

This is part of a series, if you haven't already, go read the previous installments:
Part 1: Installing EV3Dev

What's a development environment?


A development environment is [usually] an application that you use to write your program.  It often comes with the ability to have multiple files open at once, automatic formatting for your code, color-coding of your code, and something that will let you know if you have errors.  Sometimes it also includes extras like version control (being able to update and roll back changes), deployment (sending files off to another location), and sftp (editing files on a different computer).  So all in all, it is much handier than just writing your code in a text file and copying it over to your EV3.

How do I get one?


There are three environments that I have played with and generally like:  BBEdit, Atom, and Visual Studio Code.  I eventually settled on Visual Studio Code, so I'll talk about how to set up that one, but it won't matter beyond the setup stage which one you choose.

Visual Studio Code.

Head over, download, and install a copy of Visual Studio Code.  Once you've got that installed, opened up, and running, you'll want to install a deployment extension.  Just like in Chrome or Firefox, extensions are bits that people have written to add functionality to the application.  Head over to the deploy extension and click "Install".  This will allow you to edit files locally and send them off to your robot every time you save them.

In order to setup deploy, you'll need to click the settings icon in the bottom left of the screen and choose "Settings." In the new pane that pops open, scroll down to extensions and choose "Deploy."  Click the link "Edit in settings.json" and copy the text below into the new "User Settings" pane that opens.

{
    "deploy": {
        "packages": [
            {
                "name": "robut",
                "description": "robut schtuff",
                "files": [
                    "*/*.py",
                    "*.py"
                ],
                "deployOnSave": true
            }
        ],

        "targets": [
        {
            "type": "sftp",
            "name": "robut",
            "description": "The ev3",

            "dir": "/home/robot/robut",
            "host": "ev3dev.local", "port": 22,
            "user": "robot", "password": "maker"
        }
        ]
    }
}

You'll want to change the name and description in 'packages' to match the local folder that holds your python files and whatever description you want.  Similarly, you'll want to change the name, description, and dir file in 'targets.'  This sends any python files in your local folder and any of its subfolders off to your robot to be run there.

That's enough for now.  Next time we'll actually create a python file, make it executable, and run it on our robot.

Python and the EV3

No comments:

Post a Comment

Python and the EV3: Part 4 Writing a Program

This is part of a series, if you haven't already, go read the previous installments: Part 1: Installing EV3Dev Part 2: SSH and Python...