Detailed explanation of the steering gear

Insert picture description here

  The steering gear refers to an executive component that controls the turning of the aircraft rudder surface (control surface) in the autopilot. There are:
① Electric steering gear, which is composed of electric motor, transmission parts and clutch. It accepts the command signal of the autopilot and works. When driving the aircraft manually, the transmission components do not work because the clutch remains disengaged.
②Hydraulic steering gear is composed of hydraulic actuator and bypass valve. When manually flying the aircraft, the bypass valve opens, and the hydraulic pressure on both sides of the actuator piston communicates with each other without hindering manual manipulation. In addition, there are electro-hydraulic servos, referred to as "electro-hydraulic servos".
  The size of the steering gear is determined by the outfitting according to the rules of the classification society, and the size of the torque is mainly considered when selecting the model. How to choose carefully and economically and in accordance with the requirements of the steering gear is also an indispensable knowledge.
[Baidu Encyclopedia]

  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. It has been widely used in high-end remote control toys, such as aircraft and submarine models, and remote control robots.
  The steering gear is a large deck machinery on the ship. The size of the steering gear is determined by the outfitting according to the rules of the classification society, and the size of the torque is mainly considered when selecting the model.
  In aerospace, servos are widely used. In aerospace, the pitch, yaw, and roll movements of the missile's attitude change are all coordinated by the steering gear. The steering gear has applications in many projects, not just ships.

structure

Insert picture description here
  The steering gear is very useful in robotics. As shown in the figure above, these motors are very small, and they have built-in control circuits. Standard steering gear systems, such as the Futaba S-148, have 42 ounces of torque (equivalent to 1.2 kilograms of torque), which is already very powerful for its volume. It can also adjust power according to load changes. Therefore, the servo system with lighter load will not consume too much energy. The internal structure of the steering gear is shown in the figure above. You can see the control circuit, the motor, a set of gears, and the housing. You can also see the 3 external connections.

Servo motor proportional control

  So, how does the steering gear work? The steering gear has some control circuits and a potentiometer (a variable resistor) connected to the output shaft. In the picture above, you can see the variable resistor on the left side of the circuit board, where the three red wires are connected. The variable resistor allows the control circuit to monitor the current angle of the servo motor. If the angle of the shaft is correct, the motor is turned off. If the circuit finds that the angle is incorrect, turn the motor to the correct direction until the angle is correct. The output shaft of the servo system can move about 180 degrees.

Insert picture description here

How to control the angle of the servo motor?

  How to control the steering angle of the servo motor? The control line is used to convey the angle signal. The angle is determined by the duration of the pulse applied to the control wire. This is called pulse code modulation. The servo system expects to see a pulse (.02 seconds) every 20 milliseconds. The length of the pulse will determine how far the motor will turn.

For example, a 1.5 ms pulse will turn the motor to a 90-degree position (often called the neutral position). If the pulse is less than 1.5 ms, the motor will axially approach 0 degrees. If the pulse is greater than 1.5ms, the axis rotates 180 degrees.

For details, please refer to: Control Principle of Servo Angle
Insert picture description here

As shown in the figure above, the duration of the pulse determines the angle of the output shaft. Note that the time here is illustrative, the actual time depends on the motor manufacturer. However, the principle is the same.

Insert picture description here

Stm32 drive servo program

The stm32 servo driver source program is as follows:

#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"



u16 led0pwmval;
int main(void)
{               

        delay_init();                     //延时函数初始化         
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);          //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
        uart_init(115200);         //串口初始化为115200
         LED_Init();                             //LED端口初始化
         TIM2_PWM_Init(1999,719);        //100Khz的计数频率,计数到2000为20ms   
          while(1)
                        {
           LED1=0;         
         


            
                                                                                 TIM_SetCompare3(TIM2,50);
                    delay_ms(5000);                                         //延时多久很重要,自己一点点试。
                                                               
                                                       //延时多久很重要,自己一点点试。
                                                                                                

               
        }
      

                        }

main function program

#include "timer.h"
#include "led.h"
#include "usart.h"

//V1.1 20120904
//1,增加TIM3_PWM_Init函数。
//2,增加LED0_PWM_VAL宏定义,控制TIM3_CH2脉宽                                                                          
//////////////////////////////////////////////////////////////////////////////////  
            
//通用定时器3中断初始化
//这里时钟选择为APB1的2倍,而APB1为36M
//arr:自动重装值。
//psc:时钟预分频数
//这里使用的是定时器3!
void TIM3_Int_Init(u16 arr,u16 psc)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能

        TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值         计数到5000为500ms
        TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值  10Khz的计数频率  
        TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
        TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位

        TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //使能指定的TIM3中断,允许更新中断

        NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  //TIM3中断
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //从优先级3级
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
        NVIC_Init(&NVIC_InitStructure);  //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器

        TIM_Cmd(TIM3, ENABLE);  //使能TIMx外设
                                                         
}
//定时器3中断服务程序
void TIM3_IRQHandler(void)   //TIM3中断
{
        if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
                {
                TIM_ClearITPendingBit(TIM3, TIM_IT_Update  );  //清除TIMx的中断待处理位:TIM 中断源
                LED1=!LED1;
                }
}




//TIM3 PWM部分初始化
//PWM输出初始化
//arr:自动重装值
//psc:时钟预分频数
void TIM2_PWM_Init(u16 arr,u16 psc)
{  
        GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        TIM_OCInitTypeDef  TIM_OCInitStructure;
        

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);        //使能定时器3时钟
         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA  | RCC_APB2Periph_AFIO, ENABLE);  //使能GPIO外设和AFIO复用功能模块时钟
        
//GPIO_PinRemapConfig(GPIO_PartialRemap_TIM2, ENABLE); //Timer3部分重映射  TIM3_CH2->PB5   

   //设置该引脚为复用输出功能,输出TIM3 CH2的PWM脉冲波形        GPIOB.5
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //TIM_CH2
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  //复用推挽输出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIO

   //初始化TIM3
        TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
        TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
        TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
        TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
        
        //初始化TIM3 Channel2 PWM模式         
        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择定时器模式:TIM脉冲宽度调制模式2
         TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出极性:TIM输出比较极性高
        TIM_OC3Init(TIM2, &TIM_OCInitStructure);  //根据T指定的参数初始化外设TIM3 OC2

        TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);  //使能TIM3在CCR2上的预装载寄存器

        TIM_Cmd(TIM2, ENABLE);  //使能TIM3
        

}

32 Microcontroller Forum Code cited >> >> Forums> Electronics Category Discussion> Share Information> stm32 servo drive routine http://www.51hei.com/bbs/dpj-150290-1.html

arduino drive servo program

#include <Servo.h>

Servo myservo;  // 定义Servo对象来控制
int pos = 0;    // 角度存储变量

void setup() {
  myservo.attach(9);  // 控制线连接数字9
}

void loop() {
  for (pos = 0; pos <= 180; pos ++) { // 0°到180°
    // in steps of 1 degree
    myservo.write(pos);              // 舵机角度写入
    delay(10);                       // 等待转动到指定角度
  }
  for (pos = 180; pos >= 0; pos --) { // 从180°到0°
    myservo.write(pos);              // 舵机角度写入
    delay(10);                       // 等待转动到指定角度
  }
}
Published 153 original articles · Like 248 · Visits 330,000+

Guess you like

Origin blog.csdn.net/qq_45172832/article/details/105415675