-
Notifications
You must be signed in to change notification settings - Fork 792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added servo component to the registry #419
Open
pedrominatel
wants to merge
3
commits into
espressif:master
Choose a base branch
from
pedrominatel:servo-motor-as-component-registry
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
pedrominatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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 | ||
pedrominatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/motor/servo.html | ||
dependencies: | ||
idf: | ||
version: '>=4.4' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to adding the servo component in
build.yml
, it is also necessary to add rules for servo inrules.yml
to ensure that changes to servo and projects dependent on servo can trigger the CI. You can refer to any existing component inrules.yml
as a reference to complete the rule definition for servo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did but I'm not sure if I did correctly. Can you kindly review it?
Thank you, @YanKE01.