Salted Fish Hardware-Servo Servo

Salted Fish Hardware-Servo Servo


The servo is a kind of position (angle) servo drive, which is suitable for those control systems that need to keep changing the angle and can maintain it. Currently used in high-end remote control toys, such as aircraft models, including aircraft models, submarine models; remote control robots have been more commonly used. The servo is a common name, but it is actually a servo motor.

Working principle of steering gear
Insert picture description here

The control circuit, potentiometer (variable resistor) and motor inside the servo are connected to the circuit board, as shown in the right part of the internal structure diagram. The control circuit can monitor the current angle of the servo through a potentiometer.
If the position of the axis matches the control signal, the motor will be turned off. If the control circuit finds that this angle is incorrect, it will control the motor to rotate until it reaches the specified angle. The angle of the steering gear varies according to the manufacturer. For example, a 180-degree servo can move between 0 degrees and 180 degrees.
Since the limit device is installed on the main output device, the mechanical structure beyond this range can no longer rotate. The output power of the servo is proportional to the distance it needs to turn. If the output shaft needs to rotate a long distance, the motor will run at full speed. If it only needs to rotate a short distance, the motor will run at a slower speed. This is called speed proportional control.

How to turn the servo to a specified angle?
Insert picture description here

The control line is used to transmit angle control signals. This angle is determined by the duration of the control signal pulse, which is called pulse code modulation (PCM). The control of the steering gear generally requires a time base pulse of about 20ms. The high level part of the pulse is generally in the range of 0.5ms-2.5ms, and the total interval is 2ms. The width of the pulse will determine the distance the motor rotates. For example: 1.5 ms pulse, the motor will turn to the 90 degree position (often called the neutral position, for a 180 ° servo, it is the 90 ° position). If the pulse width is less than 1.5 milliseconds, the motor axis is oriented in the direction of 0 degrees. If the pulse width is greater than 1.5 milliseconds, the axial direction is toward 180 degrees. Take the 180-degree servo as an example, the corresponding control relationship is as follows:
0.5ms ——- 0 degree;
1.0ms —— 45 degrees;
1.5ms —— 90 degrees;
2.0ms ———— 135 degrees;
2.5ms-180 degrees;

Example usage:
from pyb import Servo
s1=Servo(1#使用X1控制(X1,VIN,GND) 
s1.angle(45#转到45°
s1.angle(-60,1500)#1500ms内转到-60°
s1.speed(50)#以速度50继续转动

The servo object uses the timer (5) to generate pwm output. You can use the timer (5) for servo control, or your own purpose, but not both.Insert picture description here

Class pyb.Servo(id)
pyb.Servo(1#创建一个伺服对象。
#id 是1-4,对应于针脚 x1到 x4。
method

angle()

 '''没有参数,这个函数返回当前角,
 有参数,这个函数设置伺服器的角度: '''
Servo.angle(angle, time=0)
'''
angle:角度:度数中移动到的角度
time:时间:时间是到达指定角度所需的毫秒数。 
 	 如果省略,然后伺服移动尽快到它的新位置。
 '''

Insert picture description here
speed()

 '''没有参数,这个函数返回当前速度。
 有参数,这个函数设置伺服器的速度:'''
Servo.speed(speed, time=0)
'''
speed:速度:取值-100到100之间
time:时间:时间是达到指定速度所需的毫秒数。 如果省略,然后伺服加速尽可能快。
 '''

pulse_width()

 '''没有参数,这个函数返回当前原始脉冲宽度值。
 有参数,这个函数设置原始脉冲宽度值。'''
Servo.pulse_width(value)

calibration()
Insert picture description here

 '''没有参数,此函数将以5元组的形式返回当前的校准数据。 '''
Servo.calibration(pulse_min, pulse_max, pulse_centre, pulse_angle_90, pulse_speed_100)
如果给出参数,这个函数设置定时校准: 
pulse_min :允许的最小脉冲宽度
pulse_max :允许的最大脉冲宽度
pulse_centre :是与中心 / 零位相对应的脉冲宽度
pulse_angle_90 :90度相对应的脉冲宽度
pulse_speed_100 :脉冲速度100是与速度100相对应的脉冲宽度。

Reference link:
seconds to understand the principle of steering angle control
micropython

Published 166 original articles · 22 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/weixin_45020839/article/details/105630530