Go to Post Off-topic: THIS IS THE REASON WHY I LOVE FIRST! - FlyingD662 [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-05-2011, 07:53
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
PIDController Rotate

I am trying to use a PIDController to rotate the robot to a certain angle using a gyro, but I cannot figure out what to set the PIDOutput parameter to in the constructor. Any ideas?
Reply With Quote
  #2   Spotlight this post!  
Unread 27-05-2011, 08:14
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate


The PID output is the voltage command to the motor being controlled.

Make sure create proper setpoint and processVariable inputs to the PID, for example like so:

angle_error = joystick_command - gyro_angle;
angle_error -= 360*floor(0.5+angle_error/360);
setpoint = gyro_angle + angle_error;
processVariable=0;

See discussion here.




Last edited by Ether : 27-05-2011 at 08:18.
Reply With Quote
  #3   Spotlight this post!  
Unread 27-05-2011, 08:17
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

I know what the PIDOutput does, but I can't figure out what to use for it since I can't just use a variable, I have to put in a Controller of some sort. I'm thinking maybe I just need to write a class that implements PIDOutput and read the value out of it to use for the rotation value.
Reply With Quote
  #4   Spotlight this post!  
Unread 27-05-2011, 08:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate




Isn't there any example code in the FRC Framework C++ WindRiver installation?

Have you looked at the C++ WPI Library source code for help?




Last edited by Ether : 27-05-2011 at 08:28.
Reply With Quote
  #5   Spotlight this post!  
Unread 27-05-2011, 08:29
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

I'm doing it in Java. Hence, the Java thread :-P
Reply With Quote
  #6   Spotlight this post!  
Unread 27-05-2011, 08:45
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate

Quote:
Originally Posted by notmattlythgoe View Post
I'm doing it in Java. Hence, the Java thread :-P
My bad. Wasn't paying attention. :-(


Reply With Quote
  #7   Spotlight this post!  
Unread 27-05-2011, 08:51
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

No problem Here is the code I have so far if anybody has any suggestions. The way PIDController works is it creates a thread and does the PID calculations and takes care of the input and output for you. But what do I set the output to to cause the robot to rotate? My guess is create a class that implements PIDOutput and do the rotation code myself. If anybody else knows a better way please inform me.

PIDController turn = new PIDController(DRIVE_P, DRIVE_I, DRIVE_D, gyro,?);
turn.setTolerance(0.05);
turn.setSetpoint(angle);
turn.setContinuous();
turn.enable();
Reply With Quote
  #8   Spotlight this post!  
Unread 27-05-2011, 08:56
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate

Quote:
Originally Posted by notmattlythgoe View Post
But what do I set the output to to cause the robot to rotate? My guess is create a class that implements PIDOutput and do the rotation code myself. If anybody else knows a better way please inform me.
What kind of drivetrain do you have? Is it skid-steer, or omni, or mecanum, or perhaps swerve? And, what it your driver interface? 3-axis joystick, 2 2 axis joysticks, etc ?


Reply With Quote
  #9   Spotlight this post!  
Unread 27-05-2011, 08:57
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

Mecanum with a 3-axis joystick.
Reply With Quote
  #10   Spotlight this post!  
Unread 27-05-2011, 09:03
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate

Quote:
Originally Posted by notmattlythgoe View Post
Mecanum with a 3-axis joystick.
Did you write your own mecanum code to calculate the wheel speeds from the driver inputs, or are you using the provided WPI library function for that?


Reply With Quote
  #11   Spotlight this post!  
Unread 27-05-2011, 09:04
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

public void turn(double speed, int angle)
{
PIDRotate rotate = new PIDRotate();
PIDController turn = new PIDController(DRIVE_P, DRIVE_I, DRIVE_D, gyro, rotate);
turn.setTolerance(0.05);
turn.setSetpoint(angle);
turn.setContinuous();
turn.enable();

while(!turn.onTarget())
{
drive(0.0, rotate.getValue());
}
turn.disable();
}


Here is what I have now. This is the method that completes a turn. Below is the PIDRotate class that gets the PID value written to it.

public class PIDRotate implements PIDOutput
{
private double value;

public PIDRotate()
{
value = 0.00;
}

public void pidWrite(double output)
{
value = output;
}

public double getValue()
{
return value;
}
}
Reply With Quote
  #12   Spotlight this post!  
Unread 27-05-2011, 09:39
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate


The inverse kinematic calculations for mecanum require three input rate commands (forward/reverse, right/left, clockwise/counterclockwise) in order to compute the required 4 wheel speeds.


When the driver is controlling robot orientation open-loop, these three rate commands come from the driver.


If you want to use the gyro to go to and hold the robot orientation at some desired angle, then the rotation rate command for the inverse kinematic calculations must come from the output of the PID, rather than from the driver.


There are a few different ways to do this.


One way would be for the driver to open-loop rotate the vehicle to the desired orientation, and when it is oriented the way he wants it, he presses a joystick button to "lock in" that angle. By "lock in", I mean that the software reads and saves that angle from the gyro and uses that as the target value for the PID. The software then changes modes and uses the PID output, instead of the driver, to provide the rotation command (to be feed into the inverse kinematic calculation of wheel speeds). This holds the robot at that angular orientation. When the driver wants to change the robot's orientation, he presses another button to release it and give control back to him.


Another way is to program the buttons so that the driver has a small set of discrete robot orientations he can access with one button press. For example, one button for forward, one for 90 degrees to the right, one for 90 degrees to the left (and one to release control back to the driver). The target values for these buttons are hard-coded to the fixed discrete positions to which they correspond.


I suppose another way to do it would be to provide some sort of separate non-spring-loaded rotary device, like a potentiometer or encoder, for the driver to turn to the desired robot orientation angle. The angle from this device would become the target value for the PID. This could be the full-time mode of operation (replacing the joystick rotation z-axis) or a joystick button could be used to toggle between the two modes of control.


You could even just use the joystick z-axis as the target value for the PID (and use the PID output as the rotation rate input to the inverse kinematic calculations), but it seems to me this would be very awkward for the driver, because he would have to hold the twist at the desired angle.


Because of gyro drift, when using the gyro you might also want to provide a button that tells the software to re-zero the gyro at the present orientation. This allows the driver to manually orient the robot at the zero orientation and then press the button to re-zero the gyro.




Last edited by Ether : 27-05-2011 at 09:57.
Reply With Quote
  #13   Spotlight this post!  
Unread 27-05-2011, 10:03
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

I appreciate all of the help Ether, but I don't think you are understanding what I am asking, and that is probably my fault for not explaining enough. What I am currently doing is working on rewriting our competition code that was done in Labview in Java. One of the programming sub-teams off-season projects this year is going to be learning to use the Java environment by reprogramming our robot from Logomotion. I am doing it myself so that I know how to do it when the students are working on it and can help them when they have questions. The problem that I ran into was that I needed an output that would go straight to a speed controller that would cause the robot to rotate. From what I can tell the PIDController in Java works differently than the ones in C++ and Labview. It works more like the CANJaguar where you give it the value and it does all of the calculations and outputs to the speed controllers for you. I think I have remedied that by writing a PIDOutput class that implements PIDOutput and tells the RobotDrive to rotate instad of telling one specific speed controller to move. I have attached the two code files, but don't quote me on anything because I have not tested it at all.
Attached Files
File Type: txt PIDRotate.txt (640 Bytes, 18 views)
File Type: txt RobotDrive2363.txt (1.8 KB, 9 views)

Last edited by notmattlythgoe : 27-05-2011 at 10:07.
Reply With Quote
  #14   Spotlight this post!  
Unread 27-05-2011, 10:12
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: PIDController Rotate

The problem I really ran into was that there was no way from what I could tell that I could just put the output of the PID into the rotate portion of the drive command because the PIDController does the output automatically. And the output must be a instance of a PIDOutput which are Jaguars, Victors, and CANJaguars.
Reply With Quote
  #15   Spotlight this post!  
Unread 27-05-2011, 11:19
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: PIDController Rotate

Quote:
Originally Posted by notmattlythgoe View Post
The problem I really ran into was that there was no way from what I could tell that I could just put the output of the PID into the rotate portion of the drive command because the PIDController does the output automatically. And the output must be a instance of a PIDOutput which are Jaguars, Victors, and CANJaguars.

Isn't there a generic PID in the WPI library for Java which lets you specify where the output goes? Like the LabVIEW PID ?



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 11:14.

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