Python Programming in Visual Studio IDE
Lab Session for Automation & Robotics Department
Instructor: [Your Name]
1. Objectives
- Learn to create and configure Python projects in Visual Studio
- Write programs for Velocity & Wheel Rotations
- Run, compile (interpret), and debug code
- Handle input/output for robotics applications
2. Program Example: Velocity Calculator
distance = float(input("Enter distance (m): "))
time = float(input("Enter time (s): "))
if time == 0:
print("Error: Time cannot be zero.")
else:
velocity = distance / time
print(f"Velocity = {velocity} m/s")
3. Program Example: Wheel Rotation Calculator
import math
wheel_radius = 0.05 # meters
distance_to_travel = float(input("Enter distance to travel (m): "))
circumference = 2 * math.pi * wheel_radius
if circumference == 0:
print("Error: Wheel circumference cannot be zero.")
else:
rotations = distance_to_travel / circumference
print(f"Wheel rotations required = {rotations:.2f}")
4. Debugging in Visual Studio
- Breakpoints → pause program execution
- Step Into/Over → run code line by line
- Watch Window → inspect variables
- Error handling: prevent ZeroDivisionError with if-checks
5. Input & Output in Robotics
- Input: Keyboard, files, or sensor data (serial input from robot).
- Output: Console print, logs, or motor controller commands.
- Example: Velocity controls motor speed.
- Example: Wheel rotations guide navigation.
6. Example Lab Workflow
1. Create project RoboticsLab.
2. Add velocity_calculator.py.
3. Run program with test values (distance=10m, time=2s).
4. Debug program with time=0 (error handling demo).
5. Add wheel_rotation.py and test with different distances.
7. Conclusion
- Visual Studio IDE makes Python programming structured and efficient.
- Students learn programming, debugging, and I/O handling.
- Robotics applications: speed control, precise wheel movements, navigation, and safety.
8. Quiz / Exercises
Q1. What happens if time = 0 in the velocity calculator?
Q2. Write the formula for wheel circumference.
Q3. Modify the velocity program to accept multiple test cases from a file.
Q4. In debugging, what is the purpose of breakpoints?
Q5. How is the output of the wheel rotation calculator useful for robotics navigation?
Q6. Bonus: Extend the wheel rotation calculator to take wheel radius as user input.