forked from CodeMunke/Robototechnics-AVR-car
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/LigntShot/Robototechnics-AVR…
…-car into dev
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <avr/interrupt.h> | ||
#include <avr/iom16.h> | ||
#include <avr/sfr_defs.h> | ||
#include <stdint.h> | ||
#include "CalculateWishSpeed.h" | ||
|
||
//Макросы, которые используются в ПИД-регуляторе для преобразования входной скорости в значения, которые использует ШИМ | ||
#define _MIN(x,y) ((x < y) ? x : y) | ||
#define _MAX(x,y) ((x > y) ? x : y) | ||
|
||
volatile uint8_t speed_cnt_left = 0; | ||
volatile uint8_t speed_cnt_right = 0; | ||
|
||
volatile int pwm_left = 0; | ||
volatile int pwm_right = 0; | ||
|
||
//Из файла "CalculateWishSpeed.h" | ||
//volatile uint8_t desired_speed_left = 0; | ||
//volatile uint8_t desired_speed_right = 0; | ||
|
||
ISR(INT0_vect) | ||
{ | ||
speed_cnt_left++; | ||
} | ||
|
||
ISR(INT1_vect) | ||
{ | ||
speed_cnt_right++; | ||
} | ||
|
||
//Регулировка скорости колёс (надо дописать изменение желаемой скорости в зависимости от left_ob и right_ob) | ||
void | ||
regulate_left() | ||
{ | ||
uint8_t spd_left = 0; //Фактическая скорость | ||
spd_left = speed_cnt_left; | ||
speed_cnt_left = 0; | ||
const uint8_t Kp = 1; | ||
uint8_t error = _MIN(_MAX(desired_speed_left - spd_left,0),20); //Обчисление пропорциональной составляющей ошибки | ||
|
||
pwm_left = Kp * error; //Величина-посредник для изменения скорости (ШИМ) | ||
} | ||
|
||
void | ||
regulate_right() | ||
{ | ||
uint8_t spd_right = 0; //Фактическая скорость | ||
spd_right = speed_cnt_right; | ||
speed_cnt_right = 0; | ||
const uint8_t Kp = 1; | ||
uint8_t error = _MIN(_MAX(desired_speed_right - spd_right,0),20); //Обчисление пропорциональной составляющей ошибки | ||
|
||
pwm_right = Kp * error; //Величина-посредник для изменения скорости (ШИМ) | ||
} |
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,10 @@ | ||
#ifndef ADJUST_SPEED_H_ | ||
#define ADJUST_SPEED_H_ | ||
|
||
void regulate_left(); | ||
void regulate_right(); | ||
|
||
volatile extern int pwm_left; | ||
volatile extern int pwm_right; | ||
|
||
#endif /* ADJUST_SPEED_H_ */ |