View unanswered posts | View active topics It is currently Fri Jul 25, 2014 5:37 pm






Reply to topic  [ 4 posts ] 
Problem with functions 
Author Message
Rookie

Joined: Tue Jun 18, 2013 4:54 pm
Posts: 2
Post Problem with functions
Hi everybody,
I have a little question about function's. First, I will explain quickly what I want to do :-) .
So Im doing a kind of Industrial robot with PF XL Motor's + Glidewheel from Mindsensors.com and the regulation is not like I want. So I have done my own PID function and desactivated the orignial PID (open loop). This function return the power of the motor in float.

Until here, everything works fine. The problem starts when I use this function inside another function, it returns this : -1.#Q0
I cannot find information about this error...

Thank you in advance for your help.

Mike

edit: this problem is the "MotPowerA" variable
Code:
#pragma config(Motor,  motorA,          axis1,         tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorB,          axis2,         tmotorNXT, openLoop, reversed, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
float const GearRatio=pow((56),-1);
int const GearRatio2=(56);
float ValEncA;
float MotPowerA;
bool PosReached;

float PIDMotA(float ConsignA ,float ValCodA)
{
   float  Kp, Ki, Kd, Prop, Inte, Deri, OldErr, ErrDiff;
   float PowMotA;
   Kp=3;
   Ki=0;
   Kd=30;
  OldErr=ErrDiff;
  ErrDiff=ConsignA-ValCodA;
  Prop=ErrDiff;
  Inte=Inte+ErrDiff;
  Deri=ErrDiff-OldErr;
  PowMotA=(Kp*Prop)+(Ki*Inte)+(Kd*Deri);
  return PowMotA; //return motor power
}

void moveJ(float Aj, float Bj)
{
   while (!PosReached)
   {
      Aj*=GearRatio2;
      MotPowerA=PIDMotA(Aj,nMotorEncoder[axis1]);
      wait1Msec(10);
      motor[axis1]=MotPowerA;
      if (MotPowerA<10&MotPowerA>-10)
      {
         motor[axis1]=0; //Position reached
         PosReached=true;
      }
   }
   PosReached=false;
   return;
}

task main()
{
   moveJ(0,0);
   wait1Msec(2000);
   moveJ(45,0);
   wait1Msec(2000);
   moveJ(0,0);
   wait1Msec(2000);
}


Last edited by TheProphet on Tue Jun 18, 2013 6:19 pm, edited 3 times in total.



Tue Jun 18, 2013 5:09 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: Problem with functions
Perhaps if you supplied us with the code, we could take a look but right now the cause of this is anyone's guess. My vote is: planetary alignment or solar flares.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jun 18, 2013 5:20 pm
Profile WWW
Rookie

Joined: Tue Jun 18, 2013 4:54 pm
Posts: 2
Post Re: Problem with functions
Sorry, I have edited now


Tue Jun 18, 2013 5:33 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: Problem with functions
First of all, your Inte variable is constantly reinitialised, instead of maintaining its value, which is kind of the point of the I part in a PID regulator. If you make it either global or a "static" type in your function, it will not lose its value each time the function is called.
Second, your ErrDiff value is assigned to OldDiff, but it wasn't assigned a value prior to that, so there's nothing to assign. Do the same thing with OldDiff as you should do with the Inte variable, make it a static variable.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jun 19, 2013 1:13 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.