View Single Post
  #8   Spotlight this post!  
Unread 01-25-2014, 07:59 PM
vigneshv vigneshv is offline
Registered User
FRC #2489
 
Join Date: Jan 2014
Location: United States
Posts: 53
vigneshv is on a distinguished road
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);
Reply With Quote