Pages: [1]   Go Down
Author Topic: Greater than but less than statement - PID sketch  (Read 988 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

 I'm working with a PID sketch and I want to setup trigger points for different PID settings depending on how far the input is from the setpoint.
The original code for this section looks like this and it works fine...

Code:
double gap = abs(Setpoint-Input); //distance away from setpoint
  if(gap<10)
  {  //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
     //we're far from setpoint, use aggressive tuning parameters
     myPID.SetTunings(aggKp, aggKi, aggKd);
  }

However, I want finer control so I came up with this, but it does not work.
Quote
Cabinet.cpp: In function 'void loop()':
Cabinet:109: error: expected primary-expression before '<' token
Cabinet:113: error: expected primary-expression before '<' token

Code:
if(gap <= .5){
    seedHTxch.SetTunings(UconsKp, UconsKi, UconsKd);
    }
 
    if(gap > .5 && < 1){
    seedHTxch.SetTunings(consKp, consKi, consKd);
    }
 
    if(gap >= 1 && < 2)
    {
    seedHTxch.SetTunings(aggKp, aggKi, aggKd);
    }
   
    if(gap >= 2)
    {
    seedHTxch.SetTunings(UaggKp, UaggKi, UaggKd);
    }

I've tried all I can think of and used the reference guide to try and find the proper commands but nothing I can come up with works.

Please help

Thanks!
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

gap > 1.0 && gap < 0.5


You need two comparisons...
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 364
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(gap > .5 && < 1)   // this is incomplete

if(gap > .5 && gap < 1)      // this is probably what you wanted

if (.5 < gap && gap < 1)     // this is how I'd do it only because that shows gap between the two values

You've repeated this little error.
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 361
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (.5 < gap && gap < 1)     // this is how I'd do it only because that shows gap between the two values

+1 !!!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks so much!
Logged

Pages: [1]   Go Up
Jump to: