Go to Post The future is a dark and mysterious place, and trying to force our current methods on that are patently absurd. - Taylor [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: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 29-09-2014, 11:53
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Mecanum Wheels & Encoders -- Java code

Hello all,

I am from team 4687, and I am having some trouble coding the encoders for a mecanum wheel robot. I currently have some code developed to read the encoder values, but I am unsure of how to change the speeds of the wheels based off of these values. Here is what I would like to do:
I would like to use 1 wheel and call it the master wheel. This wheel will provide me with an encoder value. This encoder value will then be used to "enslave" the other wheels, which will then match the master wheel's rpm. The only differences in the wheels will happen when I change the direction of the wheels to move in the directions I need them to move in.

If you guys have any other way to implement some encoder code into a mecanum wheel drive to get all the wheels to move the same speed all the time, it would be great if you could advise me on that too. I will leave you all with my current code, with encoders implemented but doing nothing.

Thank you all in advance for your help in this project.


Code:
//I do my brackets differently than most
//import statements
public class RobotTemplate extends SimpleRobot
{
RobotDrive drive =- new RobotDrive(1,2,3,4);
Joystick joystick = new Joystick(1);
Encoder wheelOne = new Encoder(8,7);
Encoder wheelTwo = new Encoder(4,3);
Encoder wheelThree = new Encoder(6,5);
Encoder wheelFour = new Encoder (2,1);

     public void OperatorControl()
     {
          while(true && isOperatorControl() && isEnabled())
          {
          drive.mecanumDrive_Cartesian(joystick.getX(), joystick.getY(), -1*joystick.getTwist(), 0);
          Timer.delay(0.001);
          int one = wheelOne.get();
          int two = wheelTwo.get();
          int three = wheelThree.get();
          int four = wheelFour.get();
          }
     }
}
Reply With Quote
  #2   Spotlight this post!  
Unread 29-09-2014, 12:44
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by aweso_meme View Post
I would like to use 1 wheel and call it the master wheel. This wheel will provide me with an encoder value. This encoder value will then be used to "enslave" the other wheels, which will then match the master wheel's rpm.
Your post is confusing.

What is the point of having mecanum wheels if you are going to spin them all at the same speed?

Quote:
The only differences in the wheels will happen when I change the direction of the wheels to move in the directions I need them to move in.
? You don't change the direction of a mecanum wheel to achieve rotation and strafe. You change its speed.


Reply With Quote
  #3   Spotlight this post!  
Unread 29-09-2014, 13:02
Jon Stratis's Avatar
Jon Stratis Jon Stratis is online now
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,827
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Mecanum Wheels & Encoders -- Java code

Feel free to send my team an email (2177 (at) therobettes.com)... we've been doing work with encoders for a while now, and are actually right now working on using them for feedback in a swerve drive robot (at our last meeting, we had just gotten everything set up to find our PID constants for the speed encoders, and we should be working on finding them this week). You're a little outside the cities, but if you wanted to come over to our space we could spend some time going over what we know and how it all works.

Feedback loops are a fairly complicated subject, and in my experience don't transfer well over a forum. Look at the PIDController object and google a white paper "PID Without a PhD" to get started, and we're certainly willing to help!
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #4   Spotlight this post!  
Unread 29-09-2014, 13:05
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Re: Mecanum Wheels & Encoders -- Java code

If I am driving a mecanum wheel drive with all wheels at the same speed, I can change the direction each wheel is spinning relative to the front to achieve each individual result.
If I spin all 4 wheels forward relative to the front, the robot will move forward.
If I spin the front-left and the back-right motors forward relative to the front, and the front-right and back-left motors backwards relative to the front, the chassis will slide to the left.
If I spin the front-left and back-left wheels backwards relative to the front, and the front-right and back-right wheels forwards relative to the front, I will get a Counter Clockwise turn.
Reply With Quote
  #5   Spotlight this post!  
Unread 29-09-2014, 13:19
Jon Stratis's Avatar
Jon Stratis Jon Stratis is online now
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,827
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Mecanum Wheels & Encoders -- Java code

That's true... but trust me, you're going to want control in between those extremes in motion. For example, what about turning while strafing? It's the whole idea of being able to move around a stationary object while always facing it. Trust me, it's easier to go for complete control from the start than it is to implement the extremes then try to jury-rig in everything in between.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #6   Spotlight this post!  
Unread 29-09-2014, 13:19
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by aweso_meme View Post
If I spin the front-left and the back-right motors forward relative to the front, and the front-right and back-left motors backwards relative to the front, the chassis will slide to the left.
No. It will slide to the right.


Quote:
Originally Posted by aweso_meme View Post
If I spin the front-left and back-left wheels backwards relative to the front, and the front-right and back-right wheels forwards relative to the front, I will get a Counter Clockwise turn.
If all 4 wheel speeds are the same, you will get rotate-in-place (spin)

Now, what do you do when you want to go forward and turn at the same time?



Last edited by Ether : 29-09-2014 at 14:08.
Reply With Quote
  #7   Spotlight this post!  
Unread 29-09-2014, 14:28
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Re: Mecanum Wheels & Encoders -- Java code

Even if I did want to be able to modify the speeds of the wheels, one of the problems we are having is that the wheels are spinning at different speeds even if we are only trying to go in one direction. Example: Each time we move forward, the wheels are misaligned so that the robot curves significantly. Do you guys have some code to fix this?
Reply With Quote
  #8   Spotlight this post!  
Unread 29-09-2014, 14:35
Jon Stratis's Avatar
Jon Stratis Jon Stratis is online now
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,827
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Mecanum Wheels & Encoders -- Java code

Yes, the encoders help fix that. Look at the PIDController class and the white paper I mentioned - they will help you to understand feedback loops and how to get started with them, although be forewarned - they can be difficult to figure out! Spend some time going through all that and then please contact my team (address already given) - we're happy to help out! We've been giving the Java presentation at MN Splash for years now, are an Alpha/Beta team for the new control system, have been playing around with PID loops since 2008, and we really aren't that far away from you guys. Trust me - if you want the robot to go straight, my students know how to make that happen.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #9   Spotlight this post!  
Unread 29-09-2014, 14:40
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by aweso_meme View Post
Example: Each time we move forward, the wheels are misaligned so that the robot curves significantly. Do you guys have some code to fix this?
First order of business is to fix all mechanical design and craftsmanship problems.

Put the bot up on blocks and power each wheel one at a time in the forward direction at various command levels. Are some wheels noticeably slower or faster than others? Take notes.

Then repeat the test except spin the wheels in the reverse direction.

Tell us what you find.



Reply With Quote
  #10   Spotlight this post!  
Unread 29-09-2014, 14:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by aweso_meme View Post
Even if I did want to be able to modify the speeds of the wheels
With all four wheels being commanded to have the same speed (albeit in different directions), you'll have a robot whose steering cannot be controlled while moving. Is that your aspiration?


Reply With Quote
  #11   Spotlight this post!  
Unread 29-09-2014, 15:11
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Re: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by Ether View Post
With all four wheels being commanded to have the same speed (albeit in different directions), you'll have a robot whose steering cannot be controlled while moving. Is that your aspiration?


At this point in time, that is our aspiration. I am the only one who knows how to program the robot on our team, and I simply do not have the time right now to put into learning about PID. I will learn about that for competition, but right now we are doing some out of competition practice. I have been having trouble with setting up the encoders and the master/slave wheels. Do you guys have some kind of set-up for that?
Reply With Quote
  #12   Spotlight this post!  
Unread 29-09-2014, 15:29
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Mecanum Wheels & Encoders -- Java code


I highly recommend you forego the master/slave all-wheel-speeds-the-same approach you are describing and do the following instead:

1) fix the mechanical issues first. see my earlier post.

