Motor Driver

From Waveshare Wiki
Jump to: navigation, search

JetBot User Guide

Open Basic_motion Program

  • Basic_motion is an official motor driver script provided by NVIDIA, which is mainly used to test whether the motor is installed correctly. We take the direction of the camera as the forward direction and the direction of the OLED screen as the backward direction.
  • Use Google or Firefox to log in to the URL http://<jetbot_ip_address>:8888 to connect to the car [jetbot_ip_address is the ip displayed by the car, please remove the "<>"], open the folder on the left to "jetbot/notebooks/basic_motion/basic_motion" .ipynb” file.

Log in JupyterLab01.png

  • You can see that there are already a lot of remarks in the demo, and the program is divided into multiple units (we will talk about the code later and refer to each code block in terms of units). When you want to run a unit, you can click on the statement, then press the ctrl+enter button or click "△" to run the statement.
  • For example, the first statement is to call the packaged jetbot library. When we click the unit with the mouse, it will be highlighted in blue, and then press Ctrl+Enter on the keyboard to run the statement. As you can see, when the program is running, an asterisk is displayed in parentheses before the unit, indicating that the code is being executed. You can also observe the python3 icon in the upper right corner. If it is a solid circle behind it, it means that the kernel is busy. If it is a hollow circle, it means that the kernel is idle and can run the next unit.

Motor Driver02.png

Step 2: Reference Library

  • When we write programs, we often need to refer to some function libraries that have been encapsulated, which can greatly save our energy. Similarly, the JetBot library is directly referenced at the beginning. JetBot mainly encapsulates some basic functions for operating the Jetbot car, such as car motion function, camera operation function, etc.

Motor Driver06.png

  • The drive motor mainly calls the robot class in the Jetbot function. You can view the robot.py program under the jetbot/jetbot path.

Motor Driver07.png

Step 3: Movement Control

  • Run the statement robot.left(speed=0.3) the car will turn left, you can also modify the speed value to change the motor speed.
  • The import library and related class statements at the beginning of the file must be run first, otherwise the following units cannot run normally. So, please go step by step in order.

Motor Driver08.png

  • The time function library is imported in the following statement, and the time function is used to control the movement of the car for 0.5s, and then stop. Here we directly assign the speed value to the motor, so in Python you can either add the parameter name or not.

Motor Driver09.png

  • Of course, you can also write your own program to experience it. Click the "+" sign to add a new unit, and write to make the car move forward for a period of time and then stop.

Motor Driver10.png

  • You can also directly assign values to the motor to experience the convenience of the function class, as shown in the following figure.

Motor Driver12.png

Step 4: Visual Control

  • We can use widgets and traitlets to create graphical tools on the web to control the car. As shown in the figure, we start by referencing the widgets function library and calling the display class in Ipython. The display class is to display the tools we created on the page. We create two sliders named left and right, the value range of the slider adjustment is -1 to 1, and the direction is vertical. Then set the speed of the car by dragging the slider in the created small window.

Motor Driver13.png

  • Here you can use widgets to create a visual button. For example, set a button with a width of 100px and a length of 80px, create 5 modules and visualize them.

Motor Driver14.png

  • Then write the handler function corresponding to each button, and then link the button with the corresponding event handler function, you can run the code to control the car.

Motor Driver15.png

  • There is also a "heartbeat" control function here. The "heartbeat" here actually means that the car network is down, that is, the car will automatically stop moving if it is down during operation. You can disconnect the network to see the effect.

Motor Driver16.png