This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/02/28 22:01] – [Suggested Readings and Knowledge Resources] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/04/09 12:58] (current) – [Result validation] pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== EMB10: Controlling standard servo ===== | + | ====== EMB10: Controlling standard servo ====== |
You will learn how to control a standard miniature servo in this scenario. Standard miniature, so-called " | You will learn how to control a standard miniature servo in this scenario. Standard miniature, so-called " | ||
<note warning> | <note warning> | ||
+ | A servo has a red arrow presenting the gauge' | ||
+ | The servo is an actuator. It requires a time to operate. So, you should give it time to operate between consecutive changes of the control PWM signal (requests to change its position). Moreover, because of the observation via camera, too quick rotation may not be observable at all depending on the video stream fps. A gap of 2s between consecutive rotations is usually a reasonable choice. | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
To ease servo control, instead of use of '' | To ease servo control, instead of use of '' | ||
Line 13: | Line 15: | ||
* [[en: | * [[en: | ||
* [[en: | * [[en: | ||
- | * [[en: | ||
* [[en: | * [[en: | ||
* [[en: | * [[en: | ||
Line 20: | Line 21: | ||
==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
- | //Describe a task to be implemented by the scenario user.// | + | Rotate the servo to the following angles: 0, 90, 180, 135, 45 and back to 0 degrees. |
+ | <note warning> | ||
==== Start ==== | ==== Start ==== | ||
- | //Write starting conditions, i.e. what to do in the beginning, what to pay attention to before beginning, how the mechanical part should look, etc.// Include needed compiler configuration, | + | Check if the servo is in the camera view. The servo is controlled with GPIO 37. |
==== Steps ==== | ==== Steps ==== | ||
- | // Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph | + | **Write your application all in the '' |
+ | <note warning> | ||
=== Step 1 === | === Step 1 === | ||
- | //Describe activities done in Step 1.// | + | Include servo control library, specific for ESP32 and declare GPIO, minimum and maximum duty cycle values: |
+ | <code c> | ||
+ | #include < | ||
+ | #define SRV_PIN 37 | ||
+ | </code> | ||
+ | MG 90 servos that we use in our lab are specific. As mentioned above, to achieve a full 180-degree rotation range, their minimum and maximum duty cycle timings go far beyond standards. Here, we declare minimum and maximum values for the duty cycle (in microseconds) and a PWM control channel (2): | ||
+ | <code c> | ||
+ | #define PWMSRV_Ch | ||
+ | #define srv_min_us | ||
+ | #define srv_max_us 2400 | ||
+ | </code> | ||
- | ... | + | === Step 2 === |
+ | Define a servo controller object: | ||
+ | <code c> | ||
+ | static Servo srv; | ||
+ | </ | ||
- | === Step n === | + | === Step 3 === |
- | //Describe activities done in Step n.// | + | Initialise parameters (duty cycle, channel, GPIO): |
+ | <code c> | ||
+ | srv.attach(SRV_PIN, | ||
+ | </code> | ||
+ | 50Hz frequency is standard, so we do not need to configure it. | ||
+ | |||
+ | === Step 4 === | ||
+ | Rotating a servo is as easy as writing the desired angle to the controller class, e.g.: | ||
+ | <code c> | ||
+ | srv.write(SRV_PIN, | ||
+ | delay(2000); | ||
+ | </code> | ||
- | ==== Result validation ==== | ||
- | //Provide some result validation methods for self-assessment.// | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | This section is to be extended as new questions appear. \\ | ||
- | When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. | ||
- | //Provide some FAQs in the following form:\\ | ||
- | **Question? | ||
- | // | ||
+ | **How do I know minimum and maximum values for the timings for servo operation? | ||
+ | |||
+ | ==== Result validation ==== | ||
+ | Observe the red arrow to rotate accordingly. Remember to give the servo some time to operate. | ||
+ | |||
+ | <WRAP noprint> | ||
===== Project information ===== | ===== Project information ===== | ||
{{: | {{: | ||
Line 61: | Line 88: | ||
{{: | {{: | ||
</ | </ | ||
- | + | </ | |
- | + |