|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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;
}
}
Thank You!! Last edited by Dpurry23 : 21-04-2016 at 12:47. Reason: Syntax |
|
#2
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
What's wrong with it and why don't you want to use PID?
|
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
Quote:
|
|
#5
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
When trying to call it in RobotInit it throws an error saying
Quote:
Code:
turnController = new PIDController(kP, kI, kD, kF, ahrs, this, period = .05); |
|
#6
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
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.
|
|
#7
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
Quote:
|
|
#8
|
||||
|
||||
|
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 |
|
#9
|
||||
|
||||
|
Re: NavX: Trying to rotate to angle without PID
Based on the error message, I would say something is preventing it from overloading properly then.
|
|
#10
|
|||
|
|||
|
Re: NavX: Trying to rotate to angle without PID
Quote:
|
|
#11
|
||||
|
||||
|
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/ |
|
#12
|
||||
|
||||
|
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 {
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 );
}
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);
Code:
turnController.setSetpoint( 0.0 ); Code:
turnController.enable(); |
|
#13
|
||||
|
||||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|