Lesson 27 JetBot Basic Motion Python Code Explanation

preview_player
Показать описание
Lesson 27: JetBot Basic Motion Python Code Explanation
Lesson 27A:
from jetbot import Robot
Here in this line of code, we are importing the Python class which is defined as Robot.
Python is an object-oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects. In this case Robot is a Python class which we are importing from Jetbot. This class called Robot will let us control the JetBot motors.
Lesson 27B:
robot = Robot()
In this line of code we are initializing a class instance, which means in Python programming world, Instance – is a individual object of a certain class. The object can be a motor or a sensor or any other device you may want to connect in future.
Lesson 27C:
After we created a class above, we will be able to use this instance to control the robot motors, so basically, we are trying to turn the JetBot motors to 30% anticlockwise speed which is 0.3. We can modify the speed by changing the numerical values from 0.3 to your desired speed, however I would advice you to keep it minimum.
Lesson 27D:
In this line of code we are defining a stop user defined function in Python in order to stop the motors of JetBot.
Lesson 27E:
import time
Here we are importing a Python library called time. The Python time library provides many ways of representing time in code, such as objects, numbers, and strings. It also provides functionality other than representing time, like waiting during code execution and measuring the efficiency of your code.
In this case of Jetbot we are using time library to run the motor for a specific duration of time, which means you can define how much time you want the JetBot motors to spin

Lesson 27F:
In this section of Python code, we are setting a user defined method within a function called left and right and also using a sleep function which is inbuilt within Python.
The sleep() function suspends (waits) execution of the current thread for a given number of seconds. Python has a module named time which we imported earlier, which provides several useful functions to handle time-related tasks. The sleep() function suspends execution of the current thread for a given number of seconds.
When you execute the above code the JetBot motors will run for 50% speed for a second and it stops which is triggered by sleep function.
Lesson 27G:
In this section of Python code, we are setting a user defined method within a function called left and

More Detailed steps and explanation to each line of codes are documented in CodingScientist Manual.

Reach out to me for 1 o 1 coaching, manuals and source code at the following contact details :
WhatsApp: +91-99725-77735
Рекомендации по теме