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 installaway. - 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_sprintconda 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:
| Topic | Why it matters |
|---|---|
Variables, data types (int, float, str, bool) | Storing sensor readings, parameters, flags |
| Lists, tuples, dictionaries | Tracking waypoints, scene objects, configuration |
if / for / while | Control loops, conditional behavior |
| Functions and arguments | Reusable controller code, helper utilities |
| Classes (basics) | Wrapping a PID controller, a robot interface, etc. |
Modules and import | Using NumPy, Matplotlib, the CoppeliaSim API |
| File I/O | Logging 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.
| Library | What it's for | Quick example |
|---|---|---|
| NumPy | Math, arrays, linear algebra | np.array([1, 2, 3]) |
| Matplotlib | Plotting controller responses, reward curves | plt.plot(time, x) |
| PyZMQ + coppeliasim-zmqremoteapi-client | Driving CoppeliaSim from Python | client = RemoteAPIClient() |
4. Watch the Introduction
If you are new to Python or want a refresher, work through these videos in order.
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
- Official Python tutorial — the canonical first read
- Python for Everybody (free book) — beginner-friendly, no prior programming required
- NumPy: the absolute basics for beginners
- Matplotlib pyplot tutorial
- Real Python — high-quality articles on specific topics, searchable
- PEP 8 — Python style guide — keep your code readable
- Refer to the Coding Standards page for the conventions used in this Sprint