Skip to content
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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/upload_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
components/led/lightbulb_driver;
components/motor/esp_sensorless_bldc_control;
components/motor/esp_simplefoc;
components/motor/servo;
components/openai;
components/sensors/humiture/aht20;
components/sensors/ntc_driver;
Expand Down
19 changes: 19 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,17 @@ build_example_motor_foc_knob:
variables:
EXAMPLE_DIR: examples/motor/foc_knob_example

build_example_motor_servo:
Copy link
Contributor

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 in rules.yml to ensure that changes to servo and projects dependent on servo can trigger the CI. You can refer to any existing component in rules.yml as a reference to complete the rule definition for servo.

Copy link
Member Author

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.

extends:
- .build_examples_template
- .rules:build:example_motor_servo
parallel:
matrix:
- IMAGE: espressif/idf:release-v4.4
- IMAGE: espressif/idf:release-v5.2
variables:
EXAMPLE_DIR: components/motor/servo/examples/servo_control

build_example_ota_simple_ota_example:
extends:
- .build_examples_template
Expand Down Expand Up @@ -1132,6 +1143,14 @@ build_components_motor_esp_simplefoc_test_apps:
variables:
EXAMPLE_DIR: components/motor/esp_simplefoc/test_apps

build_components_motor_servo_test_apps:
extends:
- .build_examples_template
- .rules:build:components_motor_servo_test_apps
- .build_idf_active_release_version
variables:
EXAMPLE_DIR: components/motor/servo/test_apps

build_components_ntc_driver_test_apps:
extends:
- .build_examples_template
Expand Down
18 changes: 17 additions & 1 deletion .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@

.patterns-components_motor_servo: &patterns-components_motor_servo
- "components/motor/servo/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

.patterns-components_openai: &patterns-components_openai
- "components/openai/**/*"
Expand Down Expand Up @@ -478,6 +479,9 @@
.patterns-example_motor_foc_knob: &patterns-example_motor_foc_knob
- "examples/motor/foc_knob_example/**/*"

.patterns-example_motor_servo: &patterns-example_motor_servo
- "components/motor/servo/examples/servo_control/**/*"

.patterns-example_ota_simple_ota_example: &patterns-example_ota_simple_ota_example
- "examples/ota/simple_ota_example/**/*"

Expand Down Expand Up @@ -1070,6 +1074,18 @@
- <<: *if-dev-push
changes: *patterns-example_motor_foc_knob

.rules:build:example_motor_servo:
rules:
- <<: *if-protected
- <<: *if-label-build
- <<: *if-trigger-job
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_motor_servo
- <<: *if-dev-push
changes: *patterns-example_motor_servo

.rules:build:example_ota_simple_ota_example:
rules:
- <<: *if-protected
Expand Down Expand Up @@ -1871,7 +1887,7 @@
- <<: *if-dev-push
changes: *patterns-components_motor_esp_sensorless_bldc_control

.rules:build:components_motor_servo_test:
.rules:build:components_motor_servo_test_apps:
rules:
- <<: *if-protected
- <<: *if-label-build
Expand Down
7 changes: 7 additions & 0 deletions components/motor/servo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ChangeLog

## v0.1.0 - 2024-11-27

### Enhancements:

* Initial version
57 changes: 57 additions & 0 deletions components/motor/servo/README.md
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)
6 changes: 6 additions & 0 deletions components/motor/servo/examples/servo_control/CMakeLists.txt
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)
36 changes: 36 additions & 0 deletions components/motor/servo/examples/servo_control/README.md
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);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "servo_control.c"
INCLUDE_DIRS ".")
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 components/motor/servo/examples/servo_control/main/servo_control.c
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);
}
9 changes: 9 additions & 0 deletions components/motor/servo/idf_component.yml
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'
Loading
Loading