Index>Robot Kit>RaspArm-S Kit for RPi>Lesson 18 Introduction to the Soft Motion Method of the Servo

Lesson 18 Introduction to the Soft Motion Method of the Servo

1843

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.

image.png 


Instantiate the servo control object.

image.png 


Define three positions and let the servo move slowly to these positions in sequence.

image.png 


Put these positions into the array.

image.png 


Define the port number of the servo you want to control.

image.png 


This is the initial position and the variable which is used to store the end point of the last movement of the servo.

image.png 


Enter a new position in the parameter of this function, the rudder will move smoothly from lastPos to newPosInput.

image.png 


Calculate the difference between lastPos and newPosInput.

image.png 


Control the servo to move from lastPos to newPosInput little by little.

image.png 


Update lastPos as the starting point of the next exercise.

image.png 


Main function, which is used to control the servo to move slowly to the three points in posList.

image.png 


18.2 Running smooth.py on Raspberry Pi

1. Open the terminal software MobaXterm:

image.png 


2. Log in to your Raspberry Pi (the way to log in to Raspberry Pi has been introduced in Lesson 1):

image.png 


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


image.png 

4. Enter the command to view the contents of the current directory:

ls


image.png 


5. The 06Smooth folder stores the sample code of this lesson. Enter the command to enter this folder:

cd  06Smooth


image.png 


6. Enter the command to view the contents of the current directory:

ls


image.png 


7.smooth.py is the sample code for this lesson, enter the command to run this program:

sudo  python3  smooth.py


image.png 


8. After running the program successfully, you will observe that the robotic arm will move between the three positions set in the program.