nRF24L01, encoder, pca9685, pid
Dependencies: mbed QEI-1 LibPN532 nRF24L01P xiugai
Diff: main.cpp
- Revision:
- 7:6f8157c58241
- Parent:
- 6:7db9b13ece76
--- a/main.cpp Sun Nov 03 08:26:46 2019 +0000 +++ b/main.cpp Thu Nov 07 06:31:09 2019 +0000 @@ -4,82 +4,20 @@ #include <string> typedef bool boolean; typedef std::string String; -#include "QEI.h" -#include "converters.h" - -int Position; -float Error; -int Output; -float Error_Last; -float P; -float Error_int; -float I; -float Error_diff; -float D; - -QEI qei_PA_0(PA_0,PA_1,NC,13,QEI::X4_ENCODING); -Serial Serial_2(PA_2,PA_3); -PwmOut myServoPB_0(PB_0); -PwmOut myServoPB_1(PB_1); -Ticker tick241376; +#include "SYN6288.h" -void PID_Caculation() { -Error = 0 - Position; -Error_diff = Error - Error_Last; -Error_Last = Error; -Error_int = Error_int + Error; -if (Error_int > 100) { -Error_int = 100; -} else if (Error_int < -100) { -Error_int = -100; -} -if (Error > -10 && Error < 10) { -Output = 0; -} else { -Output = P * Error + (I * Error_int + D * Error_diff); -} -if (Output > 100) { -Output = 100; -} else if (Output < -100) { -Output = -100; -} -} +String str; -void Set_speed() { -if (Output >= 0) { -myServoPB_0.period_ms(20); -myServoPB_0.pulsewidth_us((200 * Output)); -myServoPB_1.period_ms(20); -myServoPB_1.pulsewidth_us(0); -} else if (Output < 0) { -myServoPB_0.period_ms(20); -myServoPB_0.pulsewidth_us(0); -myServoPB_1.period_ms(20); -myServoPB_1.pulsewidth_us((-200 * Output)); -} -} - -void tick241376_handle() { -Position = Position + qei_PA_0.getPulses(); -qei_PA_0.reset(); -Serial_2.printf("%d\n",_p(Position)); -PID_Caculation(); -Set_speed(); -} - +Serial syn6288_Serial_2(PA_2,PA_3); int main() { -Serial_2.baud(9600); - -tick241376.attach(&tick241376_handle,0.05); -Position = 0; -qei_PA_0.reset(); -P = 1; -I = 0; -D = 1; -while (true) { +for (int count = 0; count < 100; count++) { +str = "\xc4\xe3\xba\xc3"; +str += String("\xca\xc0\xbd\xe7"); +voice_play(str,&syn6288_Serial_2); +wait_ms(2000); } } \ No newline at end of file