• Smooth servo control. What is a servo drive

    It is an element of precision kinematics, allowing for precise positioning of mechanisms. But unlike a stepper motor, a servo drive has feedback, allowing you to track the exact angle of rotation of the shaft at any time. Can be used as a source of feedback various types encoders and potentiometers.

    In the article we will look at connecting and working with junior representatives of servos - the so-called. servos - a favorite among robot builders and modelers.

    Constructive

    The servo machine consists of a housing that contains a small commutator electric motor, a gearbox and control electronics.

    Potentiometers are used as feedback. Therefore, these servos have limitations on the angle of rotation of the shaft around the axis. So, in the Futaba S3003 servos I purchased, the output shaft rotation angle is 225°.

    Technical characteristics of Futaba S3003

    Parameter Supply voltage, V
    4,8 6,0
    Shaft force 3,2 kg/cm 4.1 kg/cm
    Speed positioning 0.23 sec/60° 0.19 sec/60°
    Size, L x W x H 41mm x 20mm x 36mm
    Weight, g37

    The feedback potentiometer is placed directly on the output shaft, thanks to which the servo control unit monitors the exact position of the shaft: potentiometer resistance changes proportionally rotation angle . Having read the resistance, the control unit compares this value with the one that should be at a given shaft position. If these values ​​differ, the control unit commands the motor to turn the shaft in the specified direction, reducing the difference in values. Having reached the shaft position when the value from the potentiometer matches the set value, the motor stops. The value is read from the potentiometer and compared with high frequency, therefore the output shaft will tend to take a given position when the external load changes.

    The design of the servo machine is made in such a way that the torque from the engine to the output shaft is transmitted through a gearbox with a large gear ratio, therefore, with small sizes and energy consumption, servos can provide greater traction.


    Control

    The control signal is a pulse signal with a period of 20 ms and a duration of 0.8 to 2.2 ms. This is a certain standard for controlling servos. The longer the pulse arrives, the greater the angle the servo shaft will rotate.To accelerate the servo, the pulse repetition period can be reduced to 10 ms.


    The control signal is sent to the servo via signal wire S. In my servo it is white, in some models it is yellow. In addition to the signal wire, two wires come out of the servo - power lines - ground (black) and power (red)


    Software part

    As you can see, controlling the servo is quite simple - just drive a pulse signal from the required frequency and duty cycle. This signal can be generated PWM, or you can write your own timer interrupt handling function. But Bascom-AVR already has a built-in command for controlling servos -Servo . Let's consider it.

    First you need to configure the connection of servos:

    Config Servos = X, Servo1 = Portb. 0, Servo2 = Portb. 1, Reload = Var

    Servos= X ; the number of connected servos is indicated; up to 14 servos can be connected.

    Servo1= Portb. 0 ; indicates the connection port of the first servo

    Servo2= Portb. 1 ; indicates the connection port for the second servo

    Reload= Var ;Here Vartime in microseconds that elapses between timer interrupts.

    By default, Timer0 is used to organize interrupts, so you can no longer use it for your own purposes. Bascom-AVR allows you to transfer interrupt servicing to any other timer, for example, to release Timer0 and use Timer1, just specify this in the configuration line:

    Config Servos = 2, Servo1 = Portb. 0, Servo2 = Portb. 1, Reload = 10, Timer= Timer1


    After everything has been configured, all that remains is to steer our servo. This is done with the following command

    Servo( a ) = F

    A - serial number servos

    F is a variable whose value specifies the angle of rotation of the servo shaft

    Full test code:


    $regfile = "m8def.dat" "microcontroller ATmega8
    $crystal = 8000000 "operating frequency 8 MHz

    "we configure ports for connecting servos
    Config Portb. 0 = Output
    Config Portb. 1 = Output

    "we configure the connections of two servos
    Config Servos = 2, Servo1 = Portb. 0, Servo2 = Portb. 1, Reload = 15

    Dim F AsByte"variable for the first servo
    Dim S AsByte"variable for the second servo

    "enable interrupts
    Enable Interruptions

    F= 15 "the value of the variable sets the angle of rotation of the servo shaft
    S= 70

    Do

    Servo(1) = F
    Servo(2) = S

    Loop

    End


    I don’t provide a connection diagram, I think one signal wire will not cause problems;) It can be connected to the microcontroller port directly, or through a resistor with a resistance of a couple of hundred ohms - to be on the safe side.

    By changing the values ​​of the variable F and S we can change the angle of rotation of the first and second servos, respectively. The lower the value of the Reload parameter, the faster our servos will rotate to the desired angle.

    I selected a working range for my servos it is the Servo(a) value in which the shaft can rotate. The shaft occupies its extreme positions at values ​​of 0 and 150; respectively, at a value of 75 the shaft occupies an intermediate position.


    Servo(a) =0 Servo(a) =75 Servo(a) =150

    Servo motors are a type of electromechanical drive that does not rotate continuously like DC/AC or stepper motors, but moves to a specific position and maintains it. They are used where continuous rotation is not required. Servo drives are used where it is necessary to move to a specific position, and then stop and maintain the position.The most common use of servo motors is to control the rudder position of aircraft and boats, etc. Servos are used effectively in these areas because the steering wheel does not need to be moved 360 degrees and does not require continuous rotation like wheels. Servo drives also use a feedback mechanism, so they can process errors and correct them during positioning. Such a system is called tracking. So, if the air flow puts pressure on the steering wheel and deflects it, then the servo will apply a force in the opposite direction and try to correct the error. For example, if you tell the servo to go and lock at 30 degrees, and then try to turn it by hand, the servos will try to overcome the force and maintain the specified angle.

    Servo drives are also used to control the steering wheel of RC cars, robotics, etc.There are many types of servos, but here we will focus onsmall servos so calledhobby. Hobby motor and its control mechanismbuilt into one block.Connection is made using three connecting wires. We will use a servoFutabaS3003.

    FutabaS3003 wiring.

    1.RED -> Position control, power supply +4.8V to 6V

    2.BLACK->Ground

    3.WHITE -> Control signal.

    Servo drive control.

    It is easy to control the servo with the help of a microcontroller, no external drivers are needed. Just by giving a control signal, the servo will position to any given angle. The frequency of the control signal is usually 50hz(i.e. a period of 20 ms), and the pulse duration specifies the angle.

    For FutabaS3003I found out the following synchronizationThe relationship between pulse width and servo rotation angle is given below. Note that this servo can only rotate between 0 and 180 degrees.

    • 0.388ms= 0 degrees.
    • 1.264ms= 90 degrees.
    • (Neutral position) 2.14ms= 180 degrees.

    Servo motor control.

    You can use AVR microcontroller with PWM function for controlling servomotors. This way, the PWM will automatically generate servo lock signals and the controller's CPU will be freed up for other tasks.To understand how you can configure and use PWM, you must have a basic knowledge of hardware timers and PWM modules in the AVR.

    Here we will use the AVR Timer module.which is 16bit timer and has two PWM channels (A and B).

    Frequency central processor is 16 MHz, this frequency is the maximum frequency at which most AVRs are capable of operating. We will also use a frequency divider by 64.So the timer will get 16MHz/64 =250khz (4 µs). Set the timer to mode 14.

    Timer functions in mode 14

    • FAST PWM mode
    • T T OP Value = ICR1

    So we set ICR1A = 4999, this gives us a PWM period of 20ms (50Hz). Make sure the output mode is set to correct settings COM1A1, COM1A0 (for PWM channel) and COM1B1,COM1B0 (for PWM channel B)

    COM1A1= 1 and COM1A0 = 0 (PWM Source)

    COM1B1= 1 and COM1B0 = 0 (PWM channel B)

    Now the duty cycle can be set by setting OCR1A and OCR1B registers. These two PWM period control registersSince the timer period is 4µs(remember 16 MHz divided by 64) We can calculate the values ​​needed to rotate the servo to a certain angle.

    § Servo angle 0 degrees requires 0.388ms (388uS) pulse width, so OCR1A value = 388us/4us = 97

    § Servo angle 90 degrees requires a pulse width of 1.264ms (1264uS), so OCR1A value = 1264us/4us = 316

    § Servo angle 180 degrees requires 2.140ms (2140uS) pulse width, so OCR1A value = 2140us/4us = 535

    So we cancalculate valueOCR1A (or OCR1B for the second servo) for any angle. Note that OCR1x values ​​range from 97 to 535 for angles from 0 to 180 degrees.

    Engine control program.

    The demo program is given below, showing how to use servo motors with the AVR microcontroller. The operation of the program is very simple, it begins with the initialization of the timer and PWM. At the beginning, the servo is fixed at 0 degrees, then moves to 90 degrees and waits for a while, moves to 135 degrees, and finally to 180 degrees. This process is repeated as long as the drive is connected to power.

    Options for proper operation programs.

    • LOW Fuse= 0xFF and HIGH Fuse= 0xC9
    • Frequency = 16 MHz.
    • Servo motorstamp Futaba S3003.
    • The MCU is AtMega32 or ATmega16 single-chip microcontroller.

    Scheme

    APPLICATIONS:

    For the very beginners. Tested code in the article. Let's plug it in, turn it around, and figure out the power supply.
    An SD90 servo drive arrived in my hands with a diagnosis malfunction and with almost complete refusal (According to his words). We need to figure it out.
    General information is needed, information is important
    SD-90 is practically the cheapest servo drive on the electronics market.
    Weight is only 15 grams and torque is 2kg/cm. This SD90 servo drive operates in temperatures from -30 to +60 degrees.
    Operating voltage from 4V to 8V.
    Consumption in motion is 70 mA, and in hold 15 mA.
    The rotation angle is only 180 degrees.
    The SD90 servo drive is ideal for installation on model aircraft.

    To control servos using Arduino there is a standard library in IDE Arduino Servo.h, which includes functions for setting the servo settings, the required angle, and reading the status. Some methods are overloaded.

    We turn to our Chinese friends for manuals and judging by the picture below, connecting the SG90 servo drive is not difficult.

    Two wires are for power and one wire is for control. Below is the program code for Arduino which will give some explanations.

      * Specially for the site site

      * Servo drive SG90 + Arduino. Connection

      //Library for working with a servo drive

      #include ‹Servo.h›

      //Declaration of a variable - object

      Servo servo;

    1. void setup()

      //The control output of the servo drive is connected to pin No. 7

      //This library method specifies the pin through which control occurs

      servo.attach(7);

      //servo.detach(7); - this method will disable control from the specified pin.

    2. void loop()

      //Set the shaft to 0 degrees

      servo.write(0);

      delay(2000); //wait 2 seconds. A minimum of 30 microseconds is required for installation.

    3. servo.write(90); //set the shaft at 90 degrees

    4. // The library has a function to read the current position (angle) of the servo.

      // The last one will be read set value in the servo drive.

      // int AngleServo=servo.read();

      // From 0 to 180 degrees.

    5. servo.write(180); //set the shaft at 190 degrees

      delay(2000); //wait 2 seconds.

    6. //Slowly return back at intervals of 1 degree

      for (int p= 179 ; p>= 1 ; p-- )

      servo.write(p);

      delay(20) ;

      //The angle (Set) can be set in time from zero.

      //Since the servo has a turning speed characteristic of 0.12 sec/60 degrees

      1 - Connector for connection
      2 - Servo drive control circuit, signal processing
      3 - Potentiometer
      4 - Engine
      5 - Val

      So, at the very beginning I said that an almost non-working servo drive fell into my hands (According to my words). After the investigations, it became clear that the Arduino was powered by Computer USB, and the servo drive itself is from Arduino.
      If we delve into the details, then in experiments with it was established that Chinese version MEGA does not pull 150mA load. The SG90 servo drive creates a load of 75-90 mA when the shaft moves, depending on the shaft load. As a result, when the Arduina started, the person who asked to look into this problem reset the Arduina itself due to the increased load and, accordingly, the servo did not show any signs.

      The solution to the problem is the simplest. It is necessary to increase the power supply for the Arduino using an external source (power supply) or separately for the SG90 servo drive.
      But the situation was such that it was not possible to use the servo drive at the installation site external source nutrition. The solution is found in the figure below.

      As a result, in order to prevent the load on the Arduino, it is necessary to install a support capacitor with a capacity of 1000 mF 10V between the power supply and ground. AND ceramic capacitor any container to prevent chatter from the servo drive (under load) on the Arduino. This solution cannot be used for permanent use, but in emergency situations this option is quite suitable.

      Note that this option Suitable for micro servos. For large servos this method for power supply it will still give a voltage drop, this will be noticeable on the LED indicators of the arduino, but will still prevent a complete reset.

    Servo drives and mechanisms are equipped with a sensor that monitors a certain parameter, such as force, position or speed, as well as a control unit in the form electronic device. The task of this device is to maintain the necessary parameters in automatic mode during operation of the device, depending on the type of incoming signal from the sensor at certain periods of time.

    Design and operation

    A servo drive differs from a conventional electric motor in that it is possible to set the exact position of the shaft in degrees. Servo drives are any mechanical drives that include a sensor for some parameter and a control unit that is capable of automatically maintaining the required parameters corresponding to certain external values.

    1 — Reducer gears
    2 - Output shaft
    3 - Bearing
    4 - Lower bushing
    5 - Potentiometer
    6 - Control board
    7 — Housing screw
    8 - Electric motor DC
    9 – Electric motor gear

    To convert electrical energy into mechanical movement, is necessary. The drive is a gearbox with an electric motor. A gearbox is required to reduce the speed of the motor as the speed is too high for the application. The gearbox consists of a housing containing shafts with gears capable of converting and transmitting torque.

    By starting and stopping the electric motor, the output shaft of the gearbox, which is connected to the servo gear, can be driven. A device or mechanism that needs to be controlled can be attached to the shaft. In addition, to control the position of the shaft, a feedback sensor is required. This sensor can convert the rotation angle back into an electrical current signal.

    This sensor is called an encoder. A potentiometer can be used as an encoder. If the potentiometer slider is turned, its resistance will change. The value of this resistance is directly proportional to the angle of rotation of the potentiometer. Thus, it is possible to achieve a certain position of the mechanism.

    In addition to the above-mentioned potentiometer, gearbox and electric motor, the servos are equipped with an electronic board that processes the incoming signal of the external parameter value from the potentiometer, compares it, and, in accordance with the comparison result, starts or stops the electric motor. In other words, this electronic filling is responsible for supporting negative feedback.

    The servo drive is connected by three conductors, two of which supply voltage to the electric motor, and the third conductor receives a control signal, which is used to set the position of the motor shaft.

    In addition to the electric motor, another mechanism can also play the role of a drive, for example a pneumatic cylinder with a rod. Angle rotation sensors are also used as feedback sensors, or . The control unit is a servo amplifier, an individual inverter. It may also contain a control signal sensor.

    If it is necessary to create smooth braking or acceleration to prevent excessive dynamic loads on the engine, more complex control microcontroller circuits are used that can control the position of the working element much more accurately. The drive device for setting the position of the heads in computer hard drives is designed in a similar way.

    Types of servos

    If it is necessary to create control of several groups of servo drives, use CNC controllers, which are assembled in the diagrams programmable logic controllers. Such servos are capable of providing a torque of 50 N*m, with a power of up to 15 kilowatts.

    Synchronous are able to set the rotation speed of the electric motor with great accuracy, as well as acceleration and rotation angle. Synchronous drive types can quickly reach rated speed.

    Asynchronous able to accurately maintain speed even at very low speeds.

    Servo drives are fundamentally divided into electromechanical And electrohydromechanical . Electromechanical drives consist of a gearbox and an electric motor. But their performance is much slower. In electrohydromechanical drives, motion is created by the movement of a piston in a cylinder, as a result of which the speed is at a very high level.

    Servo Drive Characteristics

    Let's consider the main parameters that characterize servos:

    • Shaft force. This parameter is the torque. This is the most important parameter servo drive. The data sheet most often indicates several torque values ​​for different voltage values.
    • Turning speed is also important characteristic. It is indicated in terms of the equivalent time required to change the position of the actuator output shaft by 60 degrees. This parameter can also be specified for multiple voltage values.
    • Servo type can be analog or digital.
    • Nutrition . The main part of the servos operates at a voltage of 4.8-7.2 volts. Power is most often supplied through three conductors: white – control signal, red – operating voltage, black – common wire.
    • Rotation angle - this is the largest angle through which the output shaft can rotate. Most often this parameter is 180 or 360 degrees.
    • Constant rotation . If necessary, a conventional servo can be retrofitted for continuous rotation.
    • Material of manufacture Servo gearboxes can be of different types: carbon, metal, plastic, or a combination. Gears made of plastic cannot withstand shock loads, but have high wear resistance. Carbon gears are much stronger than plastic ones, but are more expensive. Metal gears can withstand significant loads and falls, but have low wear resistance. The output shaft of the gearbox is installed differently on different models: on sliding bushings or on ball bearings.


    Advantages
    • Ease and simplicity of installation of the structure.
    • Reliability and reliability, which is important for critical devices.
    • They do not create noise during operation.
    • Precision and smooth movement is achieved even at low speeds. Depending on the task at hand, the resolution can be adjusted by the employee.
    Flaws
    • Difficult to set up.
    • Increased cost.

    Application

    Servo drives are currently used quite widely. For example, they are used in various precision instruments, industrial robots, production machines printed circuit boards, computer-controlled machines, various valves and gate valves.

    High-speed drives have become the most popular in aircraft modeling. Servo motors have the advantage of efficient electrical energy consumption as well as uniform movement.

    At the beginning of the appearance of servomotors, commutator three-pole motors with windings on the rotor and permanent magnets on the stator were used. In addition, the engine design included a unit with a commutator and brushes. Further, as technical progress the number of motor windings increased to five, and the rotation torque increased, as well as the acceleration speed.

    The next stage in the development of servo motors was the location of the windings outside the magnets. This reduced the mass of the rotor and reduced the acceleration time. At the same time, the cost of the engine has increased. As a result of further design of servomotors, it was decided to abandon the presence of a commutator in the motor design. Motors with permanent magnet rotors began to be used. The motor became brushless, its efficiency increased due to an increase in torque, speed and acceleration.

    IN lately The most popular are servomotors powered by a programmable controller (Arduino). As a result, great opportunities have opened up for the design of precision machine tools, robotics, and aircraft manufacturing (quadcopters).

    Since drives with motors without commutators have high functional characteristics, precise control, increased efficiency, they are often used in industrial equipment, household appliances(powerful vacuum cleaners with filters), and even in children's toys.

    Heating servo drive

    Compared to mechanical adjustment of the heating system, electric servos are the most advanced and progressive technical devices ensuring the maintenance of space heating parameters.


    1 - Power supply
    2 - Room thermostats
    3 - Switching block
    4 - Servomotors
    5 - Supply manifold
    6 - Bypass
    7 — Water heated floor
    8 - Return manifold
    9 — Water temperature sensor
    10 - Circular pump
    11 - Ball valve
    12 — Control valve
    13 - Two-way thermostatic valve

    The heating system drive operates in conjunction with a wall-mounted thermostat. An electrically driven faucet is mounted on the coolant supply pipe, in front of the warm water floor collector. Next, connect the 220 volt power supply and set the operating mode thermostat.

    The control system is equipped with two sensors. One of them is located in the floor, the other in the room. The sensors transmit signals to a thermostat that controls a servomotor that is connected to the faucet. You can increase the accuracy of adjustment by installing additional device outside the room, since climate conditions are constantly changing and affect the temperature in the room.

    The actuator is mechanically connected to the valve to control it. Valves can be two- or three-way. A two-way valve can change the temperature of the water in the system. The three-way valve is able to maintain the temperature constant, but it changes the consumption of hot water that is supplied to the circuits. The three-way valve device has two hot water inlets (supply pipes) and a return water outlet through which mixed water is supplied at a predetermined temperature.

    Mixing of water occurs using a valve. At the same time, the supply of coolant to the collectors is adjusted. When one entrance opens, the other begins to close, and the water flow at the outlet does not change.

    Trunk servos

    Currently, modern cars are most often produced with an automatic trunk opening function. For this purpose, the servo drive design we discussed is used. Automakers use two methods to equip a vehicle with this feature.

    Of course, the trunk pneumatic drive is more reliable, but its cost is quite high, so such a drive has not been used in cars.

    The electric drive is available with different control methods:

    • The handle is on the trunk lid.
    • Button on the driver's door panel.
    • From the alarm panel.

    Opening the trunk manually is not always convenient. For example, in winter the castle tends to freeze. The servo drive additionally performs the function of protecting the car from unauthorized entry, as it is combined with the locking device.

    Such trunk drives are used on some imported cars, however, it is possible to install such a mechanism on domestic cars, if desired.

    There are trunk drives with magnetic plates, but they have not found application since their design is quite complex.

    The most affordable ones are trunk servos, which only open. The closing function is not available for them. You can also choose a drive model design that has an inertial mechanism. It plays the role of blocking when an obstacle appears when the trunk moves.

    Expensive models of servo drives include a mechanism for raising and lowering the trunk, a closer locking mechanism, sensors and a controller. They are usually installed on cars at the factory, but simple designs can be installed independently.

    A servo drive is a negative feedback driven drive that allows precise control of motion parameters. Servo drive is any type mechanical drive, which contains a sensor (position, speed, force, etc.) and a drive control unit, automatically maintains the necessary parameters on the sensor and device according to a given external value.

    Many servos can be connected to Arduino directly. To do this, a loop of three wires comes from them:

    red – food connects to 5V pin or directly to power supply
    brown or black ground (GND pin of Arduino)
    yellow or white signal; connects to the Arduino digital output.

    It is possible to generate control pulses yourself, but this is such a common task that there is a standard Servo library to simplify it ( ).
    More details about the library
    The library itself is also

    Dietary restrictions

    A typical hobby servo drive consumes more than 100 mA when operating. At the same time, Arduino is capable of delivering up to 500 mA. Therefore, if you need to use several servos in a project, it makes sense to think about separating the servos into a circuit with additional power.

    Limitations on the number of connected servos

    On most boards Arduino library Servo supports control of up to 12 servos, per Arduino Mega this number increases to 48. However, there is a small side effect of using this library: if you are not working with Arduino Mega, then it becomes impossible to use the function analogWrite() on pins 9 and 10, regardless of whether servos are connected to these pins or not. You can connect up to 12 servos to the Arduino Mega without disrupting PWM/PWM functionality when using more we cannot use servos analogWrite() on pins 11 and 12.

    Servo library functions

    Library Servo allows for software control servos. For this purpose, a servo object of the Servo class is created. Management is carried out by the following functions:

    attach()– secures the drive with a specific pin. There are two syntax options for this function: servo.attach (pin) і servo.attach (pin, min, max). In this case, pin is the number of the pin to which the servo drive is connected, min and max are the pulse lengths in microseconds, responsible for the rotation angles of 0 ° and 180 °. By default, they are set to 544 μs and 2400 μs, respectively.
    write()– commands the servo drive to accept a certain parameter value. The syntax is as follows: servo.write(angle), where angle is the angle at which the servo should turn.
    writeMicroseconds()– gives a command to send a pulse of a certain length to the servo drive; it is a low-level analogue of the previous command. The syntax is as follows: servo.writeMicroseconds (uS), where uS is the pulse length in microseconds.
    read()– reads the current value of the angle at which the servo is located. The syntax is as follows: servo.read(), returns an integer value from 0 to 180.
    attached()– checking whether an object was attached to a specific pin. The syntax is as follows: servo.attached(), a boolean one is returned if the object was attached to any foam, or a zero otherwise.
    detach()- performs an action, reverse action attach(), i.e. detaches an object from the pin to which it was assigned. The syntax is as follows: servo.detach().

    A potentiometer can be used to control the change in servo position. It has three contacts connected as follows:
    The two extreme contacts (as a rule) are power and ground, and the middle one is information. We connect the power of the potentiometer –> 5 V Arduino, ground –> GND Arduino, information –> analog pin of Arduino.
    This is what the diagram might look like:

    And this is a primitive program:

    #include Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin void setup() ( myservo.attach(9); // attaches the servo on pin 9 to the servo object ) void loop() ( val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo.write(val ); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there )

    #include

    Servo myservo ; // create servo object to control a servo

    int potpin = 0 ; // analog pin used to connect the potentiometer

    int val ; // variable to read the value from the analog pin