-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added servo component to the registry
fix: Added copyright notice on the servo_control.c file fix: Added servo example to the patterns in the rules.yml fix: Typo fixed in the servo example pattern in the rules.yml fix: Typo fixed in the .rules:build:components_motor_servo_test_apps fix: Changes in the test script to reduce the test scope for multiple targets
- Loading branch information
1 parent
aff99b9
commit aa94cc6
Showing
17 changed files
with
508 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# ChangeLog | ||
|
||
## v0.1.0 - 2024-11-27 | ||
|
||
### Enhancements: | ||
|
||
* Initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Servo Motor Component | ||
|
||
This component provides an easy-to-use interface for controlling servo motors with the ESP-IDF framework. Servo motors are commonly used in robotics, automation, and various mechanical applications due to their precise control of angular position. | ||
|
||
The library uses PWM (Pulse Width Modulation) to control servo motor rotation and supports customizable configurations for angle limits, pulse width, frequency, and more. | ||
|
||
## Features | ||
|
||
- Easy control of servo motors using PWM signals | ||
- Support for custom angle range and pulse width | ||
- Flexible configuration of PWM channels and timers | ||
- Compatible with the ESP-IDF framework | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- ESP-IDF installed and configured on your development environment | ||
- A servo motor compatible with PWM signals | ||
- Proper connections between the ESP32 and the servo motor (signal, VCC, GND) | ||
|
||
## How to use | ||
|
||
Initialize the sensor with the configuration: | ||
|
||
```c | ||
servo_config_t servo_cfg = { | ||
.max_angle = 180, | ||
.min_width_us = 500, | ||
.max_width_us = 2500, | ||
.freq = 50, | ||
.timer_number = LEDC_TIMER_0, | ||
.channels = { | ||
.servo_pin = { | ||
SERVO_GPIO, | ||
}, | ||
.ch = { | ||
LEDC_CHANNEL_0, | ||
}, | ||
}, | ||
.channel_number = 1, | ||
}; | ||
|
||
// Initialize the servo | ||
iot_servo_init(LEDC_LOW_SPEED_MODE, &servo_cfg); | ||
``` | ||
Set the angle: | ||
```c | ||
uint16_t angle = 0; | ||
iot_servo_write_angle(LEDC_LOW_SPEED_MODE, 0, angle); | ||
``` | ||
|
||
## Reference | ||
|
||
[Documentation](https://docs.espressif.com/projects/esp-iot-solution/en/latest/motor/servo.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(servo_control) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Example for the servo component | ||
|
||
This example shows how to use the servo component. | ||
|
||
## How to use | ||
|
||
Initialize the sensor with the configuration: | ||
|
||
```c | ||
servo_config_t servo_cfg = { | ||
.max_angle = 180, | ||
.min_width_us = 500, | ||
.max_width_us = 2500, | ||
.freq = 50, | ||
.timer_number = LEDC_TIMER_0, | ||
.channels = { | ||
.servo_pin = { | ||
SERVO_GPIO, | ||
}, | ||
.ch = { | ||
LEDC_CHANNEL_0, | ||
}, | ||
}, | ||
.channel_number = 1, | ||
}; | ||
|
||
// Initialize the servo | ||
iot_servo_init(LEDC_LOW_SPEED_MODE, &servo_cfg); | ||
``` | ||
Set the angle: | ||
```c | ||
uint16_t angle = 0; | ||
iot_servo_write_angle(LEDC_LOW_SPEED_MODE, 0, angle); | ||
``` |
2 changes: 2 additions & 0 deletions
2
components/motor/servo/examples/servo_control/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "servo_control.c" | ||
INCLUDE_DIRS ".") |
4 changes: 4 additions & 0 deletions
4
components/motor/servo/examples/servo_control/main/idf_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies: | ||
espressif/servo: | ||
version: "*" | ||
override_path: '../../../' |
73 changes: 73 additions & 0 deletions
73
components/motor/servo/examples/servo_control/main/servo_control.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <math.h> | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "esp_log.h" | ||
#include "esp_system.h" | ||
#include "sdkconfig.h" | ||
#include "iot_servo.h" | ||
|
||
#define SERVO_GPIO (2) // Servo GPIO | ||
|
||
static const char *TAG = "Servo Control"; | ||
|
||
static uint16_t calibration_value_0 = 30; // Real 0 degree angle | ||
uint16_t calibration_value_180 = 195; // Real 0 degree angle | ||
|
||
// Task to test the servo | ||
static void servo_test_task(void *arg) | ||
{ | ||
ESP_LOGI(TAG, "Servo Test Task"); | ||
while (1) { | ||
// Set the angle of the servo | ||
for (int i = calibration_value_0; i <= calibration_value_180; i += 1) { | ||
iot_servo_write_angle(LEDC_LOW_SPEED_MODE, 0, i); | ||
vTaskDelay(20 / portTICK_PERIOD_MS); | ||
} | ||
// Return to the initial position | ||
iot_servo_write_angle(LEDC_LOW_SPEED_MODE, 0, calibration_value_0); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
} | ||
vTaskDelete(NULL); | ||
} | ||
|
||
static void servo_init(void) | ||
{ | ||
ESP_LOGI(TAG, "Servo Control"); | ||
|
||
// Configure the servo | ||
servo_config_t servo_cfg = { | ||
.max_angle = 180, | ||
.min_width_us = 500, | ||
.max_width_us = 2500, | ||
.freq = 50, | ||
.timer_number = LEDC_TIMER_0, | ||
.channels = { | ||
.servo_pin = { | ||
SERVO_GPIO, | ||
}, | ||
.ch = { | ||
LEDC_CHANNEL_0, | ||
}, | ||
}, | ||
.channel_number = 1, | ||
}; | ||
|
||
// Initialize the servo | ||
iot_servo_init(LEDC_LOW_SPEED_MODE, &servo_cfg); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
ESP_LOGI(TAG, "Servo Control"); | ||
// Initialize the servo | ||
servo_init(); | ||
// Create the servo test task | ||
xTaskCreate(servo_test_task, "servo_test_task", 2048, NULL, 5, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 0.1.0 | ||
description: Espressif's Servo Motor Component | ||
url: https://github.com/espressif/esp-iot-solution/tree/master/components/motor/servo | ||
repository: https://github.com/espressif/esp-iot-solution.git | ||
issues: https://github.com/espressif/esp-iot-solution/issues | ||
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/motor/servo.html | ||
dependencies: | ||
idf: | ||
version: '>=4.4' |
Oops, something went wrong.