Go to Post Your students are my idols. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 31 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 27-01-2012, 16:25
l0stboy l0stboy is offline
Registered User
FRC #4064 (InZombiacs)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: United States
Posts: 22
l0stboy is an unknown quantity at this point
Help Setting Up PID System for Tank Drive Train

My team is making 4 motor drive train that has two on each side with a jaguar attached to each motor. I have a basic understanding of the CommandBase structure included in the library, but I'm not sure what I would use for the pid loop when it comes to values, constants, and to do with returnPIDInput(). I'm not entirely sure what sort of input the jaguars can have, and that's the source of my problem. I keep seeing that they have built in encoders? Here's my code so far. I hope that once I figure out how to use PID here I'll be able to use a similar format to control our "arm."



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates.subsystems;

import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.templates.RobotMap;

/**
*
* @author l0stboy
*/
public class DriveTrain extends PIDSubsystem {

private static final double Kp = 0.0;
private static final double Ki = 0.0;
private static final double Kd = 0.0;


//declare objects

RobotDrive zombieDrive;




// Initialize your subsystem here
public DriveTrain() {
super("DriveTrains", Kp, Ki, Kd);

// Use these to get going:
// setSetpoint() - Sets where the PID controller should move the system
// to
// enable() - Enables the PID controller.
zombieDrive = new RobotDrive(RobotMap.leftBackMotor, RobotMap.leftFrontMotor,
RobotMap.rightBackMotor, RobotMap.rightFrontMotor);

}

public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());d
setDefaultCommnad(JoystickDrive);
}

protected double returnPIDInput() {
// Return your input value for the PID loop
// e.g. a sensor, like a potentiometer:
// yourPot.getAverageVoltage() / kYourMaxVoltage;
return zombieDrive.get;
}

protected void usePIDOutput(double output) {
// Use output to drive your system, like a motor
// e.g. yourMotor.set(output);
}
}
__________________

Pedro
Ocala InZombiacs

Last edited by l0stboy : 27-01-2012 at 16:37.
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2012, 17:59
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Help Setting Up PID System for Tank Drive Train

Quote:
Originally Posted by l0stboy View Post
I keep seeing that they have built in encoders
An encoder is a sensor that must be mounted on/near the device whose rotary speed/position it is sensing. So no, there is no encoder built-in to the Jag.

The Jag does have a built-in encoder interface however, to receive a signal from an encoder.

And the Jag also has a microcontroller with firmware which which can use the encoder signal as an input to a PID algorithm in the firmware.

Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2012, 19:49
l0stboy l0stboy is offline
Registered User
FRC #4064 (InZombiacs)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: United States
Posts: 22
l0stboy is an unknown quantity at this point
Re: Help Setting Up PID System for Tank Drive Train

That makes sense. Would there be link anywhere for some sample code of that?
__________________

Pedro
Ocala InZombiacs
Reply With Quote
  #4   Spotlight this post!  
Unread 27-01-2012, 19:52
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Help Setting Up PID System for Tank Drive Train

Quote:
Originally Posted by l0stboy View Post
That makes sense. Would there be link anywhere for some sample code of that?
I don't have the FRC Java installed here. I'll let a Java guru answer that.

You must use CAN bus (instead of PWM) to control the Jags if you want to use their built-in PID.

Depending on what you want to accomplish with the encoders, you may be better off connecting them to the cRIO rather than the Jag, and run your controller in the cRIO (either home-brew or the PID in WPILib library).


Last edited by Ether : 27-01-2012 at 19:56.
Reply With Quote
  #5   Spotlight this post!  
Unread 28-01-2012, 03:25
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 591
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Help Setting Up PID System for Tank Drive Train

Quote:
Originally Posted by l0stboy View Post
That makes sense. Would there be link anywhere for some sample code of that?
If you look at the GearsBot sample program included with the Netbeans install it should serve as an example. There are a few differences, it uses an ultrasonic rangefinder to drive its PID loop. And it uses 2 motors.

You can modify the RobotDrive constructor to take all 4 of your motors. one you do that, the rest will be unchanged.

