Go to Post I can tell you for a fact that students don't need smartphones in order to unproductively entertain themselves in a robotics lab. - remulasce [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 10-01-2010, 17:03
Zrob Zrob is offline
Registered User
FRC #1631
 
Join Date: Sep 2008
Location: Henderson
Posts: 5
Zrob is an unknown quantity at this point
Programming Mecanum

Hi. Im new to the programming jig, but I'm planning to use Java to program the robot. Our team is going to use mecanum wheels this year, but I don't really know how to program that. Any advice/tips/etc?
Reply With Quote
  #2   Spotlight this post!  
Unread 10-01-2010, 23:49
ericarseneau ericarseneau is offline
Registered User
no team
 
Join Date: Jan 2010
Location: San Diego
Posts: 30
ericarseneau is an unknown quantity at this point
Re: Programming Mecanum

I dont know what mecanum wheels are, however you will likely connect the motors to the speed controls, the Jaguars, or to some digital or analog output. If you use Jaguars then there is a class that handles the Jaguars (Victors) as well. There is control for the analog and digital out, although I dont know what they are as I am not as familiar with WPILib.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-01-2010, 06:25
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Programming Mecanum

Check out the holonomicDrive method of edu.wpi.first.wpilibj.RobotDrive. Holonomic Drive is just another name for the class of omnidirectional drives that work by vector addition (mecanum and quad-omnis).

--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
  #4   Spotlight this post!  
Unread 11-01-2010, 10:53
gaby1367 gaby1367 is offline
Driver (Ret.)
AKA: Pablo
FRC #0714
Team Role: Mentor
 
Join Date: May 2007
Rookie Year: 2004
Location: New Jersey
Posts: 16
gaby1367 is an unknown quantity at this point
Re: Programming Mecanum

if you are new go with LABview because dragging boxes and conecting wires is easier than typing code and having to worry about syntax
Reply With Quote
  #5   Spotlight this post!  
Unread 11-01-2010, 19:48
Zrob Zrob is offline
Registered User
FRC #1631
 
Join Date: Sep 2008
Location: Henderson
Posts: 5
Zrob is an unknown quantity at this point
Re: Programming Mecanum

Wait, Ryan, could you give me a sample of what that would look like?

And gaby, I programmed our bot last year, attempting Labview, but ended up going with Windriver.
Reply With Quote
  #6   Spotlight this post!  
Unread 12-01-2010, 02:50
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Programming Mecanum

I actually haven't programmed FRC in Java before, but using the information available at http://first.wpi.edu/FRC/frcjava.html, this is what I'd guess. Follow the instructions in the getting started guide to set up a basic robot project, the code they give you in the guide looks like this:

Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
public class RobotTemplate extends SimpleRobot {
    RobotDrive drive = new RobotDrive(1, 2);
    Joystick leftStick = new Joystick(1);
    Joystick rightStick = new Joystick(2);
    public void autonomous() {
        for (int i = 0; i < 4; i++) {
            drive.drive(0.5, 0.0); // drive 50% fwd 0% turn
            Timer.delay(2.0); // wait 2 seconds
            drive.drive(0.0, 0.75); // drive 0% fwd, 75% turn
            }
        drive.drive(0.0, 0.0); // drive 0% forward, 0% turn}    }
        }
    public void operatorControl() {
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick, rightStick); // drive with joysticks
            Timer.delay(0.005);
        }
    }
}
This sets up the robot for a standard differential ("tank") drive. To switch to holonomic drive, refer to the WPIlibJ Javadocs (all of these links are available from that WPI Java resource page [first link]) for the Robot Drive class: Right now, they're constructing the RobotDrive object with two parameters which specify the PWM ports that the left and right motors are connected to. Since you have 4 motors, you should use the
Code:
RobotDrive(int frontLeftMotor, int rearLeftMotor, int frontRightMotor, int rearRightMotor)
constructor instead. Once you have this, you can switch from the drive() and tankDrive() methods to the holonomicDrive() method. You will need to actually use the methods of the Joystick class to get numeric values for the joystick axes, as the holonomicDrive method expects doubles. I would guess that your teleop would look something like this:

Code:
public void operatorControl() {
    while (true && isOperatorControl() && isEnabled()) // loop until change
    {
        drive.holonomicDrive(leftStick.getDirectionDegrees(), leftStick.getMagnitude(), rightStick.getX(GenericHID.Hand.kRight)); // drive with joysticks
        Timer.delay(0.005);
    }
}
Or if your joystick has a twist/Z axis, you can replace rightStick.getX with leftStick.getTwist()

Code is untested, so may require some adjustment.

--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
  #7   Spotlight this post!  
Unread 12-01-2010, 15:30
Zrob Zrob is offline
Registered User
FRC #1631
 
Join Date: Sep 2008
Location: Henderson
Posts: 5
Zrob is an unknown quantity at this point
Re: Programming Mecanum

Alright, got it. Just what I needed. Thanks!
Reply With Quote
  #8   Spotlight this post!  
Unread 16-01-2010, 17:55
Todd's Avatar
Todd Todd is offline
Software Engineer
FRC #1071 (Team Max)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Connecticut, Wolcott
Posts: 51
Todd is just really niceTodd is just really niceTodd is just really niceTodd is just really niceTodd is just really nice
Re: Programming Mecanum

