|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a PIDController with the PIDSource as an encoder and the PIDOutput as a Jaguar. Even though the PIDController->GetError() returns a value of 100 (the encoder distance value - setpoint (this is correct)), the Jaguars do not run automatically to minimize the error. Why is this happening? |
|
#2
|
||||||
|
||||||
|
Re: PIDController not manipulating jaguars
What values did you use for P, I, and D? Did you enable the PID Controller?
|
|
#3
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
P = 13, I = 13, D = 13, PID was enabled.
|
|
#4
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
Are there any flashing or solid lights on the Jaguar? is it a black jag or a grey one? Do you notice the same behavior using BDC-COM?
|
|
#5
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
The Jaguar is a grey Jaguar, and the Jaguar just has a solid orange light. I cannot use Set() to manipulate it either.
|
|
#6
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
Are you using CAN or PWM for the Jaguar. If CAN, the gray Jaguars do not have an RS232 to CAN interface and can not be the first Jaguar in a chain. You should check it by using PC with BDC-COM and a serial cable to a black Jaguar and daisy chain CAN to the gray one. You might as well flash the firmware while you have it hooked up.
|
|
#7
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
Quote:
Posting your code will help us better help you. |
|
#8
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
We also get a PID output with a value between 1 and -1, but the Jaguar does not move. The Jaguar is connected to the PWM output port 1.
Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick *stick; // only joystick
DriverStationLCD *screen;
Encoder *encoder1;
Jaguar *motor1;
PIDController *PIDmotor1;
public:
RobotDemo():
myRobot(1, 2)//, // these must be initialized in the same order
{
stick = new Joystick(1);
screen = DriverStationLCD::GetInstance();
encoder1 = new Encoder(13,14);
motor1 = new Jaguar(1);
PIDmotor1 = new PIDController(0.5,0,0,encoder1,motor1);
PIDmotor1->SetContinuous(true);
PIDmotor1->SetOutputRange(-1,1);
PIDmotor1->SetTolerance(3);
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous()
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(-0.5, 0.0); // drive forwards half speed
Wait(2.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
}
void OperatorControl()
{
myRobot.SetSafetyEnabled(true);
encoder1->Start();
PIDmotor1->SetSetpoint(0);
while (IsOperatorControl())
{
if(stick->GetRawButton(3))
{
PIDmotor1->SetSetpoint(100);
}
if(stick->GetRawButton(2))
{
PIDmotor1->SetSetpoint(-100);
}
if(stick->GetRawButton(4))
{
PIDmotor1->Enable();
}
screen->PrintfLine(DriverStationLCD::kUser_Line1, "Count = %d", encoder1->GetRaw());
screen->PrintfLine(DriverStationLCD::kUser_Line2, "Error = %f", PIDmotor1->GetError());
screen->PrintfLine(DriverStationLCD::kUser_Line3, "Setpoint = %f", PIDmotor1->GetSetpoint());
screen->PrintfLine(DriverStationLCD::kUser_Line4, "Output = %f", PIDmotor1->Get());
//myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
screen->UpdateLCD();
Wait(0.005); // wait for a motor update time
}
}
/**
* Runs during test mode
*/
void Test() {
}
};
START_ROBOT_CLASS(RobotDemo);
|
|
#9
|
||||||
|
||||||
|
Re: PIDController not manipulating jaguars
Both the Jaguar and the RobotDrive are using PWM 1.
|
|
#10
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
So if we remove the RobotDrive, it will work?
|
|
#11
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
So if we remove the RobotDrive, it will work, because as I understand RobotDrive uses the Jag ports as well?
|
|
#12
|
|||||
|
|||||
|
Re: PIDController not manipulating jaguars
Put your PID-controlled Jaguar on a PWM port that isn't already being used by other code. It's a one-character change to your code, and a single connector to move from one set of pins to another.
Code:
motor1 = new Jaguar(3); |
|
#13
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
Isn't the RobotDrive supposed to use the jaguar ports, or should I remove that entirely and control the robot with motor1->Set()?
|
|
#14
|
|||||
|
|||||
|
Re: PIDController not manipulating jaguars
The questions you're asking seem to be assuming something that you haven't told us. Can you explain exactly what you're trying to get the robot to do? What sort of mechanism are you controlling, and where do you have the encoder mouted? I get the feeling that what you want is something you haven't quite made clear to us.
|
|
#15
|
|||
|
|||
|
Re: PIDController not manipulating jaguars
Hi,
I am trying to use the PID controller to keep the robot stationary while shooting. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|