View unanswered posts | View active topics It is currently Mon May 21, 2018 10:30 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Problem with functions
Author Message
Rookie

Joined: Tue Jun 18, 2013 4:54 pm
Posts: 2
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

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

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
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
Rookie

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

Tue Jun 18, 2013 5:33 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning