In this lesson, we will learn the soft motion method of the servo.
18.1 Learning the smooth motion method smooth.py
Here we use Subline IDE to view and edit the code program of this course. For the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in Lesson 2. The specific code and comments are as follows:
In the file manager of the MobaXterm terminal, find adeept_rasparms/CourseCode/06Smooth, and open the code of this lesson: smooth.py.
Import the library that is used to control the servo.
Instantiate the servo control object.
Define three positions and let the servo move slowly to these positions in sequence.
Put these positions into the array.
Define the port number of the servo you want to control.
This is the initial position and the variable which is used to store the end point of the last movement of the servo.
Enter a new position in the parameter of this function, the rudder will move smoothly from lastPos to newPosInput.
Calculate the difference between lastPos and newPosInput.
Control the servo to move from lastPos to newPosInput little by little.
Update lastPos as the starting point of the next exercise.
Main function, which is used to control the servo to move slowly to the three points in posList.
18.2 Running smooth.py on Raspberry Pi
1. Open the terminal software MobaXterm:
2. Log in to your Raspberry Pi (the way to log in to Raspberry Pi has been introduced in Lesson 1):
3. The relevant code programs of the RaspArm-S robot are stored in the folder of adeept_rasparms, which has been explained in "2.1 Downloading the Code Program for Controlling the Robot" in Lesson 2. First, you need to enter a command with the command window of the Raspberry Pi to enter the folder where the course code is stored: CourseCode, this folder stores the sample code program for each course, enter the following command:
cd adeept_rasparms/CourseCode
4. Enter the command to view the contents of the current directory:
ls
5. The 06Smooth folder stores the sample code of this lesson. Enter the command to enter this folder:
cd 06Smooth
6. Enter the command to view the contents of the current directory:
ls
7.smooth.py is the sample code for this lesson, enter the command to run this program:
sudo python3 smooth.py
8. After running the program successfully, you will observe that the robotic arm will move between the three positions set in the program.