Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Python — A Quick Start Guide


1. Why Python for this Sprint?

Almost every piece of code we write in this Sprint — driving CoppeliaSim, implementing a PID controller, training an RL agent, reading sensor data — is in Python 3.10.

Python is a great fit for robotics because:

  • Readable syntax — looks close to pseudocode, so the logic stays visible.
  • Huge library ecosystem — NumPy, Matplotlib, OpenCV, PySerial, PyZMQ are all one pip install away.
  • Cross-platform — the same script runs on Windows and Ubuntu without changes.
  • Fast to prototype, easy to debug — perfect for iterating on controllers and algorithms before deploying to hardware.

NOTE : Make sure your elsi_sprint conda environment is active before running any Python in this Sprint. See (1a) Software Install using Windows or (1b) Software Install using Ubuntu for the setup.


2. What You Should Know

You don't need to be a Python expert, but you should be comfortable with the following before tackling Task 1:

TopicWhy it matters
Variables, data types (int, float, str, bool)Storing sensor readings, parameters, flags
Lists, tuples, dictionariesTracking waypoints, scene objects, configuration
if / for / whileControl loops, conditional behavior
Functions and argumentsReusable controller code, helper utilities
Classes (basics)Wrapping a PID controller, a robot interface, etc.
Modules and importUsing NumPy, Matplotlib, the CoppeliaSim API
File I/OLogging data, reading config files
Exceptions (try / except)Handling connection drops to the simulator

3. Sprint-Specific Libraries

A quick overview of the libraries you'll actually use. All of these are already installed in your elsi_sprint env.

LibraryWhat it's forQuick example
NumPyMath, arrays, linear algebranp.array([1, 2, 3])
MatplotlibPlotting controller responses, reward curvesplt.plot(time, x)
PyZMQ + coppeliasim-zmqremoteapi-clientDriving CoppeliaSim from Pythonclient = RemoteAPIClient()

4. Watch the Introduction

If you are new to Python or want a refresher, work through these videos in order.

Video 1: Python for Beginners — Full Course

Video 2: NumPy Tutorial for Beginners

Video 3: Matplotlib Tutorial for Beginners


5. Hands-On Practice

The fastest way to get fluent is to write code yourself. Try these in your elsi_sprint env:

# 1. A simple loop
for i in range(5):
    print(f"step {i}, value = {i ** 2}")

# 2. A function
def clamp(x, low, high):
    return max(low, min(x, high))

print(clamp(15, 0, 10))   # 10
print(clamp(-3, 0, 10))   # 0

# 3. NumPy basics
import numpy as np
a = np.linspace(0, 10, 5)
print(a)
print("mean:", a.mean())

# 4. Plot a sine wave
import matplotlib.pyplot as plt
t = np.linspace(0, 2 * np.pi, 100)
plt.plot(t, np.sin(t))
plt.xlabel("t"); plt.ylabel("sin(t)")
plt.grid(True); plt.show()

If all four snippets run without errors, you're ready for the PID and RL implementation sections.


6. Additional References