nRF24L01, encoder, pca9685, pid
Dependencies: mbed QEI-1 LibPN532 nRF24L01P xiugai
Diff: main.cpp
- Revision:
- 6:7db9b13ece76
- Parent:
- 4:652d2be11b35
- Child:
- 7:6f8157c58241
--- a/main.cpp Wed Oct 30 10:59:58 2019 +0000 +++ b/main.cpp Sun Nov 03 08:26:46 2019 +0000 @@ -5,6 +5,7 @@ typedef bool boolean; typedef std::string String; #include "QEI.h" +#include "converters.h" int Position; float Error; @@ -20,7 +21,7 @@ Serial Serial_2(PA_2,PA_3); PwmOut myServoPB_0(PB_0); PwmOut myServoPB_1(PB_1); -Ticker tick561436; +Ticker tick241376; void PID_Caculation() { Error = 0 - Position; @@ -58,24 +59,26 @@ } } -void tick561436_handle() { +void tick241376_handle() { Position = Position + qei_PA_0.getPulses(); qei_PA_0.reset(); -Serial_2.printf("%d\n",Position); +Serial_2.printf("%d\n",_p(Position)); PID_Caculation(); Set_speed(); } int main() { + + Serial_2.baud(9600); -tick561436.attach(&tick561436_handle,0.05); +tick241376.attach(&tick241376_handle,0.05); Position = 0; qei_PA_0.reset(); P = 1; I = 0; -D = 10; +D = 1; while (true) { }