Go Down

Topic: PID does not sense negative values. (Read 1 time) previous topic - next topic

dvl12

Hello. I am trying to set up a system of Servomotor and a combo board (gyro + accelerometers). I am using PID and the setups is such: setpoint is zero degrees, input is angle from the combo board and output is Amplitude of rotation of servo arm on my servo. I made it work, but it only works when incline the combo board in one direction and gives positive angles. however, when incline the other way and it gives negative angles PID does not do anything. Is there any solution to that?

Magician

Looks as extract from encrypt comms in CERN, something related to Large Hadron Collider  8)

dvl12


Magician


dvl12

I am working on a project, which involves PID controller, Arduino, IMU combo board (gyro + accelerometer) and a servomotor. The aim is to keep IMU horizontal at zero degrees, when it inclines amplitude of oscillation of a servo arm on my servomotor increases and when IMU is back in horizontal position amplitude is zero. I set my PID as such: Input = angles from IMU, Output = Amplitude, Setpoint = 0 degrees. It works fine in one direction when angles from IMU are positive, however, in the other direction when angles are negative PID does not respond. Could anyone help me to find a solution for that problem?

Here is a code to make it easier to understand:
Code: [Select]
#include <PID_v1.h>

#include <FreeSixIMU.h>
#include <FIMU_ADXL345.h>
#include <FIMU_ITG3200.h>

#include <Wire.h>


double Setpoint, Input, Output;
PID myPID(&Input, &Output, &Setpoint,2,5,1, REVERSE);

int Ampl = 0;

float angles[3]; // yaw pitch roll

// Set the FreeSixIMU object
FreeSixIMU sixDOF = FreeSixIMU();

void setup() {
  Serial.begin(9600);
  Wire.begin();
 
  Input = angles[2];
  Setpoint = 0.00;
  myPID.SetMode(AUTOMATIC);
 
  delay(5);
  sixDOF.init(); //begin the IMU
  delay(5);
}

void loop() {
 
  sixDOF.getEuler(angles);

  Input = angles[2]; 
  myPID.Compute();
  myPID.SetOutputLimits(0, 180);
  Ampl = Output;
 
 
  Serial.print(angles[0]);
  Serial.print(" | "); 
  Serial.print(angles[1]);
  Serial.print(" | ");
  Serial.print(angles[2]);
  Serial.print(" | ");
  Serial.println(Ampl);
 
  delay(100);
}

Go Up