Go to Post I in all sincerity thoroughly enjoy the way that programming for FIRST makes me want to bash my head against a wall. - pogenwurst [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-04-2016, 12:31
Dpurry23's Avatar
Dpurry23 Dpurry23 is offline
Programmer/Control System/Scout
AKA: Darian Purry
FRC #0207 (Metalcrafters)
Team Role: Programmer
 
Join Date: Sep 2013
Rookie Year: 2012
Location: Hawthorne
Posts: 13
Dpurry23 is an unknown quantity at this point
Thumbs down NavX: Trying to rotate to angle without PID

Code:
             double turnDegrees = ahrs->GetYaw();
      
             while(codriver.GetRawButton(12) == 1)
             {
            	 if(turnDegrees > -10 && turnDegrees < 10 && centered == FALSE )
            	 {
            		 myRobot.Drive(0.0, 0.0);
            		 centered = TRUE;

            	 }
            	 else if (turnDegrees < -11 && turnDegrees > -180 && centered == FALSE)
            	 {
            		 myRobot.Drive(0.4, 1.0);
            		 centered = FALSE;
            	 }
            	 else if (turnDegrees > 11 && turnDegrees < 180 && centered == FALSE)
            	 {
            		 myRobot.Drive(-0.4, 1.0);
            		 centered = FALSE;
            	 }
             }
This is code I have come up with so far any suggestions would help.
Thank You!!

Last edited by Dpurry23 : 21-04-2016 at 12:47. Reason: Syntax
Reply With Quote
  #2   Spotlight this post!  
Unread 21-04-2016, 12:38
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Captain
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 143
nickbrickmaster is an unknown quantity at this point
Re: NavX: Trying to rotate to angle without PID

What's wrong with it and why don't you want to use PID?
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #3   Spotlight this post!  
Unread 21-04-2016, 12:42
Dpurry23's Avatar
Dpurry23 Dpurry23 is offline
Programmer/Control System/Scout
AKA: Darian Purry
FRC #0207 (Metalcrafters)
Team Role: Programmer
 
Join Date: Sep 2013
Rookie Year: 2012
Location: Hawthorne
Posts: 13
Dpurry23 is an unknown quantity at this point
Re: NavX: Trying to rotate to angle without PID

Nothing, we just cant mount encoders on the drive train or use Talon SRX's to get that feedback.
Reply With Quote
  #4   Spotlight this post!  
Unread 21-04-2016, 12:46
Jaci's Avatar
Jaci Jaci is online now
Registered User
AKA: Jaci R Brunning
FRC #5333 (Can't C# | OpenRIO)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Perth, Western Australia
Posts: 251
Jaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond repute
Re: NavX: Trying to rotate to angle without PID

Quote:
Originally Posted by Dpurry23 View Post
Nothing, we just cant mount encoders on the drive train or use Talon SRX's to get that feedback.
You can do PID without encoders. PID only requires a feedback, the source of which can be any kind of sensor, including a gyroscope. The NavX has an example for this kind of thing here
__________________
Jacinta R

Curtin FRC (5333+5663) : Mentor
5333 : Former [Captain | Programmer | Driver], Now Mentor
OpenRIO : Owner

Website | Twitter | Github
jaci.brunning@gmail.com
Reply With Quote
  #5   Spotlight this post!  
Unread 21-04-2016, 17:49
Dpurry23's Avatar
Dpurry23 Dpurry23 is offline
Programmer/Control System/Scout
AKA: Darian Purry
FRC #0207 (Metalcrafters)
Team Role: Programmer
 
Join Date: Sep 2013
Rookie Year: 2012
Location: Hawthorne
Posts: 13
Dpurry23 is an unknown quantity at this point
Re: NavX: Trying to rotate to angle without PID

When trying to call it in RobotInit it throws an error saying
Quote:
PIDController.h:39:3: note: no known conversion for argument 6 from 'Robot*' to 'PIDOutput*'
PIDController.h:37:3: note: PIDController:IDController(float, float, float, PIDSource*, PIDOutput*, float)
PIDController(float p, float i, float d, PIDSource *source, PIDOutput *output,
^
PIDController.h:37:3: note: candidate expects 6 arguments, 7 provided
This is how I call it
Code:
turnController = new PIDController(kP, kI, kD, kF, ahrs, this, period = .05);
Reply With Quote
  #6   Spotlight this post!  
Unread 21-04-2016, 18:29
dubiousSwain's Avatar
dubiousSwain dubiousSwain is offline
The ride never ends
AKA: Christian Steward
FRC #5420 (Velocity)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2011
Location: USA
Posts: 304
dubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond repute
Re: NavX: Trying to rotate to angle without PID

Quote:
Originally Posted by Dpurry23 View Post
When trying to call it in RobotInit it throws an error saying

This is how I call it
Code:
turnController = new PIDController(kP, kI, kD, kF, ahrs, this, period = .05);
It looks like argument 6 is out of place. You're using "this" in robotinit, which from the error message I assume passes an object of type Robot. I don't think you want that there, considering PIDController is looking for a float. You also have 7 arguments where there should be 6, which makes me think you have an extra argument in there. What is kF? argument 4 should be of type PIDSource.
__________________
2015 MAR District Champions




Reply With Quote
  #7   Spotlight this post!  
Unread 21-04-2016, 22:32
lethc's Avatar
lethc lethc is offline
#gkccurse
AKA: Becker Lethcoe
FRC #1806 (S.W.A.T.)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2013
Location: Smithville, MO
Posts: 118
lethc will become famous soon enough
Re: NavX: Trying to rotate to angle without PID

Quote:
Originally Posted by dubiousSwain View Post
It looks like argument 6 is out of place. You're using "this" in robotinit, which from the error message I assume passes an object of type Robot. I don't think you want that there, considering PIDController is looking for a float. You also have 7 arguments where there should be 6, which makes me think you have an extra argument in there. What is kF? argument 4 should be of type PIDSource.
kF is the optional constructor for the feed forward constant
__________________
2016: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Semifinalists, IRI Quarterfinalists
2015: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Quarterfinalists, IRI Winners
2014: Central Illinois Regional Quarterfinalists, Greater Kansas City Regional Finalists, Newton Semifinalists
2013: Greater Kansas City Regional Winners, Oklahoma Regional Winners, Galileo Quarterfinalists
Reply With Quote
  #8   Spotlight this post!  
Unread 21-04-2016, 22:36
Dpurry23's Avatar
Dpurry23 Dpurry23 is offline
Programmer/Control System/Scout
AKA: Darian Purry
FRC #0207 (Metalcrafters)
Team Role: Programmer
 
Join Date: Sep 2013
Rookie Year: 2012
Location: Hawthorne
Posts: 13
Dpurry23 is an unknown quantity at this point
Re: NavX: Trying to rotate to angle without PID

I pushed the NavX rotate to angle example to my code but now i'm receiving another error. No matter what I put in the PIDOutput space it is coming out as not being able to convert it.

Code:
RobotDrive myRobot;

turnController = new PIDController(kP, kI, kD, ahrs, myRobot);

Last edited by Dpurry23 : 21-04-2016 at 22:51. Reason: Clarification
Reply With Quote
  #9   Spotlight this post!  
Unread 21-04-2016, 22:39
dubiousSwain's Avatar
dubiousSwain dubiousSwain is offline
The ride never ends
AKA: Christian Steward
FRC #5420 (Velocity)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2011
Location: USA
Posts: 304
dubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond repute
Re: NavX: Trying to rotate to angle without PID

Quote:
Originally Posted by lethc View Post
kF is the optional constructor for the feed forward constant
Based on the error message, I would say something is preventing it from overloading properly then.
__________________
2015 MAR District Champions




Reply With Quote
  #10   Spotlight this post!  
Unread 22-04-2016, 12:17
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 337
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: NavX: Trying to rotate to angle without PID

Quote:
Originally Posted by Dpurry23 View Post
I pushed the NavX rotate to angle example to my code but now i'm receiving another error. No matter what I put in the PIDOutput space it is coming out as not being able to convert it.

Code:
RobotDrive myRobot;

turnController = new PIDController(kP, kI, kD, ahrs, myRobot);
Can you post your code, and the error message? Please keep in mind that in order for this to work, myRobot needs to implement the PIDOutput interface, so my best guess is myRobot is an instance of a class which does not implement the PIDOutput interface - but it's hard to tell with only this information.
Reply With Quote
  #11   Spotlight this post!  
Unread 22-04-2016, 12:52
orangelight's Avatar
orangelight orangelight is offline
Registered User
AKA: Alex
FRC #0548 (Robostangs)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Northville
Posts: 165
orangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to behold
Re: NavX: Trying to rotate to angle without PID

I'm pretty sure there is a turn to angle example with the navx
http://www.pdocs.kauailabs.com/navx-mxp/examples/
__________________


Reply With Quote
  #12   Spotlight this post!  
Unread 22-04-2016, 14:01
bobcroucher's Avatar
bobcroucher bobcroucher is offline
Registered User
FRC #2471 (Team Mean Machine)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2008
Location: United States
Posts: 33
bobcroucher has a spectacular aura aboutbobcroucher has a spectacular aura about
Re: NavX: Trying to rotate to angle without PID

You can either create a new tiny class specifically to be used as your PIDOutput class, or you can have your robot class be that class too by using a line like this on your Robot class definition.

Code:
public class Robot extends SampleRobot implements PIDOutput {
Then you need to implement pidWrite() which tells the PID what you want to do with the output.

In your case, copying a line from above I assume you will want this:

Code:
@Override
  /* This function is invoked periodically by the PID Controller, */
  /* based upon navX-MXP yaw angle input and PID Coefficients.    */
  
public void pidWrite(double output) {
      Drive( output, 1.0 );
}
If the error between your setpoint and the gyro angle was 90 degrees or more you would want full 1.0 power, so I would start with a P constant of 1.0 / 90. So 0.01 should be a good starting place.

When you set your gyro up, here are some other suggestions straight from their example:
Code:
      turnController.setInputRange(-180.0f,  180.0f);
      turnController.setOutputRange(-1.0, 1.0);
      turnController.setAbsoluteTolerance(2.0);
      turnController.setContinuous(true);
Last, if you are trying to go to 0, then call

Code:
turnController.setSetpoint( 0.0 );
and to turn the controller on use,

Code:
turnController.enable();
Reply With Quote
  #13   Spotlight this post!  
Unread 22-04-2016, 15:29
Dpurry23's Avatar
Dpurry23 Dpurry23 is offline
Programmer/Control System/Scout
AKA: Darian Purry
FRC #0207 (Metalcrafters)
Team Role: Programmer
 
Join Date: Sep 2013
Rookie Year: 2012
Location: Hawthorne
Posts: 13
Dpurry23 is an unknown quantity at this point
I have since fixed the problem, I needed to add the PIDOutput class in my code.
What I had to put:

Class Robot: public PIDOutput, public Sample Robot
__________________
2016 - Long Beach Regional Engineering Inspiration Award, Ventura Regional Industrial Design Award
2015 - Long Beach Regonal Chairmans Award
2014 - Long Beach Regional Woodie Flowers Finalist Award - Lucas Pacheco, Gracious Professionalism Award
2013 - Long Beach Regional Quality Award
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi