Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   PIDController not manipulating jaguars (http://www.chiefdelphi.com/forums/showthread.php?t=125225)

vigneshv 01-25-2014 03:02 PM

PIDController not manipulating jaguars
 
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?

Joe Ross 01-25-2014 04:30 PM

Re: PIDController not manipulating jaguars
 
What values did you use for P, I, and D? Did you enable the PID Controller?

vigneshv 01-25-2014 05:41 PM

Re: PIDController not manipulating jaguars
 
P = 13, I = 13, D = 13, PID was enabled.

NotInControl 01-25-2014 05:59 PM

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?

vigneshv 01-25-2014 06:52 PM

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.

gpetilli 01-25-2014 07:12 PM

Re: PIDController not manipulating jaguars
 
Quote:

Originally Posted by vigneshv (Post 1332295)
The Jaguar is a grey Jaguar, and the Jaguar just has a solid orange light. I cannot use Set() to manipulate it either.

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.

NotInControl 01-25-2014 07:40 PM

Re: PIDController not manipulating jaguars
 
Quote:

Originally Posted by vigneshv (Post 1332295)
The Jaguar is a grey Jaguar, and the Jaguar just has a solid orange light. I cannot use Set() to manipulate it either.

Can you paste your code? Because the light is solid that means that the jaguar is correctly gettting power and receiving comms. It may be a programming problem, maybe the wrong motor controller is referenced.

Posting your code will help us better help you.

vigneshv 01-25-2014 07:59 PM

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);


Joe Ross 01-25-2014 08:09 PM

Re: PIDController not manipulating jaguars
 
Both the Jaguar and the RobotDrive are using PWM 1.

vigneshv 01-25-2014 08:35 PM

Re: PIDController not manipulating jaguars
 
So if we remove the RobotDrive, it will work?

vigneshv 01-25-2014 08:36 PM

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?

Alan Anderson 01-26-2014 01:08 PM

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);

vigneshv 01-26-2014 03:32 PM

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()?

Alan Anderson 01-26-2014 09:38 PM

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.

vigneshv 01-27-2014 09:14 AM

Re: PIDController not manipulating jaguars
 
Hi,
I am trying to use the PID controller to keep the robot stationary while shooting.


All times are GMT -5. The time now is 09:27 AM.

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