Stage 03 · Lesson 10/14

Linux & Dev Environment · Lesson 10

VS Code for Robotics

Est. 35–45 min

Why

Why your editor is your workbench

Any editor works, but a well-configured one saves you from silly bugs: wrong Python, wrong folder, Windows line endings, unsaved files. This lesson sets up VS Code the way robotics teams commonly do.

Concept

The big idea: folder + interpreter + terminal + debugger in one window

Parts of the workbench
PartHow to openWhy it matters for robots
Open a folder, not a filecd ~/robot_ws && code .Paths, settings and Git all work relative to the project
Command PaletteCtrl + Shift + PEvery feature by name, e.g. “Python: Select Interpreter”
Quick OpenCtrl + PJump to bringup.sh by typing part of the name
Integrated terminalCtrl + ` (backtick)A real bash shell, already in your project folder
Source ControlCtrl + Shift + GSee changes, stage, commit (Lesson 9)
Run and DebugF5Breakpoints in your controller loop
Toggle commentCtrl + /Quickly disable a line while testing
Extensions worth installing first (from the Extensions view, Ctrl + Shift + X)
Extension (ID)What it gives you
Python (ms-python.python)Interpreter selection, linting hooks, run button
Python Debugger (ms-python.debugpy)Breakpoints and variable inspection for Python
Remote - SSH (ms-vscode-remote.remote-ssh)Open a folder that lives on the robot (Lesson 13)
NoteInstall VS Code on Ubuntu from the official instructions at code.visualstudio.com/docs/setup/linux (a .deb package or sudo snap install code --classic).

How it works

How it actually works: which Python does VS Code run?

  1. Open the folder

    code ~/robot_ws. VS Code looks for .vscode/settings.json inside it.

  2. Find interpreters

    The Python extension lists every Python it can find: /usr/bin/python3, and .venv/bin/python if the folder has a venv.

  3. You choose

    Ctrl + Shift + P → “Python: Select Interpreter” → pick the .venv one. The status bar shows the choice.

  4. Run / debug

    The Run button and F5 now use that interpreter — the same one that has pyserial and numpy installed.

  5. Terminal follows

    New integrated terminals usually activate the selected venv automatically, so pip install goes to the right place.

Visual

Visualise it: the integrated terminal is a real shell

VS Code’s integrated terminal is a normal shell. Practise the same moves here: pwd to confirm you are in the project, cd into workspace/scripts, cat bringup.sh.

Interactive · Terminal simulator

# robotics workstation simulator
# try: pwd · ls · cd workspace · cat robot_controller.py

cwd: /home/robot · simulated only

Code lab

Code lab: commit your editor settings with the project

Create a .vscode folder in robot_ws with these two files. Commit them, so every teammate gets the same setup.

.vscode/settings.json · JSON
{
  "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
  "editor.formatOnSave": true,
  "files.trimTrailingWhitespace": true,
  "files.exclude": { "**/__pycache__": true },
  "terminal.integrated.cwd": "${workspaceFolder}"
}
.vscode/extensions.json · JSON
{
  "recommendations": [
    "ms-python.python",
    "ms-python.debugpy",
    "ms-vscode-remote.remote-ssh"
  ]
}

When a teammate opens the folder, VS Code offers to install the recommended extensions. To debug, create a launch configuration:

.vscode/launch.json · JSON
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Run robot controller",
      "type": "debugpy",
      "request": "launch",
      "program": "${workspaceFolder}/src/robot_controller.py",
      "console": "integratedTerminal",
      "env": { "SERIAL_PORT": "/dev/ttyUSB0", "ROBOT_NAME": "desk-arm" }
    }
  ]
}

Real world

Where VS Code fits a robot workflow

  • Remote-SSH: open ~/robot_ws on the Jetson from your laptop, edit and run there.
  • Split view: controller code on the left, robot.yaml on the right, terminal with logs below.
  • Source Control view shows exactly which config lines you changed before a test run.
  • Committed .vscode/ settings mean a new team member is productive on day one.

Mistakes

Common mistakes and debugging

Hardware & safety

Hardware lab and safety notes

VS Code can edit code directly on a Raspberry Pi or Jetson over SSH, so you do not need a screen on the robot.

  • The Remote - SSH extension opens a folder on the robot as if it were local (needs SSH from Lesson 13).
  • On a small Pi, prefer editing over Remote - SSH from the laptop rather than running the full VS Code on the Pi.
  • Add the Arduino sketch folder to the workspace so code and firmware sit side by side.
Raspberry Pi 4 Model B single-board computer, top view
With Remote - SSH, VS Code on the laptop edits files that live on the Pi.Photo: Laserlicht · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Debugging

Debugging: when it doesn’t work

Symptom → likely cause → fix
SymptomLikely causeFix
ModuleNotFoundError in VS Code but not in the terminalWrong interpreter selectedCommand Palette → “Python: Select Interpreter” → .venv
Script fails with \r errors on the PiFile saved with CRLFClick “CRLF” in the status bar → choose LF
Breakpoint is never hitRunning, not debuggingUse F5 with your launch.json
Remote - SSH cannot connectSSH itself failsTest ssh jetson in a terminal first (Lesson 13)
NoteRead the last line of an error first — it usually names the problem. Change one thing at a time and re-run.

Think

Think about it

Think

Your script runs fine with `python3 src/robot_controller.py` in the terminal but VS Code’s Run button says `No module named 'serial'`. What do you check first?

Experiment

Try it in the lab: set up your workbench

Practise the terminal moves here, then do the real setup on your laptop.

Experiment

Set up your workbench

You will need

  • Terminal simulator
  • Ubuntu laptop with VS Code (optional but recommended)

Steps

  1. In the simulator: `pwd`, `cd workspace`, `ls`, `cd scripts`, `cat bringup.sh` — this is what you will do in the integrated terminal.
  2. On your laptop: `cd ~/robot_ws && code .`
  3. Install the three recommended extensions.
  4. Select the `.venv` interpreter (create it first if needed — Lesson 11).
  5. Add `settings.json` and `extensions.json`, commit them, and check the status bar says LF.
  6. Set one breakpoint in a loop and step through three iterations with F10.

Interactive · Terminal simulator

# robotics workstation simulator
# try: pwd · ls · cd workspace · cat robot_controller.py

cwd: /home/robot · simulated only

The status bar should show the venv Python and LF line endings. The integrated terminal prompt should end in robot_ws$.

Knowledge check

Check your understanding

Knowledge check

1. For a robot project you should open in VS Code…

2. The Remote - SSH extension lets you…

3. “No module named serial” only inside VS Code usually means…

4. Which shortcut opens the Command Palette?

5. Why commit `.vscode/extensions.json`?

Mini assignment

Hands-on assignment

Mini assignment

VS Code setup notes

Document your editor setup so a teammate can copy it in ten minutes.

Deliverables

  • Screenshot or note of the status bar showing the venv interpreter and LF
  • Your `settings.json`, `extensions.json` and `launch.json`
  • Five shortcuts you will use daily, with what each does

Do this, step by step

  1. Install VS Code using the official Linux instructions.
  2. Open robot_ws, select the .venv interpreter and set line endings to LF.
  3. Add the three JSON files from the code lab to .vscode/.
  4. Set a breakpoint in a script, press F5 and step through three lines.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: The status bar (bottom) shows the interpreter and “LF/CRLF”.
  2. Hint 2: extensions.json only recommends extensions; teammates still click Install.
  3. Hint 3: In launch.json, "program": "${file}" debugs whichever file is open.

Challenges (pick by level)

  • 🟢 Easy: Learn Ctrl + P (open file) and Ctrl + Shift + P (command palette).
  • 🟡 Medium: Add an env entry with ROBOT_MODE=sim to launch.json.
  • 🟠 Hard: Open a folder on a Pi with Remote - SSH and run a script there.

Next step

Look back: Lesson 9: Git & GitHub for Robotics. Next: Lesson 11: Python Virtual Environments. Related: Stage 2 — Python for Robotics.

Sources

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in