Has this worked out for you?
Our team hasn't tried it yet because the drive base is still being assembled, and we're coding in Labview but I'm pretty sure that the holonomic drive code vi uses the same algorithm as the java RobotDrive holonomicDrive function.

I was curious because I was under the impression that some of the mathematics of mecanum wheels were different from omni wheels, which I believe are what the stock algorithm was designed for.
Reply With Quote
  #9   Spotlight this post!  
Unread 16-01-2010, 19:38
Kahn! Kahn! is offline
Registered User
FRC #1379
 
Join Date: Sep 2008
Location: Norcross, GA
Posts: 22
Kahn! is an unknown quantity at this point
Re: Programming Mecanum

Quote:
Originally Posted by Todd View Post
Has this worked out for you?
Our team hasn't tried it yet because the drive base is still being assembled, and we're coding in Labview but I'm pretty sure that the holonomic drive code vi uses the same algorithm as the java RobotDrive holonomicDrive function.

I was curious because I was under the impression that some of the mathematics of mecanum wheels were different from omni wheels, which I believe are what the stock algorithm was designed for.
I'm interested in the answer to this question as we have also gotten some conflicting information on the topic.
Reply With Quote
  #10   Spotlight this post!  
Unread 17-01-2010, 00:48
Steve_Alaniz Steve_Alaniz is offline
Registered User
FRC #2848 (All Sparks)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 1997
Location: Dallas
Posts: 211
Steve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond repute
Re: Programming Mecanum

Not sure I understand where this thread is. I have the coding for mechanums in C and it would have to be translated to Labview or Java or used as C in Labview. But not sure if its needed.

Steve
Reply With Quote
  #11   Spotlight this post!  
Unread 17-01-2010, 12:41
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Programming Mecanum

Here is the code that our team uses for mechanum (in C, but easily portable)-

Code:
velocity = (p1_y - 127); //Joystick 1 y
rotation = (p1_x - 127); //Joystick 1 x
strafe = (p2_x - 127); // Joystick 2 x

wFL = velocity - rotation - strafe; //Front Left wheel, etc...
wFR = velocity + rotation + strafe;
wRL = velocity - rotation + strafe;
wRR = velocity + rotation - strafe;

pwm01 = wFL + 127;
pwm02 = 127 - wFR;
pwm03 = wRL + 127;
pwm04 = 127 - wRR;
__________________
Team 2052- Knightkrawler
Mentor and volunteer
Reply With Quote
  #12   Spotlight this post!  
Unread 17-01-2010, 20:43
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Programming Mecanum

Quote:
Originally Posted by Todd View Post
I was curious because I was under the impression that some of the mathematics of mecanum wheels were different from omni wheels, which I believe are what the stock algorithm was designed for.
The ambiguously named holonomic drive method in C++, LabVIEW, and Java was designed for use with mecanum wheels, not omni wheels.
Reply With Quote
  #13   Spotlight this post!  
Unread 18-01-2010, 14:00
Daniel Jones Daniel Jones is offline
Registered User
AKA: Hanes
FRC #0190 (Gompei and the HERD)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Shrewsbury MA
Posts: 13
Daniel Jones is on a distinguished road
Re: Programming Mecanum

The holonomic drive function will work with either mecanum or with a 4-wheel omni drive if the wheels are oriented 90 degrees from eachother, arranged like this:
/\
\/
It will not work with kiwi drive.
__________________
"there are 10 types of people in this world, those who understand binary and those who don't"
Reply With Quote
  #14   Spotlight this post!  
Unread 22-01-2010, 09:21
aziobro aziobro is offline
Registered User
FRC #4475 (Terrier Byte Bots)
Team Role: Leadership
 
Join Date: Nov 2008
Rookie Year: 2009
Location: Newark,NJ
Posts: 7
aziobro will become famous soon enough
Re: Programming Mecanum

We tried the above code almost exactly.
It apears to work, but the left-right control of the joystick is inverted. Same with the rotation.

What is the best way to flip to readings from the joystick?

We are currently using the method to get the magitude and direction from the joystick.
Reply With Quote
  #15   Spotlight this post!  
Unread 22-01-2010, 10:56
Todd's Avatar
Todd Todd is offline
Software Engineer
FRC #1071 (Team Max)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Connecticut, Wolcott
Posts: 51
Todd is just really niceTodd is just really niceTodd is just really niceTodd is just really niceTodd is just really nice
Re: Programming Mecanum

I'm not sure in the Java library but in labview direction is departure from 0 degrees forward. Negating your direction should flip it's left/right movement.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mecanum Programming Help Mars Programming 8 27-02-2008 15:41
Bizarre Mecanum Programming Bug manderson5192 Programming 10 08-02-2008 22:11
Mecanum drivetrain programming problems Mr. Freeman Programming 4 21-03-2007 17:11
mecanum programming mrmummert Programming 27 28-01-2007 13:45
programming motors with programming kit BorisTheBlade FIRST Tech Challenge 4 01-11-2005 19:03


All times are GMT -5. The time now is 10:41.

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