control for robotic arm that can play chess using a granular gripper

Dependencies:   Encoder mbed HIDScope Servo MODSERIAL

Fork of chessRobot by a steenbeek

Revision:
81:71e7e98deb2c
Parent:
62:6c566e6f9664
Child:
82:4cc8f9ad3fec
--- a/PID/PID.cpp	Tue Oct 20 13:39:05 2015 +0200
+++ b/PID/PID.cpp	Tue Oct 20 14:25:31 2015 +0200
@@ -55,12 +55,20 @@
 
 void PID::SetTunings(double Kp, double Ki, double Kd)
 {
+	if (Kp<0 || Ki<0|| Kd<0) return;
 	kp = Kp;
-	ki = Ki * SampleTime; // change PID parameters according to sample time
+	ki = Ki * SampleTime; // change PID parameters according to sample time (in seconds)
 	kd = Kd / SampleTime;
+
+	if(controllerDirection ==REVERSE){
+      kp = (0 - kp);
+      ki = (0 - ki);
+      kd = (0 - kd);
+   }
 }
 
 
+
 void PID::SetSampleTime(double NewSampleTime){
 	if (NewSampleTime > 0 ){
 		// change ratios for parameters for better computation in compute()
@@ -102,6 +110,10 @@
 	else if(ITerm<outMin) ITerm=outMin;
 }
 
+void PID::SetControllerDirection(int Direction){
+	controllerDirection = Direction;
+}
+
 double PID::getKp(){
 	return kp;
 }