OCCRA
Go to Post Ahh! I see that you discovered the "CMD_FLING_RECEIVER_RADIO_ACROSS_ROOM" command in the robot scripting language! Nicely done! - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 06-14-2018, 11:50 AM
IsaacB's Avatar
IsaacB IsaacB is offline
Registered User
FRC #5437 (Rocky Balboabots)
Team Role: Mentor
 
Join Date: Jun 2018
Rookie Year: 2017
Location: Booneville, AR
Posts: 3
IsaacB is an unknown quantity at this point
Help with Swerve Drive programming (Java)

Our team bought the AndyMark Swerve and Steer modules, however our program only causes the swivel motors to spin continuously when a joystick is moved. I am not the "chief" programmer for our team but we would like to get the chassis going in the off season.

We are still using the hall effect encoders on the rear of the motor in stead of the absolute encoder they recommend for it.

Here is a link to our code: https://github.com/FRC5437/2017-Swerve-Code

Thanks for any help!
Reply With Quote
  #2   Spotlight this post!  
Unread 06-14-2018, 12:23 PM
nickbrickmaster nickbrickmaster is offline
Registered User
AKA: Nick Schatz
no team (3184 Alum)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 461
nickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond reputenickbrickmaster has a reputation beyond repute
Re: Help with Swerve Drive programming (Java)

It's probably an issue with your steer control loops. First of all I would double check your in/out polarity- a positive output from the PID controller should reduce a positive error.

Then comes tuning. I would set all your gains (kP, kI, kD) to 0, then start with a small kP and slowly increase it. You also probably want just a PD loop (0 kI) as you want fast rise time with little overshoot.

Last of all an absolute encoder is almost essential for swerve. You'll need either that or a limit switch/hall effect sensor to set zero on your modules. Otherwise your quadrature encoder will only measure changes in angle while the robot is on, and not absolute angle.
__________________
This is a postmodern signature.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-14-2018, 12:50 PM
gerthworm's Avatar
gerthworm gerthworm is offline
Making the 1's and 0's
FRC #1736 (Robot Casserole)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Peoria, IL
Posts: 653
gerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond reputegerthworm has a reputation beyond repute
Re: Help with Swerve Drive programming (Java)

Definitely start with making sure your angles are being read properly by all encoders. Positive/increasing angle should be in the same direction as when the motors are given positive control effort.

A couple "code review" items to look into:

This code handles bad encoders. Do all calls to getAngle() check if -1 is returned and do something appropriate, or is -1 ever used as an actual angle later on?

I believe this code attempts to wrap "angle" to the 0-360 degree range. Is it ever possible to get angle = -370 as input to this function? If so, the wrap logic may not work as expected. I haven't dug deep enough to determine if this is true, just something to double check.

The encoder appears configured to return 0.875 degrees per pulse. Can you confirm this is accurate?

To the absolute encoder logic: What physical state is defined as "0 degrees of module rotation" on the robot? What logic in software (or mechanism in hardware?) guarntees that during at least one point of operation, the robot will know you're in the zero degree state, and reset the encoder readings to 0?

Check the "desired" angles coming in from the controller too. Print out all four angles passed into your swerve modules objects. Are all of these angles reasonable, based on driver inputs?

Same comment as above - once you've verified encoders are reading in the correct direction, try to re-tune. I'd start by setting your I/D gains to zero, P very small. Double P until you get oscillations in steady state. Back it off slowly until the oscillations cease. Then pull in some I to overcome steady state error. Historically, I've avoided D for cases like this. Then again, I've historically been dealing with high-stiction systems with low controllability. YMMV.

You may also want to add logic to prevent integrator windup. Perhaps only "accumulate" your I term when your actual is within a few degrees of setpoint? There's a couple other ways to accomplish this....

Last edited by gerthworm : 06-14-2018 at 12:55 PM.
Reply With Quote
  #4   Spotlight this post!  
Unread 06-28-2018, 01:17 PM
IsaacB's Avatar
IsaacB IsaacB is offline
Registered User
FRC #5437 (Rocky Balboabots)
Team Role: Mentor
 
Join Date: Jun 2018
Rookie Year: 2017
Location: Booneville, AR
Posts: 3
IsaacB is an unknown quantity at this point
Re: Help with Swerve Drive programming (Java)

I went ahead and bought the absolute encoders from AndyMark and the 40 tooth gear. It seems like the encoders are working. They give values between 0 and 359.

The wheels do turn to a degree of rotation, but sometimes they will be over 80 or 90 degrees off. I've tried to PID tune but it seems when I increase the 'I' value the wheels will start to spin out of control. Plus I may not be PID tuning the correct way.


Here's the updated code : https://github.com/isaacbrown60/2018...DriveBase.java
Reply With Quote
  #5   Spotlight this post!  
Unread 06-28-2018, 01:40 PM
Andrew Schreiber Andrew Schreiber is offline
Petitioning the UN to ban Lythgoe
no team
Team Role: Engineer
 
Join Date: Jan 2005
Rookie Year: 2000
Location: Somehow, the entire east coast...
Posts: 4,898
Andrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond repute
Re: Help with Swerve Drive programming (Java)

Quote:
Originally Posted by IsaacB View Post
I went ahead and bought the absolute encoders from AndyMark and the 40 tooth gear. It seems like the encoders are working. They give values between 0 and 359.

The wheels do turn to a degree of rotation, but sometimes they will be over 80 or 90 degrees off. I've tried to PID tune but it seems when I increase the 'I' value the wheels will start to spin out of control. Plus I may not be PID tuning the correct way.


Here's the updated code : https://github.com/isaacbrown60/2018...DriveBase.java


So, I is usually the last thing I touch when tuning. In fact, I usually completely ignore it. In fact, for 323's steering we completely ignored D as well and just used a lot of P. The robot weight and friction will do a decent job damping the system. Or something like that, it worked.

We had a similar issue where the angle seemed to be off by a variable amount, turns out our field centric code was using a different coordinate system than the rest of the bot (CW+ instead of the CCW+ the rest of the system used) so that's definitely somewhere to check as well.

If you're still struggling, have you given John a call?
__________________




.
Reply With Quote
  #6   Spotlight this post!  
Unread 06-29-2018, 01:27 PM
IsaacB's Avatar
IsaacB IsaacB is offline
Registered User
FRC #5437 (Rocky Balboabots)
Team Role: Mentor
 
Join Date: Jun 2018
Rookie Year: 2017
Location: Booneville, AR
Posts: 3
IsaacB is an unknown quantity at this point
Re: Help with Swerve Drive programming (Java)

Thanks for all the help. I finally got it to tune right and I runs fairly good.
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 10:38 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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