diff --git a/examples/Nano/PID_Position_test/PID_Position_test.ino b/examples/Nano/PID_Position_test/PID_Position_test.ino index 3dc65f6..2c86aaa 100644 --- a/examples/Nano/PID_Position_test/PID_Position_test.ino +++ b/examples/Nano/PID_Position_test/PID_Position_test.ino @@ -1,5 +1,4 @@ -#include -//#include +#include #define INTERRUPT_PIN 6 //Variable to store the battery voltage @@ -9,6 +8,9 @@ static int batteryVoltage; static int duty = 0; int target; +float P; +float I; +float D; void setup() { @@ -48,47 +50,51 @@ void setup() Serial.print("Duty: "); Serial.println(dutyInit); - /************* PID 1 ***********************/ - -// pid1.setControlMode(CL_POSITION); -// -// //pid1.resetGains(); -// //pid1.setLimits(-100,100); -// pid1.setGains(0.01f, 0.017f, 0.0f); //Proportional(change) Integral(change) Derivative -// Serial.print("P Gain: "); -// Serial.println((float)pid1.getPgain()); -// Serial.print("I Gain: "); -// Serial.println((float)pid1.getIgain()); -// Serial.print("D Gain: "); -// Serial.println((float)pid1.getDgain(), 7); -// Serial.println(""); -// -// encoder1.resetCounter(0); -// Serial.print("encoder1: "); -// Serial.println(encoder1.getRawCount()); -// target = 1000; -// pid1.setSetpoint(TARGET_POSITION, target); + P = 0.07f;//0.07 //0.2 + I = 0.0f; + D = 0.007f; - /************* PID 2 ***********************/ + /************* PID 1 ***********************/ - pid2.setControlMode(CL_POSITION); + pid1.setControlMode(CL_POSITION); //pid1.resetGains(); //pid1.setLimits(-100,100); - pid2.setGains(0.1f, 0.0f, 0.0f); //Proportional(change) Integral(change) Derivative + pid1.setGains(P, I, D); //Proportional(change) Integral(change) Derivative Serial.print("P Gain: "); - Serial.println((float)pid2.getPgain()); + Serial.println((float)pid1.getPgain()); Serial.print("I Gain: "); - Serial.println((float)pid2.getIgain()); + Serial.println((float)pid1.getIgain()); Serial.print("D Gain: "); - Serial.println((float)pid2.getDgain(), 7); + Serial.println((float)pid1.getDgain(), 7); Serial.println(""); - encoder2.resetCounter(0); - Serial.print("encoder2: "); - Serial.println(encoder2.getRawCount()); - target = 1000; - pid2.setSetpoint(TARGET_POSITION, target); + encoder1.resetCounter(0); + Serial.print("encoder1: "); + Serial.println(encoder1.getRawCount()); + target = 5000; + pid1.setSetpoint(TARGET_POSITION, target); + + /************* PID 2 ***********************/ + + // pid2.setControlMode(CL_POSITION); + // + // //pid1.resetGains(); + // //pid1.setLimits(-100,100); + // pid2.setGains(P, I, D); //Proportional(change) Integral(change) Derivative + // Serial.print("P Gain: "); + // Serial.println((float)pid2.getPgain()); + // Serial.print("I Gain: "); + // Serial.println((float)pid2.getIgain()); + // Serial.print("D Gain: "); + // Serial.println((float)pid2.getDgain(), 7); + // Serial.println(""); + // + // encoder2.resetCounter(0); + // Serial.print("encoder2: "); + // Serial.println(encoder2.getRawCount()); + // target = 1000; + // pid2.setSetpoint(TARGET_POSITION, target); } @@ -96,32 +102,29 @@ void loop() { /************* PID 1 ***********************/ -// Serial.print("encoder1: "); -// Serial.print(encoder1.getRawCount()); -// Serial.print(" target: "); -// Serial.println(target); -// if (encoder1.getRawCount() == target) { -// target += 1000; -// Serial.print("Target reached: Setting new target.."); -// pid1.setSetpoint(TARGET_POSITION, target); -// //delay(5000); -// } - - /************* PID 2 ***********************/ - - Serial.print("encoder2: "); - Serial.print(encoder2.getRawCount()); + Serial.print("encoder1: "); + Serial.print(encoder1.getRawCount()); Serial.print(" target: "); Serial.println(target); - if (encoder2.getRawCount() == target) { + if (encoder1.getRawCount() == target) { target += 1000; Serial.print("Target reached: Setting new target.."); - pid2.setSetpoint(TARGET_POSITION, target); + pid1.setSetpoint(TARGET_POSITION, target); //delay(5000); } - //--------------------------------------- - controller.ping(); - //wait + /************* PID 2 ***********************/ + + // Serial.print("encoder2: "); + // Serial.print(encoder2.getRawCount()); + // Serial.print(" target: "); + // Serial.println(target); + // if (encoder2.getRawCount() == target) { + // target += 1000; + // Serial.print("Target reached: Setting new target.."); + // pid2.setSetpoint(TARGET_POSITION, target); + // //delay(5000); + // } + delay(50); -} +} \ No newline at end of file diff --git a/examples/Nano/ServoTest/ServoTest.ino b/examples/Nano/ServoTest/ServoTest.ino index caf21fc..88e0ec2 100644 --- a/examples/Nano/ServoTest/ServoTest.ino +++ b/examples/Nano/ServoTest/ServoTest.ino @@ -1,7 +1,5 @@ -#include + #include -//#include -//#include #define INTERRUPT_PIN 6 @@ -32,10 +30,6 @@ void setup() M2.setDuty(0); M3.setDuty(0); M4.setDuty(0); - - if (!PMIC.enableBoostMode()) { - Serial.println("Error enabling Boost Mode"); - } } void loop() { @@ -43,14 +37,14 @@ void loop() { //Servo sweep from 0 position to 180 for (int i = 0; i < 180; i += 1) { - //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + //Set angle to each specific servo motor servo1.setAngle(i); servo2.setAngle(i); servo3.setAngle(i); servo4.setAngle(i); Serial.print("Servos position"); Serial.println(i); - delay(20); + delay(100); } delay(200); @@ -58,20 +52,15 @@ void loop() { //Servo sweep from 180 position to 0 for (int i = 180; i > 0; i -= 1) { - //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + //Set angle to each specific servo motor servo1.setAngle(i); servo2.setAngle(i); servo3.setAngle(i); servo4.setAngle(i); Serial.print("Servos position: "); Serial.println(i); - delay(20); + delay(100); } - - //Keep active the communication between MKR board & MKR Motor Carrier - //Ping the SAMD11 - controller.ping(); - //wait - delay(50); + delay(200); }