Go Down

Topic: Processing Front-End for the PID Library (Read 17 times) previous topic - next topic

Xbee

Well, I have a strange problem.

I can't get any output from my pid-controller even if i change my PID constants i.e. tuning. Here is what i am doing.

double MagStartPositionY = 375;
double MagReadingsInts[3];
double YawServoOffset = 0;

//Yaw PID control
#define Input MagReadingsInts[1]  
#define Output   YawServoOffset
#define SetPoint MagStartPositionY


double P_Param = 0.5;   //0.004
double I_Param = 0.01;  //0.009
double D_Param = 0;     //0.3

PID YawPID(&MagReadingsInts[1], &YawServoOffset, &MagStartPositionY, P_Param, I_Param, D_Param);

void setup()
{
//Some Code//
YawPID.SetOutputLimits(0,30); // I want output to be a number from                0-30
YawPID.SetMode(AUTO); //turn on the PID
}

void loop()
{

// Code to receive data is correct
...................

//
YawPID.compute();
Serial.print("Output : ");Serial.println(Output);
delay(2000);

}

My input is the serial Magnetometer data. I move my magnetometer to  change the input and want to see how output changes. But strangely output always remain zero.

I tried putting YawPID.SetTunings(P_K,I_K,D_K); and changing the input, output and setpoint definitions to double but all in vain.

Can anybody figure out what is the problem?

Thanks!

zer0vector

#26
Jul 09, 2010, 01:27 am Last Edit: Jul 09, 2010, 01:36 pm by zer0vector Reason: 1
Hi there,

I am attempting to get the frontend working for the PID library and I've hit something of a snag.  I am getting the following error when I run the program in Processing:

Code: [Select]
error, disabling serialEvent() for /dev/ttyUSB0
java.lang.reflect.InvocationTargetException
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:616)
     at processing.serial.Serial.serialEvent(Unknown Source)
     at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
     at gnu.io.RXTXPort.eventLoop(Native Method)
     at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
     at PID_FrontEnd_v02.serialEvent(PID_FrontEnd_v02.java:436)
     ... 8 more


The graphical display comes up but no data is passed to or received from the arduino.  Nothing comes up on the graph or in the data fields to the left.

I was able to eliminate the error by removing the setValue() and setText() commands in serialEvent().  If I comment out those lines, like this:

Code: [Select]
//take the string the arduino sends us and parse it
void serialEvent(Serial myPort)
{
 
 String read = myPort.readStringUntil(10);
 if(outputFileName!="") output.print(str(millis())+ " "+read);
 String[] s = split(read, " ");
 if (s.length ==8)
 {
   Setpoint = float(s[1]);           // * pull the information
   Input = float(s[2]);              //   we need out of the
   Output = float(s[3]);             //   string and put it
   //SPLabel.setValue(s[1]);           //   where it's needed
   //InLabel.setValue(s[2]);           //
   //OutLabel.setValue(trim(s[3]));    //
   //PLabel.setValue(trim(s[4]));      //
   //ILabel.setValue(trim(s[5]));      //
   //DLabel.setValue(trim(s[6]));      //
   //AMCurrent.setValue(trim(s[7]));   //

   if(justSent)                      // * if this is the first read
   {                                 //   since we sent values to
     //SPField.setText(trim(s[1]));    //   the arduino,  take the
     //InField.setText(trim(s[2]));    //   current values and put
     //OutField.setText(trim(s[3]));   //   them into the input fields
     //PField.setText(trim(s[4]));     //
     //IField.setText(trim(s[5]));     //
     //DField.setText(trim(s[6]));     //
     mode = trim(s[7]);              //
     //AMLabel.setValue(mode);         //
     justSent=false;                 //
   }                               //

   if(!madeContact) madeContact=true;
 }
}


Again, the graphical window comes up, but some data starts coming from the arduino (the led starts blinking), and it begins drawing the setpoint, input, and output lines.  The data fields to the left do not show anything.  However, I can change the setpoint, "Send to Arduino" and the green line will reflect the change.

I've read around a bit about this error, but I still don't understand what's going on.  

Do you have any thoughts?

BTW I'm running on Ubuntu, if that makes any difference.

EDIT:  I just tried this on a windows laptop and it worked with no errors.  It must be specific to Linux or Ubuntu versions of processing.

EDIT2: This thread is the closest I've come to a similar error, but its from 2007, and they don't have a solution:

http://processing.org/discourse/yabb2/YaBB.pl?num=1183525352

eecharlie

Brett,

This GUI has been awesome for playing with the PID library more productively. I am now trying to record some data sets and run them through some system ID code in Matlab so I can do model-based gain selection. (And then I can use it to control the temperature of my mash for homebrewing =)

I am finding that when I give an output file name to the frontend code, it creates an empty file but never writes anything to it. I was able to fix the problem by adding output.flush() immediately after the output.println(). Is there a way to cleanly close the frontend? I didn't see an output.close() or any other wrap-up stuff, so I'm wondering if anyone has been using the write to file feature.

Thanks!

br3ttb

Quote
I'm wondering if anyone has been using the write to file feature.


in all honesty I threw that in there to do what you are doing, but it's been a while since I've used it.  since then there's been a new version of processing, a new windows OS, and a few tweaks to the code.

the not-closing-cleanly thing is something I just plain missed.
Brett

eecharlie

Cool. If you're going through that code anytime soon, another recommendation I'd have is matching the specific string "PID" before trying to parse a line of serial data - I've run into trouble where other debugging strings I've printed happen to have 8 space-separated strings and confuse the frontend.

Go Up