Committed for sharing.

Dependencies:   mbed SelfBalancingRobot_BerkYasarYavuz_AdilBerkayTemiz Motor ledControl2 HC_SR04_Ultrasonic_Library

Revision:
11:0a2944e7be23
Parent:
9:67f2110fce8e
diff -r 8050817ae610 -r 0a2944e7be23 BalancingRobot.h
--- a/BalancingRobot.h	Thu Aug 25 22:55:36 2016 +0000
+++ b/BalancingRobot.h	Wed Jan 01 20:31:22 2020 +0000
@@ -6,18 +6,14 @@
 BusOut LEDs(LED1, LED2, LED3, LED4);
 
 /* Left motor */
-DigitalOut leftA(p5);
-DigitalOut leftB(p6);
-PwmOut leftPWM(p23);
+DigitalOut leftA(D6);
+DigitalOut leftB(D5);
+PwmOut leftPWM(D7);
 
 /* Right motor */
-DigitalOut rightA(p7);
-DigitalOut rightB(p8);
-PwmOut rightPWM(p24);
-
-/* Encoder variables */
-float LeftWheelPosition = 0.0;
-float RightWheelPosition = 0.0;
+DigitalOut rightA(D4);
+DigitalOut rightB(D3);
+PwmOut rightPWM(D2);
 
 // Results
 double accYangle;
@@ -26,15 +22,24 @@
 int16_t raw_gyroYrate;
 
 /* PID variables */
-double Kp = 0.5; //11 - 7
-double Ki = 0.00001; //1
-double Kd = 0.01; //12
+
+double Kp = 0.085; //0.100; //0.0400; // 11 - 7
+double Ki = 0.00900; //0.005;//0.00320; //1 0.001 sanki gideri var mı ne
+double Kd = 0.050;//0.0125 baya iyi //0.0333; //12
+
+//double Kp = 0.185; //11 - 7 almost well   //0.1
+//double Ki = 0.0000; //1                   //0.005  integralli ilk iyi gibi
+//double Kd = 0.1; //12                     //0.01
+
 double PIDValue = 0.0;
-double targetAngle = 1.05;
+double DesiredAngle;
+double ConstantAngle;
+unsigned int distF;
+unsigned int distB;
 double targetOffset = 0;
 float pitchAngle = 0;
 float rollAngle = 0;
-double error = 0.0;
+double error1 = 0.0;
 double lastError = 0.0;
 double iTerm;