And you only need to use a PID subsystem if you intend to use encoders. If you aren't installing encoders change the PIDSubsystem to a Subsystem and remove all the methods and code that pertain to the PID loop stuff (returnPIDInput and usePIDOutput).

If you do have encoders, then instead of using rangefinder.getVoltage() as the feedback element, you'll read the encoder value and use that. The PID constants (Kp, Ki, and Kd) will have to be adjusted to account for the range of values the encoders will return. And the set point will be in the same units that the encoder is returning, such as encoder count that represents the distance you need to drive.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #6   Spotlight this post!  
Unread 28-01-2012, 15:04
mbushroe mbushroe is offline
Registered User
FRC #2840
 
Join Date: Jan 2009
Location: Phoenix
Posts: 16
mbushroe is an unknown quantity at this point
Re: Help Setting Up PID System for Tank Drive Train

Ether,

how about a code sample to connect the cRIO to the internal PID of the Jaguar? The WindRiver user's guide has no text in the serial interface section, and nothing for digital control of a Jaguar. Also, is there code for the SmartDashboard to monitor and control the PID parameters and monitor the speed and drive voltage outputs? We would like to use the internal Jaguar PID, but have not yet found a way to control it through the robot.

Mike


Quote:
Originally Posted by Ether View Post
I don't have the FRC Java installed here. I'll let a Java guru answer that.

You must use CAN bus (instead of PWM) to control the Jags if you want to use their built-in PID.
Reply With Quote
  #7   Spotlight this post!  
Unread 28-01-2012, 15:54
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Help Setting Up PID System for Tank Drive Train

Quote:
Originally Posted by mbushroe View Post
Ether,

how about a code sample to connect the cRIO to the internal PID of the Jaguar?
I'm not a Java programmer so I can't give you authoritative advice in this area.

According to Page 32 of this document, the Jaguar class of the WPILib library supports CAN on the Jaguar. As I mentioned in the earlier post in this thread, I don't have access to an FRC Java installation so I can't confirm whether this class supports the serial-to-CAN interface.

According to the C++ WPILib reference from 2011, there's a CANJaguar class which might have what you need (assuming there's an equivalent class in Java).


Last edited by Ether : 28-01-2012 at 16:10.
Reply With Quote
  #8   Spotlight this post!  
Unread 28-01-2012, 19:17
rrossbach rrossbach is offline
Registered User
AKA: Ron R
FRC #2607 (RoboVikings)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Warrington PA
Posts: 90
rrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to behold
Re: Help Setting Up PID System for Tank Drive Train

Quote:
Originally Posted by mbushroe View Post
how about a code sample to connect the cRIO to the internal PID of the Jaguar? ... We would like to use the internal Jaguar PID, but have not yet found a way to control it through the robot.
You can look at our team's 2011 code for an example if you like - it's available at http://code.google.com/p/robovikings-2607/. In particular look at the LogomotionDriveTrain class.

Basically, in robotInit() you would do something similar to this:
Code:
public void robotInit() {
   try {
      m = new CANJaguar(2);    // change 2 to match the CAN id of the Jag
      m.changeControlMode(CANJaguar.ControlMode.kSpeed);
      m.setSpeedReference(CANJaguar.SpeedReference.kEncoder);
      m.configEncoderCodesPerRev(240);  // change 240 to match your encoder
      m.setPID(.350, .004, .001);  // change gains to whatever you need based on tuning
      m.enableControl();
   } catch (Exception e) {
       ...
   }
}
Then in the autonomous or teleop methods use the m.setX() to set the speed you want the motor to run at.

Quote:
Originally Posted by Ether View Post
... I don't have access to an FRC Java installation so I can't confirm whether this class supports the serial-to-CAN interface.
The WPILib classes for CAN support in Java and C++ (and Labview for that matter) are all independent of the type of CAN interface used (serial or 2CAN). The actual comms are handled via the "plugin" (BlackJag plugin for serial, or 2CAN plugin for the 2CAN) and the WPILib routines communicate through those plugins.

Hope this helps!

- Ron
Team #2607 controls mentor
__________________

FIRST Mid-Atlantic Volunteer
FRC Team #2607 Mentor
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 21:05.

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