2) forget the PID and encoder for now. instead, program the wheel speeds properly using either the WPILib RobotDrive class or home-brew code described here. This will give the driver full control of steering and strafing.

3) Once you've got that working, there's a good chance you won't need PID at all.


Reply With Quote
  #13   Spotlight this post!  
Unread 30-09-2014, 21:57
seg9585's Avatar
seg9585 seg9585 is offline
Registered User
AKA: Eric
FRC #4276 (Surf City Vikings)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2001
Location: Boeing (Seal Beach, CA)
Posts: 520
seg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond repute
Re: Mecanum Wheels & Encoders -- Java code

Quote:
Originally Posted by aweso_meme View Post
At this point in time, that is our aspiration. I am the only one who knows how to program the robot on our team, and I simply do not have the time right now to put into learning about PID. I will learn about that for competition, but right now we are doing some out of competition practice. I have been having trouble with setting up the encoders and the master/slave wheels. Do you guys have some kind of set-up for that?
No one here has been very helpful yet with OP's original project goals, so I'll chime in here. I see exactly what what you want to do, so here's what I suggest:

First, learn how the mecanum drive classes actually map joystick inputs to individual motor powers and generate an equation describing them. Stick with linear control and it should be relatively simple to interpolate.

For example, look at the constraints first:

When JoyY1 = 1 and JoyX = 0, all four motors output "1" (for purposes of this exercise, reverse polarity on the opposing wheels due to gearbox orientation)

When JoyY1 = -1 and JoyX = 0, all four motors output "-1"
When JoyY1 = 0 and JoyX = 1, Front outputs "1" and rear outputs "-1"
When JoyY1 = 0 and JoyX = -1, Rear outputs "-1" and front output "1"
When JoyY1 = 1 and JoyX = 1, Front outputs "1" and rear outputs "0"
...
etc etc

Anyway, map the entire region on an XY plane and you can see how the X input and Y input varies each motor power. Note that they are dependent.

Now, in your code you can record the X and Y input values, and calculate the "expected" motor output powers. Use your reference encoder to relate power vs rpm (say, 100 rpm = 0.7 power output) and calculate a "control" constant (although this could be a function and not a constant -- determine this by testing at different powers). C = 100/0.7 (or whatever units you want).

For the rest of the wheels, read in encoder values and calculate new power ratios based on how different each wheel's power correlates to their rpm.
100 rpm / C = output power.
If "output power" is exactly 0.7 here as well, the wheel speeds are equal. But since they're not due to friction or other reasons, you will need to generate new constants for each wheel.
100 rpm / C = 0.7 * constant

that constant will be close to 1 -- maybe 0.95 if that particular wheel has less friction, 1.05 if it has more.
Anyway, take this constant and bias the mecanum drive output: motor1.set(motor1_output*constant);

That way, in the case where JoyY = 1 and JoyX = 0 (for example), Motor1 = 1 but Motor2 = 0.95, thus keeping the robot driving straight.

Last thing -- you'd have to determine the "worst-case" motor, the one that performs the worst for a given output power, and use that as your limiting output power. Otherwise the less powerful wheel will saturate (above calc will be >1) and the power will truncate to 1. So all the constants to 3 motors should be <1, and the least effective motor is exactly 1.
__________________
My FIRST legacy:

Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)
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 13:03.

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