-
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.
Added servo component to the registry
Minor fix on the idf_component.yml file Added docs link and improved readme file Added test_apps to the servo component Added servo component to the CI
- Loading branch information
1 parent
aff99b9
commit e03d757
Showing
15 changed files
with
483 additions
and
1 deletion.
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
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: '../../../' |
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "driver/i2c_types.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"; | ||
|
||
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); | ||
} | ||
|
||
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: 1.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.