mirror of
https://github.com/GyverLibs/GyverMotor2.git
synced 2026-06-05 14:47:00 +03:00
Compare commits
4 Commits
1.0.0
..
9bfa5d429a
| Author | SHA1 | Date | |
|---|---|---|---|
| 9bfa5d429a | |||
| 160ed7a24f | |||
| 691cae2cf6 | |||
| 03743c449c |
@@ -0,0 +1,32 @@
|
||||
|
||||
name: Publish to PlatformIO Registry
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout release tag
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.release.tag_name }}
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
- name: Install PlatformIO
|
||||
run: pip install -U platformio
|
||||
|
||||
- name: Check package
|
||||
run: pio pkg pack
|
||||
|
||||
- name: Publish to PlatformIO Registry
|
||||
env:
|
||||
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
|
||||
run: pio pkg publish --owner gyverlibs --non-interactive
|
||||
@@ -8,13 +8,28 @@ jobs:
|
||||
name: Send Message
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: send telegram message on push
|
||||
- name: Check if major or minor release
|
||||
id: semver
|
||||
shell: bash
|
||||
run: |
|
||||
TAG="${{ github.event.release.tag_name }}"
|
||||
VERSION="${TAG#v}"
|
||||
PATCH="$(echo "$VERSION" | cut -d. -f3)"
|
||||
|
||||
if [[ "$PATCH" == "0" ]]; then
|
||||
echo "should_send=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "should_send=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: send telegram message on release
|
||||
if: steps.semver.outputs.should_send == 'true'
|
||||
uses: appleboy/telegram-action@master
|
||||
with:
|
||||
to: ${{ secrets.TELEGRAM_TO }}
|
||||
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||
disable_web_page_preview: true
|
||||
message: |
|
||||
${{ github.event.repository.name }} v${{ github.event.release.tag_name }}
|
||||
${{ github.event.repository.name }} ${{ github.event.release.tag_name }}
|
||||
${{ github.event.release.body }}
|
||||
https://github.com/${{ github.repository }}
|
||||
|
||||
+78
-70
@@ -1,142 +1,150 @@
|
||||
This is an automatic translation, may be incorrect in some places. See sources and examples!
|
||||
This is an automatic translation and may be incorrect in some places. See the source README and examples for authoritative information.
|
||||
|
||||
[](https://github.com/GyverLibs/GyverMotor2/releases/latest/download/GyverMotor2.zip)
|
||||
[](https://registry.platformio.org/libraries/gyverlibs/GyverMotor2)
|
||||
[](https://alexgyver.ru/)
|
||||
[](https://alexgyver.ru/support_alex/)
|
||||
[](https://github-com.translate.goog/GyverLibs/GyverMotor2?_x_tr_sl=ru&_x_tr_tl=en)
|
||||
|
||||
[](https://t.me/GyverLibs)
|
||||
|
||||
# GyverMotor2
|
||||
Library for controlling commutator motors via a driver, an improved version of the library [GyverMotor](https://github.com/GyverLibs/GyverMotor)
|
||||
- Control of speed and direction of rotation
|
||||
- Work with PWM of any resolution
|
||||
Library for managing collector motors through a driver, improved version of the library[GyverMotor](https://github.com/GyverLibs/GyverMotor)
|
||||
- Speed and direction control
|
||||
- Working with PWM of any permission
|
||||
- Smooth start and speed change
|
||||
- Minimum PWM threshold
|
||||
- Software deadtime
|
||||
- Supports 7 types of drivers
|
||||
- software deadtime
|
||||
- Support for 7 Types of Drivers
|
||||
|
||||
### Compatibility
|
||||
Compatible with all Arduino platforms (uses Arduino functions)
|
||||
Compatible with all Arduino platforms (Arduino features are used)
|
||||
|
||||
## Contents
|
||||
- [Usage](#usage)
|
||||
- [Use of use](#usage)
|
||||
- [Versions](#versions)
|
||||
- [Installation](#install)
|
||||
- [Bugs and feedback](#feedback)
|
||||
|
||||
<a id="usage"></a>
|
||||
|
||||
## Usage
|
||||
## Use of use
|
||||
### Driver type
|
||||
|Driver |Description |Pins |speed > 0 |speed < 0 |stop |brake |
|
||||
|---------------------|------------------------|-------------------|-------------|-------------|-----------|-------------|
|
||||
| Driver | Description | Pines | speed > 0 | speed < 0 | stop | brake |
|
||||
|----------------------|-------------------------|-------------------|-------------|-------------|-----------|-------------|
|
||||
| `GM2::ONLY_PWM`| PWM only | (PWM) | (PWM) | (PWM) | (0) | (0) |
|
||||
|`GM2::DIR_DIR` |Direction only |(GPIO, GPIO) |(0, 1) |(1, 0) |(0, 0) |(1, 1) |
|
||||
| `GM2::DIR_DIR`Only direction | (GPIO, GPIO) | (0, 1) | (1, 0) | (0, 0) | (1, 1) |
|
||||
| `GM2::DIR_PWM`| One PWM without inversion | (GPIO, PWM) | (0, PWM) | (1, PWM) | (0, 0) | (1, MAX) |
|
||||
| `GM2::DIR_PWM_INV`| One PWM with inversion | (GPIO, PWM) | (0, PWM) | (1, ~PWM) | (0, 0) | (1, MAX) |
|
||||
| `GM2::PWM_PWM_SPEED`| Two PWM, speed mode | (PWM, PWM) | (0, PWM) | (PWM, 0) | (0, 0) | (MAX, MAX) |
|
||||
|`GM2::PWM_PWM_POWER` |Two PWM, torque mode |(PWM, PWM) |(~PWM, MAX) |(MAX, ~PWM) |(0, 0) |(MAX, MAX) |
|
||||
| `GM2::PWM_PWM_POWER`| Two PWM torque mode | (PWM, PWM) | (~PWM, MAX) | (MAX, ~PWM) | (0, 0) | (MAX, MAX) |
|
||||
| `GM2::DIR_DIR_PWM`| Two directions and PWM | (GPIO, GPIO, PWM) | (0, 1, PWM) | (1, 0, PWM) | (0, 0, 0) | (1, 1, MAX) |
|
||||
|
||||
Notes:
|
||||
|
||||
- The pins in parentheses are in the order of the constructor, i.e.for example, for `DIR_PWM` the initialization will be `GyverMotor2<GM2::DIR_PWM> motor(gpio, pwm)`, where gpio is a regular digital pin (digitalWrite), pwm is a pin with PWM support (analogWrite)
|
||||
- `MAX` - maximum PWM value at the specified resolution
|
||||
- `PWM` - direct PWM `(0.. MAX)`
|
||||
- `~PWM` - reverse PWM `(MAX.. 0)`
|
||||
- In brackets, pins are indicated in the order of the designer, i.e. for example, for`DIR_PWM`initialization will`GyverMotor2<GM2::DIR_PWM> motor(gpio, pwm)`where gpio is a regular digital pin (digitalWrite), pwm is a PWM-enabled pin (analogWrite)
|
||||
- `MAX`- maximum PWM value at the specified permit
|
||||
- `PWM`- straight CHIM`(0.. MAX)`
|
||||
- `~PWM`- reverse CHIM`(MAX.. 0)`
|
||||
|
||||
Mode selection for H-bridge driver (2 pins, usually IN1 and IN2) - most driver modules for Arduino:
|
||||
Mode selection for the H-bridge driver (2 pins, usually IN1 and IN2) - most of the driver modules for the Arduino:
|
||||
|
||||
- For symmetrical speed operation in both directions, a dual PWM mode is recommended, where `PWM_PWM_SPEED` has a higher speed, and `PWM_PWM_POWER` is more stable at low speeds and has a higher torque on some motors and drivers.Ideal for wheeled robots
|
||||
- To work in both directions, when the symmetry of the motor operation is not important, you can use the `DIR_PWM_INV` mode - it saves one PWM pin.Drivers that work with `DIR_PWM` (without inversion) are rare
|
||||
- For one-way operation with speed control (MOSFET or bridge with a closed pin), the `ONLY_PWM` mode is suitable and uses only one pin
|
||||
- For relay control (without speed control) you can use the `DIR_DIR` mode
|
||||
- For symmetrical speed of operation in both directions, a mode with two PWM is recommended, where`PWM_PWM_SPEED`has a higher speed, and`PWM_PWM_POWER`It is more stable at low revs and has higher torque on some motors and drivers. Perfect for wheeled robots
|
||||
- To work in both directions, when the symmetry of the engine is not important, you can use the mode.`DIR_PWM_INV`- he saves one PIN. Drivers who work with`DIR_PWM`(without inversion) are rare.
|
||||
- For one-way operation with speed control (MOSFET or closed-pin bridge) the mode is suitable`ONLY_PWM`and uses only one pin.
|
||||
- For relay control (without speed control), you can use the mode`DIR_DIR`
|
||||
|
||||
For drivers with separate direction controlI eat cranberries and the speed IN1+IN2+EN needs the `DIR_DIR_PWM` mode.
|
||||
Drivers with separate direction control and speed IN1+IN2+EN need a mode`DIR_DIR_PWM`.
|
||||
|
||||
### Compilation settings
|
||||
Before connecting the library
|
||||
|
||||
```cpp
|
||||
#define GMOTOR2_NO_ACCEL // cut acceleration module
|
||||
#define GMOTOR2_NO_ACCEL // cut out
|
||||
```
|
||||
|
||||
### Class description
|
||||
```cpp
|
||||
// initialization indicating driver type, PWM resolution (bits) and pins
|
||||
// initialization indicating the driver type, PWM resolution (bit) and pins
|
||||
GyverMotor2<driver, res = 8>(uint8_t pinA, uint8_t pinB = 0xff, uint8_t pinC = 0xff);
|
||||
|
||||
// set deadtime (delay when changing direction) in microseconds (default 0)
|
||||
// set deadtime (delay in changing direction) in microseconds (default 0)
|
||||
void setDeadtime(uint8_t us);
|
||||
|
||||
// get deadtime in microseconds
|
||||
// Get deadtime in microseconds
|
||||
uint8_t getDeadTime();
|
||||
|
||||
// set direction reverse (default false)
|
||||
// set the reverse direction (silent. false)
|
||||
void setReverse(bool rev);
|
||||
|
||||
// get direction reverse
|
||||
// reverse
|
||||
bool getReverse();
|
||||
|
||||
// set minimum PWM (default 0)
|
||||
// set the minimum PWM (failed 0)
|
||||
void setMinDuty(uint16_t duty);
|
||||
|
||||
// set the minimum PWM as a % of the maximum (default 0)
|
||||
// set the minimum PWM in % of the maximum (failed 0)
|
||||
void setMinDutyPerc(uint8_t perc);
|
||||
|
||||
// get minimum PWM
|
||||
// get the minimum PWM
|
||||
uint16_t getMinDuty();
|
||||
|
||||
// get maximum PWM
|
||||
// maximise
|
||||
uint16_t getMaxDuty();
|
||||
|
||||
// set PWM speed (-max.. max)
|
||||
// set the PWM speed (-max. max. max.
|
||||
void runSpeed(int16_t speed);
|
||||
|
||||
// set the speed as a % of the maximum PWM (-100.. 100%)
|
||||
// set the speed in % of the maximum PWM (-100). 100%
|
||||
void runSpeedPerc(int8_t perc);
|
||||
|
||||
// get the current motor speed in PWM
|
||||
// Get the current speed of the motor in PIM
|
||||
int16_t getSpeed();
|
||||
|
||||
// get direction: motor is spinning (1 and -1), motor is stopped (0)
|
||||
// receive direction: motor turns (1 and -1), motor stops (0)
|
||||
int8_t getDir();
|
||||
|
||||
// stop.If acceleration is enabled, then smooth
|
||||
// stop. If the acceleration is activated, the
|
||||
void stop();
|
||||
|
||||
// active braking (keeps driver pins active)
|
||||
// Active braking (leaving driver pins active)
|
||||
void brake();
|
||||
|
||||
// stop and turn off the motor
|
||||
void disable();
|
||||
|
||||
// set acceleration in PWM per second.The real minimum is 5.0 to disable
|
||||
// set the acceleration in PWM per second. Real minimum - 5.0 to turn off
|
||||
void setAccel(uint16_t accel);
|
||||
|
||||
// set the acceleration in percent per second.0 to disable
|
||||
// set the acceleration as a percentage per second. 0 to turn off
|
||||
void setAccelPerc(uint8_t perc);
|
||||
|
||||
// get the period at least which tick should be called, ms
|
||||
// get a period at least less than which you need to call a tick, ms
|
||||
uint8_t getDt();
|
||||
|
||||
// get target speed (acceleration mode)
|
||||
// Get the target speed (acceleration mode)
|
||||
int16_t getTarget();
|
||||
|
||||
// smooth change to the specified speed with setAccel acceleration, call in loop.Returns true when speed is reached
|
||||
// smooth change to the specified speed with acceleration setAccel, call in loop. Return true when you reach speed
|
||||
bool tick();
|
||||
```
|
||||
|
||||
### Description of features
|
||||
#### Start and stop
|
||||
- `runSpeed` starts the motor at the specified speed, supports negative values for rotation in the opposite direction.When set to `0`, turns off the motor
|
||||
- `stop` - stop and shutdown, equivalent to calling `runSpeed(0)`
|
||||
- `setReverse` - motor reverse, when set to `true` it will rotate in the opposite direction
|
||||
- `brake` - active braking via the driver (not supported everywhere)
|
||||
- `disable` - stop and disable the driver
|
||||
### Description of the fit
|
||||
#### Launch and stop
|
||||
- `runSpeed`starts the motor at the specified speed, maintains negative values for rotation in the opposite direction. meaning`0`switch off
|
||||
- `stop`- stop and disconnect, equivalent to a call`runSpeed(0)`
|
||||
- `setReverse`- engine reverse, when installed`true`It will turn in the opposite direction.
|
||||
- `brake`Active braking through the driver (not supported everywhere)
|
||||
- `disable`Stop and disable the driver
|
||||
|
||||
#### DeadTime
|
||||
Inside, `runSpeed`, when changing the direction of rotation, turns off the driver and creates a delay for the specified number of microseconds, after which it sends the required signal to the motor.This is necessary for homemade simple H-bridge drivers to avoid shorting the bridge.Drivers in the form of chips and modules usually have built-in hardware deadtime and do not need to be enabled in the library.
|
||||
Inside.`runSpeed`When changing the direction of rotation, it turns off the driver and creates a delay for the specified number of microseconds, after which it gives the desired signal to the motor. This is necessary for homemade simple H-bridge drivers to avoid closing the bridge. Drivers in the form of chips and modules usually have built-in hardware deadtime and do not need to include it in the library.
|
||||
|
||||
#### MinDuty
|
||||
Allows you to set the minimum signal to the motor.The value supplied to `runSpeed` will scale linearly from the specified MinDuty to the maximum (if not zero).This allows you to “skip” the values at which the motor cannot move without changing the logic of the speed setting.Example values for 8 bits and `MinDuty=50`:
|
||||
Allows you to adjust the minimum signal to the motor. The value submitted in`runSpeed`It will scale linearly from MinDuty to maximum (if not zero). This allows you to "skip" the values at which the motor can not move without changing the logic of the speed setting. Example of values for 8 bits and`MinDuty=50`:
|
||||
|
||||
| `runSpeed`| Actual PWM |
|
||||
|------------|-----------------|
|
||||
|-----------|---------------- |
|
||||
| 0 | 0 |
|
||||
| 1 | 50 |
|
||||
| 50 | 90 |
|
||||
@@ -145,7 +153,7 @@ Allows you to set the minimum signal to the motor.The value supplied to `runSpee
|
||||
| 255 | 255 |
|
||||
|
||||
#### Accel
|
||||
When specifying a non-zero acceleration (in units of PWM per second), the `runSpeed` call will not apply the specified speed immediately, but will instead ramp smoothly towards the specified speed.To work, you need to call the ticker in the main program loop no less often than `getDt` milliseconds (varies from 30 to 200 depending on the acceleration).Calling `stop` will make a smooth stop, while `brake` and `disable` will stop the motor abruptly:
|
||||
When setting non-zero acceleration (in PWM units per second) call`runSpeed`does not apply the specified speed immediately, instead, the speed will change smoothly to the specified. To work, you need to call a ticker in the main cycle of the program at least less often than`getDt`milliseconds (ranging from 30 to 200 depending on acceleration) A challenge`stop`will make a smooth stop, and`brake`and`disable`Stop the engine abruptly:
|
||||
|
||||
```cpp
|
||||
void setup() {
|
||||
@@ -154,11 +162,11 @@ motor.runSpeed(170);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
motor.tick();// smoothly accelerates the motor to speed 170
|
||||
motor.tick(); // smoothly accelerate the motor to a speed of 170
|
||||
}
|
||||
```
|
||||
|
||||
Might come in handyis used when controlling a heavy wheeled robot to avoid jerks during acceleration and braking.
|
||||
It can be useful when driving a heavy wheeled robot to avoid jerks during acceleration and braking.
|
||||
|
||||
## Examples
|
||||
```cpp
|
||||
@@ -190,32 +198,32 @@ motor.runSpeed(speed);
|
||||
|
||||
<a id="install"></a>
|
||||
## Installation
|
||||
- The library can be found by the name **GyverMotor2** and installed through the library manager in:
|
||||
- The library can be found under the name **GyverMotor2** and installed through the library manager in:
|
||||
- Arduino IDE
|
||||
- Arduino IDE v2
|
||||
- PlatformIO
|
||||
- [Download library](https://github.com/GyverLibs/GyverMotor2/archive/refs/heads/main.zip).zip archive for manual installation:
|
||||
- [Download the library](https://github.com/GyverLibs/GyverMotor2/archive/refs/heads/main.zip).zip archive for manual installation:
|
||||
- Unpack and put in *C:\Program Files (x86)\Arduino\libraries* (Windows x64)
|
||||
- Unpack and put in *C:\Program Files\Arduino\libraries* (Windows x32)
|
||||
- Unpack and put in *Documents/Arduino/libraries/ *
|
||||
- (Arduino IDE) automatic installation from .zip: *Sketch/Connect library/Add .ZIP library…* and indicate the downloaded archive
|
||||
- (Arduino IDE) Automatic installation from .zip: *Sketch/Connect library/Add .ZIP library...* and specify downloaded archive
|
||||
- Read more detailed instructions for installing libraries[here](https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA)
|
||||
### Update
|
||||
- I recommend always updating the library: in new versions errors and bugs are corrected, as well as optimization is carried out and new features are added
|
||||
- Through the IDE library manager: find the library as during installation and click "Update"
|
||||
- Manually: **delete the folder with the old version**, and then put the new one in its place.“Replacement” cannot be done: sometimes new versions delete files that will remain after replacement and can lead to errors!
|
||||
- I recommend always updating the library: new versions fix errors and bugs, as well as optimize and add new features.
|
||||
- Through the library manager IDE: find the library as when installing and click "Update"
|
||||
- Manually: **Delete the folder with the old version** and then put the new one in its place. “Replacement” can not be done: sometimes new versions delete files that will remain when replaced and can lead to errors!
|
||||
|
||||
<a id="feedback"></a>
|
||||
|
||||
## Bugs and feedback
|
||||
When you find bugs, create an **Issue**, or better yet, immediately write to [alex@alexgyver.ru](mailto:alex@alexgyver.ru)
|
||||
The library is open for improvement and your **Pull Requests**!
|
||||
If you find bugs, create **Issue**, or better write to the mail immediately.[alex@alexgyver.ru](mailto:alex@alexgyver.ru)
|
||||
The library is open for revision and your **Pull Requests*!
|
||||
|
||||
When reporting bugs or incorrect operation of the library, be sure to indicate:
|
||||
When reporting bugs or incorrect work of the library, it is necessary to specify:
|
||||
- Library version
|
||||
- Which MK is used?
|
||||
- What is used by the IC
|
||||
- SDK version (for ESP)
|
||||
- Arduino IDE version
|
||||
- Do the built-in examples that use functions and constructs that lead to a bug in your code work correctly?
|
||||
- What code was loaded, what work was expected from it and how it works in reality
|
||||
- Ideally, attach the minimum code in which the bug is observed.Not a canvas of a thousand lines, but minimal code
|
||||
- Are embedded examples that use features and designs that cause bugs in your code working correctly?
|
||||
- What code was downloaded, what work was expected from it and how it works in reality
|
||||
- Ideally, attach the minimum code in which the bug is observed. Not a canvas of a thousand lines, but a minimum code.
|
||||
|
||||
Reference in New Issue
Block a user