View Single Post
  #6   Spotlight this post!  
Unread 01-12-2010, 02:50 AM
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 688
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