lab 3 ros done
lab 3 ros done
Objective
This lab introduces the fundamentals of Python programming, focusing on its role in robotics. Students
will learn Python’s syntax, execution methods, and installation process, comparing it with C++ in terms
of performance and ease of use. Additionally, they will practice writing and executing Python scripts.
1. Introduction to Python
Python is a general-purpose, high-level, object-oriented language known for its simplicity and
readability.
It is an interpreted language, executing code line by line, making debugging easier.
Created by Guido van Rossum, its first version was released in 1994.
C++: Faster execution, efficient resource usage, preferred for high-performance applications.
Python: Easier development, quick prototyping, and compatibility with libraries like OpenCV
and ROS.
3. Python in Robotics
Commonly used for sensor data logging, serial communication, and UI development.
Suitable for applications where computational efficiency is not the primary concern.
Python Execution Methods
Python Interpreter: Code is executed line by line in a shell.
Python Scripts: Code is saved in a .py file and executed using an interpreter.
Lab Tasks:
Introduction to Python Interpreter:
Python interpreter in the terminal
Installing Python on Ubuntu 20.04 LTS
Python is preinstalled on Ubuntu, but the following command installs Python manually
sudo apt-get install python python3
Location of Python:
Location of Python interpreter, sources, and documentation
Another way:
There is another way to execute the Python file. Use the following command.
$ chmod a+x hello_world.py.
And after giving permission, you can simply execute the Python code using the following command.
$ ./hello_world.py
Python: Classes:
Python class example
Python: Files:
Python file I/O example
Python file I/O output:
Python: Modules:
Custom Python test module