Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/02/28 22:01] – [Suggested Readings and Knowledge Resources] pczekalskien: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 "analogue" servo is controlled with a PWM signal of 50Hz with a duty cycle between 1 ms (rotate to 0) and 2 ms (rotate to 180 degrees), where 1.5 ms corresponds to 90 degrees.  You will learn how to control a standard miniature servo in this scenario. Standard miniature, so-called "analogue" servo is controlled with a PWM signal of 50Hz with a duty cycle between 1 ms (rotate to 0) and 2 ms (rotate to 180 degrees), where 1.5 ms corresponds to 90 degrees. 
 <note warning>Do not keep the servo rotating when leaving the lab. Implement your code as non-repeating. A servo that remains rotating for a long time may easily wear out its gears, overheat and even burn!</note> <note warning>Do not keep the servo rotating when leaving the lab. Implement your code as non-repeating. A servo that remains rotating for a long time may easily wear out its gears, overheat and even burn!</note>
 +A servo has a red arrow presenting the gauge's current position. <note important>Note that servos tend to have relatively high implementation inaccuracy. Moreover, as the arrow is not in the centre of view of the camera but instead to the corner, the reading may be subject to error because of the parallaxes and lens distortion.</note> 
  
 +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 ''ledc'' we will use a dedicated library: To ease servo control, instead of use of ''ledc'' we will use a dedicated library:
Line 13: Line 15:
   * [[en:iot-open:introductiontoembeddedprogramming2:cppfundamentals]]   * [[en:iot-open:introductiontoembeddedprogramming2:cppfundamentals]]
   * [[en:iot-open:hardware2:esp32|]]   * [[en:iot-open:hardware2:esp32|]]
-  * [[en:iot-open:hardware2:actuators_light|]] 
   * [[en:iot-open:practical:hardware:sut:esp32|]]   * [[en:iot-open:practical:hardware:sut:esp32|]]
   * [[en:iot-open:embeddedcommunicationprotocols2:pwm|]]   * [[en:iot-open:embeddedcommunicationprotocols2:pwm|]]
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>Do not keep the servo rotating when leaving the lab. Implement your code as non-repeating. A servo that remains rotating for a long time may easily wear out its gears, overheat and even burn!</note>
  
 ==== 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, etc.+Check if the servo is in the camera viewThe servo is controlled with GPIO 37.
  
 ==== Steps ==== ==== Steps ====
-// Write some extra information ifi.e. some steps are optional; otherwise, cancel this paragraph (but do not remove the header).//+**Write your application all in the ''setup()'' functionleaving ''loop()'' empty.** 
 +<note warning>Do not keep the servo rotating when leaving the labImplement your code as non-repeating. A servo that remains rotating for a long time may easily wear out its gears, overheat and even burn!</note>
 === 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 <Servo.h> 
 +#define SRV_PIN 37 
 +</code> 
 +MG 90 servos that we use in our lab are specificAs 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     2 
 +#define srv_min_us  550 
 +#define srv_max_us 2400 
 +</code>
  
-...+=== Step 2 === 
 +Define a servo controller object: 
 +<code c> 
 +static Servo srv; 
 +</code>
  
-=== Step === +=== Step === 
-//Describe activities done in Step n.//+Initialise parameters (duty cycle, channel, GPIO): 
 +<code c> 
 +srv.attach(SRV_PIN, PWMSRV_Ch,srv_min_us, srv_max_us); 
 +</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,180); 
 +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?**: Answer. 
-// 
  
 +**How do I know minimum and maximum values for the timings for servo operation?**: Those parameters are provided along with servo technical documentation, so you should refer to them. Our configuration reflects the servos we use (MG90/SG90), and as you can see, it goes far beyond the standard servo rotation control that is a minimum of 1000us and a maximum of 2000us. Using standard configuration, your servo won't rotate at full 180 degrees but at a shorter rotation range.
 +
 +==== Result validation ====
 +Observe the red arrow to rotate accordingly. Remember to give the servo some time to operate.
 +
 +<WRAP noprint>
 ===== Project information ===== ===== Project information =====
 {{:en:iot-open:logo_iot_200_px.png?200|}}\\ {{:en:iot-open:logo_iot_200_px.png?200|}}\\
Line 61: Line 88:
 {{:en:iot-open:ccbync.png?100|}} {{:en:iot-open:ccbync.png?100|}}
 </figure> </figure>
- +</WRAP>
- +
en/iot-open/practical/hardware/sut/esp32/emb10_1.1709157686.txt.gz · Last modified: 2024/02/28 22:01 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0