-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add stepper motor driver firmware to sra-board-component #77
Open
ChinmayLonkar
wants to merge
12
commits into
SRA-VJTI:main
Choose a base branch
from
ChinmayLonkar:stepper_dev
base: main
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
12 commits
Select commit
Hold shift + click to select a range
1086727
Add stepper motor driver firmware to sra-board-component
ChinmayLonkar c4cf302
Add license to stepper.c
ChinmayLonkar dd0ba70
stepper.c: Modify include addressing for user defined header files
ChinmayLonkar f7396f7
Add stepper_motor to test build app
ChinmayLonkar e068833
Change project name in Makefile
ChinmayLonkar 52bc413
Update README
ChinmayLonkar 20094db
Correct formatting in README
ChinmayLonkar c5dc7e4
Change example name to stepper_motor
ChinmayLonkar ebb0524
Merge branch 'SRA-VJTI:main' into stepper_dev
ChinmayLonkar dda7369
Update branch
ChinmayLonkar 629cded
Applied recommended changes for making some variables static
ChinmayLonkar 803155e
Merge branch 'SRA-VJTI:main' into stepper_dev
ChinmayLonkar 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
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,8 @@ | ||
# The following 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.5) | ||
|
||
set(EXTRA_COMPONENT_DIRS ../../.) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(stepper_motor) |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Society of Robotics and Automation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := stepper_motor | ||
|
||
include $(IDF_PATH)/make/project.mk | ||
|
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,8 @@ | ||
# Edit following two lines to set component requirements (see docs) | ||
set(COMPONENT_REQUIRES ) | ||
set(COMPONENT_PRIV_REQUIRES ) | ||
|
||
set(COMPONENT_SRCS "main.c") | ||
set(COMPONENT_ADD_INCLUDEDIRS "") | ||
|
||
register_component() |
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,8 @@ | ||
# | ||
# Main component makefile. | ||
# | ||
# This Makefile can be left empty. By default, it will take the sources in the | ||
# src/ directory, compile them and link them into lib(subdirectory_name).a | ||
# in the build directory. This behaviour is entirely configurable, | ||
# please read the ESP-IDF documents if you need to do this. | ||
# |
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,59 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Society of Robotics and Automation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "sra_board.h" | ||
|
||
static const char *TAG = "STEPPER_DEBUG"; | ||
|
||
static const stepper_config_t stepper_1 = { | ||
.step_pin = STEP, | ||
.dir_pin = DIR, | ||
.accl_decel = 0.001, | ||
.min_step_interval_us = MIN_STEP_INTERVAL, | ||
.steps_per_revolution = 200, | ||
.current_step_count = 0, | ||
}; | ||
|
||
void run_motor(void *arg) | ||
{ | ||
while (1) | ||
{ | ||
ESP_LOGI(TAG, "Inside task"); | ||
move_to_step(&stepper_1, 10000); | ||
ESP_LOGI(TAG, "Done 1"); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
move_to_step(&stepper_1, 0); | ||
ESP_LOGI(TAG, "Done 2"); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
} | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
init_stepper(&stepper_1); | ||
xTaskCreatePinnedToCore(&run_motor, "Homing Task", 4096, NULL, 1, NULL, 0); | ||
} |
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 @@ | ||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n |
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 |
---|---|---|
|
@@ -105,4 +105,7 @@ | |
#define SERVO_D 18 | ||
///////////////////////////// | ||
|
||
#define STEP 14 | ||
#define DIR 27 | ||
|
||
#endif |
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,127 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Society of Robotics and Automation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#ifndef STEPPER_H | ||
#define STEPPER_H | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include "driver/gpio.h" | ||
#include "esp_timer.h" | ||
#include "esp32/rom/ets_sys.h" | ||
#include "esp_log.h" | ||
#include "esp_err.h" | ||
#include "esp_sleep.h" | ||
#include "pin_defs.h" | ||
|
||
#define MIN_STEP_INTERVAL 1000 | ||
|
||
typedef struct | ||
{ | ||
int step_pin; // Stepping Signal Pin of ESP32. | ||
int dir_pin; // Direction signal Pin of ESP32. | ||
int min_step_interval_us; // minimum step interval in microseconds | ||
int steps_per_revolution; // Number of Step pulses per revolution. | ||
int prev_delay; // Internal varaible to store previous pulse interval. | ||
int dir; // Internal variable to store the direction of stepper. | ||
float accl_decel; // Accelaration/Decelaration value. | ||
bool movement_done; // To check if movement is done. | ||
long current_step_count; // Internal variable to store current position of stepper motor. | ||
} stepper_config_t; | ||
|
||
/** @struct stepper_config_t | ||
* @brief This structure contains the configuration of stepper. | ||
* @var stepper_config_t::step_pin | ||
* Member 'step_pin' contains the gpio pin number to which step signal pin of stepper motor driver is connected | ||
* @var stepper_config_t::dir_pin | ||
* Member 'dir_pin' contains the gpio pin number to which direction signal pin of stepper motor driver is connected | ||
* @var stepper_config_t::min_step_interval_us | ||
* Member 'min_step_interval_us' contains the minimum pulse interval for the step signal of stepper motor | ||
* @var stepper_config_t::steps_per_revolution | ||
* Member 'steps_per_revolution' contains number of step pulses per revolution. | ||
* @var stepper_config_t::prev_delay | ||
* Member 'prev_delay' contains internal varaible to store previous pulse interval. | ||
* @var stepper_config_t::dir | ||
* Member 'dir' contains internal variable to store the direction of stepper. | ||
* @var stepper_config_t::accl_decel | ||
* Member 'accl_decel' contains accelaration/decelaration value. | ||
* @var stepper_config_t::movement_done | ||
* Member 'movement_done' contains variable to check if movement is done. | ||
* @var stepper_config_t::current_step_count | ||
* Member 'current_step_count' contains internal variable to store current position of stepper motor. | ||
*/ | ||
|
||
/** | ||
* @brief Initiates and configures ESP32 for stepper control | ||
|
||
* @param stepper pointer to stepper_config_t struct | ||
|
||
* @return esp_err_t i.e it shows if pins are configured successfully or not. | ||
**/ | ||
esp_err_t init_stepper(stepper_config_t *stepper); | ||
|
||
/** | ||
* @brief calculates first pulse interval delay as per the accelaration value. | ||
|
||
* @param stepper pointer to stepper_config_t struct | ||
|
||
* @return int containing first pulse interval delay as per the accelaration value. | ||
**/ | ||
static int calc_first_delay_in_millis(stepper_config_t *stepper); | ||
|
||
/** | ||
* @brief calculates delay for next step interval for accelaration. | ||
|
||
* @param stepper pointer to stepper_config_t struct | ||
|
||
* @param n count of the previous step that was executed. | ||
|
||
* @return int containing delay for next step interval for accelaration. | ||
**/ | ||
static int cal_delay_accl(stepper_config_t *stepper, int n); | ||
|
||
/** | ||
* @brief calculates delay for next step interval for decelaration. | ||
|
||
* @param stepper pointer to stepper_config_t struct | ||
|
||
* @param n count of the previous step that was executed. | ||
|
||
* @return int containing delay for next step interval for decelaration. | ||
**/ | ||
static int cal_delay_decel(stepper_config_t *stepper, int n); | ||
|
||
/** | ||
* @brief moves stepper to a specified position as per number of steps. | ||
|
||
* @param stepper pointer to stepper_config_t struct. | ||
* @param pos_step step position to which stepper should be moved. | ||
|
||
* @return esp_err_t i.e it shows if stepper has moved successfully or not. | ||
**/ | ||
esp_err_t move_to_step(stepper_config_t *stepper, float pos_step); | ||
|
||
#endif |
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.
STEP_DIR would be better
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.
These macros define the pins to which the
STEP
pin andDIRECTION
pins are connected to ESP32.we cannot name it STEP_DIR
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.
Is
DIR
okay then?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.
Also is
STEP
okay? it needs to mean something atleastThere 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 can make it
STEP_SIGNAL_PIN
andDIR_SIGNAL_PIN
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.
DIR_SIGNAL_PIN
should be related to the stepper.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.
CC @gautam-dev-maker suggest a better naming scheme