Go to Post There are times when we talk as friends and joke around about things like this, but then the most important times are when he says "I'm telling you this as a mentor," no matter what it is, those moments mean a lot. - Akash Rastogi [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Spotlight this post!  
Unread 27-01-2016, 14:39
techkid86's Avatar
techkid86 techkid86 is offline
Magic Programer
FRC #3044 (0xBE4)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: ballston spa
Posts: 58
techkid86 is an unknown quantity at this point
Arrow Re: Drive train PID control

More or less yes. So you're using talons. PWM I assume? if so, the following code should be enough to set up your drive.

using only basic classes:
Code:
Talon leftDrive=new Talon(1);
Talon rightDrive=new Talon(2);

//if using gamepad
Joystick gamepad=new Joystick(1);

//if using two individual joysticks
Joystick leftJoy=new Joystick(1);
Joystick leftJoy=new Joystick(2);

Encoder leftEncoder=new Encoder(1,2);
Encoder rightEncoder=new Encoder(1,2);

PIDController leftPID=new PIDController(0.1,0,0, leftEncoder, leftDrive);
PIDController rightPID=new PIDController(0.1,0,0, rightEncoder, rightDrive);

public void robotInit()
{
leftEncoder.setPIDSourceType(PIDSourceType.kDisplacement); rightEncoder.setPIDSourceType(PIDSourceType.kDisplacement); rightEncoder.setReverseDirection(true); rightDrive.setInverted(true); //only one side needs inversion leftEncoder.reset(); rightEncoder.reset(); leftPID.setOutputRange(-0.75,0.75); //max speed it can set to motors rightPID.setOutputRange(-0.75,0.75); //max speed it can set to motors leftPID.enable(); rightPID.enable();
} public void autonomousPeriodic() {
leftPID.setSetpoint(400); rightPID.setSetpoint(400); //set distance. you can change distance per tick through the encoder
} public void teleopInit() {
leftPID.disable(); rightPID.disable();
} public void teleopPeriodic() {
//for two joysticks leftDrive.set(leftJoy.getY()); rightDrive.set(rightJoy.getY()); //for one gamepad leftDrive.set(gamepad.getRawAxis(1)); rightDrive.set(gamepad.getRawAxis(2)); //replace 1 and 2 axis with actual axis number.
}
__________________
"you can build a perfect machine out of imperfect parts" -Urza

Last edited by techkid86 : 27-01-2016 at 14:51.
Reply With Quote
 


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 10:19.

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