View unanswered posts | View active topics It is currently Tue Feb 09, 2016 6:09 am

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
PID problems
Author Message
Rookie

Joined: Thu Jun 20, 2013 4:56 pm
Posts: 19
PID problems
Hi Jason,

I've got a wandering robot when trying to do a PID line follow on the Obstacle Course.

It follows the line (very very slowly!) staying within +- 5 of the threshold.

Problems start when the robot almost completes the first turn and the compass reads about 138. The error gets really big and the robot begins to wobble and not move forward any more. I suspect it is shooting over the line and freaking out with the maths.

The robot is going slowly because I thought slow would be more accurate, but the same thing happens when power is big (say 25 or 35).

Any ideas?

Cheers

Leslie

while (nMotorEncoder[leftMotor]<4000)
{
float turn;
float targetPower=10;
float error;
float kp=1;
float powerRight;
float powerLeft;
int threshold=50;

error=threshold-SensorValue(light);
turn = kp * error;
powerRight= targetPower + turn;
powerLeft= targetPower - turn;

motor[leftMotor]=powerLeft;
motor[rightMotor]=powerRight;
}

Mon Jul 08, 2013 5:21 pm
Senior Roboticist

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Re: PID problems
This is not a PID algorithm, it is simply a P algorithm. That is, you only have the P value. It's directly proportional. The problem with this, is that it can get very "freaked out" as you put it and just wobble back and forth. PID is really not needed in VW, but I can give you some sample code if you want true PID. Because, as I said, this is just using the P parameter.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.

Mon Jul 08, 2013 5:36 pm
Rookie

Joined: Thu Jun 20, 2013 4:56 pm
Posts: 19
Re: PID problems
Hello again.

Thanks for getting back to me so quickly. I've just had a look at the class from 01 July, and seen the part on the I and the D. I'll give it a whirl.

Cheers

Leslie

Mon Jul 08, 2013 5:50 pm

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Re: PID problems
Hi Leslie,
The other thing you could try is bounding the control signal:

 Code:error=threshold-SensorValue(light);turn = kp * error;if (turn > targetPower)  turn = targetPower;else if (turn < -targetPower)  turn = -targetPower;powerRight= targetPower + turn;powerLeft= targetPower - turn;

As you've noticed, if the error becomes too large, then your forward movement command can essentially become a point turn. By limiting the magnitude of turn to be no more than targetPower, the robot will only ever do swing turns. You may need to tune the bounds to get the best behavior.

Cheers,
--Ryan

_________________
Ryan Cahoon
RVW Software Developer

Mon Jul 08, 2013 6:02 pm
Rookie

Joined: Thu Jun 20, 2013 4:56 pm
Posts: 19
Re: PID problems
Hi Guys,

It's still wigging out at about the same place, even with programming out the errors that get too large.

Any suggestions?

Many thanks in advance for having a look.

Leslie

 Code:while (nMotorEncoder[leftMotor]<4000)   {      float turn;      float targetPower=30;      float error;      float kp=1.5;      float powerRight;      float powerLeft;      int threshold=45;      error=threshold-SensorValue(light);      turn = kp * error;      powerRight= targetPower + turn;      powerLeft= targetPower - turn;      if (powerRight<10)      {         powerRight=-15;      }      if (powerRight>70)      {         powerRight=50;      }      if (powerLeft<10)      {         powerLeft=-10;      }      if (powerLeft>80)      {         powerLeft=70;      }            motor[leftMotor]=powerLeft;      motor[rightMotor]=powerRight;   }

Mon Jul 08, 2013 6:11 pm

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Re: PID problems
Hi Leslie,
Usually when coding bounds you have the value in the if-comparison and the value set in the if-block as the same, so your code would be something like:

 Code:      if (powerRight<10)      {         powerRight=10;      }      if (powerRight>70)      {         powerRight=70;      }      if (powerLeft<10)      {         powerLeft=10;      }      if (powerLeft>70)      {         powerLeft=70;      }

otherwise your power values will jump around in weird ways. That aside, I just tried running the code from your original post on the Obstacle Course virtual world, and it worked fine for me for the entire length of the line. One thing that comes to mind is if the virtual world is running slowly, the sensor value may not be updating very often. Can you load one of the utility tables and check what framerate you're getting while your program is running? It's displayed on the utility tables in the bottom right corner of the screen in white text, so it might be easier to read on one of the tables with a surface that isn't white.

Thanks,
--Ryan

_________________
Ryan Cahoon
RVW Software Developer

Mon Jul 08, 2013 6:33 pm
Rookie

Joined: Thu Jun 20, 2013 4:56 pm
Posts: 19
Re: PID problems
Hey Ryan,

Thanks for checking my code. That's great news that it works on your system.

I looked at the fps rate and it's mostly hovering in the 90s with dips down to 47 and sometimes up to 118. What do you reckon it is supposed to be? Is it meant to be this volatile? I am working on a laptop with display of Mobile Intel 4 Series with 1300 MB graphics memory and 32 of video (this hardware stuff is not my forte!).

Leslie

Tue Jul 09, 2013 4:52 am

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Re: PID problems
Hi Leslie,
Those numbers sound high enough. The framerate will fluctuate to a certain degree; it is marginally possible this could be the source of the problems, but I doubt it.

Something I should have checked initially: which versions of ROBOTC and Curriculum Companion are you using? The latest is 3.61 for ROBOTC and 2.4.0 for Curriculum Companion. If you're not using the latest, can you upgrade and see if that helps?

Thanks,
--Ryan

_________________
Ryan Cahoon
RVW Software Developer

Last edited by rcahoon on Wed Jul 10, 2013 5:20 pm, edited 1 time in total.

Wed Jul 10, 2013 5:02 pm
Rookie

Joined: Thu Jun 20, 2013 4:56 pm
Posts: 19
Re: PID problems
Hi Ryan,

Thanks for getting back to me about my PID issue.

My gear is fully updated. I think I will take it on the nose and move on now and out the whi,e thing down to a gena, weirdness. I enjoyed learning about the PID, and if it runs on your system, then fab,

Cheers,

Leslie

Wed Jul 10, 2013 5:18 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 9 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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    2014 Robotics Academy Summer of Learning    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