Go to Post Now, everyone knows that Oompaloompas are like bunnies in that they have an insatiable desire to multiply, and the same can be said with Michigan teams (with all due respect) which are currently multiplying and filling that hand-shaped democratic kingdom with their honorable number. - Eugenia Gabrielov [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 11-12-2011, 18:25
TEAM-3871 TEAM-3871 is offline
Registered User
FRC #3871
 
Join Date: Feb 2011
Location: US
Posts: 10
TEAM-3871 is an unknown quantity at this point
Question Help with mecanum Drive!

Hey Andy from Team 3871 here, this year will be our first year using java and we curently are using macanum wheels... just wonder how to program them... dont quit understan the how to state the joystick axis..

PHP Code:
drive.mecanumDrive_Cartesian(leftStick.getDirectionDegrees(), leftStick.getMagnitude(), rightStick.gyroAngle(); 
Am i on the right track, and how do i go about wachdog...
missing something?

Here is everything i have so far...

PHP Code:
package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;

public class 
Team3871Robot extends SimpleRobot {
    
    
RobotDrive drive = new RobotDrive (12);
    
Joystick leftStick = new Joystick(1);
    
Joystick rightStick = new Joystick(2);
    
    public 
void autonomous() {
     
    }
       public 
void operatorControl() {
        while (
isOperatorControl() && isEnabled())
        {
            
drive.mecanumDrive_Cartesian(leftStick.getDirectionDegrees(), leftStick.getMagnitude(), rightStick.gyroAngle(); 
        }
        
Timer.delay(0.005);
    }

Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 11-12-2011, 19:32
Kovs's Avatar
Kovs Kovs is offline
Registered User
FRC #1259 (Paradigm Shift)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Pewaukee, Wisconsin
Posts: 19
Kovs will become famous soon enough
Re: Help with mecanum Drive!

Here is a java Doc for RobotDrive.
Specifically, I would recommend looking at:
  • The constructors
  • mecanumDrive_Cartesian(double x, double y, double rotation, double gyroAngle)
  • mecanumDrive_Polar(double magnitude, double direction, double rotation)
  • setInvertedMotor(RobotDrive.MotorType motor, boolean isInverted)
And here is one for the Joystick class
Specifically, I would look at
  • getX()
  • getY()

I haven't coded mecanum, but I think you need 4 motors assigned to your RobotDrive instead of 2.

Also, try using the "search" button up top Where I found this similar thread
Reply With Quote
  #3   Spotlight this post!  
Unread 12-12-2011, 10:31
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: Help with mecanum Drive!

Here are some sections of code from FRC 623's mecanum drive from 2011.

First, as mentioned above you need 4 motors for mecanum. Additionally, 623 used a three axis joy stick: x, y, and twist.

The following class implements a "low pass" filter on the joystick inputs (reduces sensitivity) and transforms x, y, and twist to magnitude, direction, and rotation required by the mecanumDrive_Polar method.

Code:
public class JoystickFRC623Drive extends Joystick
{
    // number of samples for averaging
    private static final int FILTER_SAMPLE_SIZE = 5;

    public double getCurrentAngle()
    {
        synchronized (this)
        {
            return currentAngle;
        }
    }

    public double getCurrentMagnitude()
    {
        synchronized (this)
        {
        return currentMagnitude;
        }
    }

    public double getCurrentTwist()
    {
        synchronized (this)
        {
        return currentTwist;
        }
    }
    
    int position;
    double [] xValues;
    double [] yValues;
    double [] twistValues;

    double currentMagnitude;
    double currentAngle;
    double currentTwist;

    // override to allow implementation of filtering
    public JoystickFRC623Drive( int port )
    {
        super(port);
        position = 0;
        xValues = new double [FILTER_SAMPLE_SIZE];
        yValues = new double [FILTER_SAMPLE_SIZE];
        twistValues = new double [FILTER_SAMPLE_SIZE];
        for(int i=0; i<FILTER_SAMPLE_SIZE; i++) {xValues[i]=0; yValues[i]=0; twistValues[i]=0;}

    }

    public void teleopInit()
    {
        // danny you may want to reset the arrays to zero here --steven
        for(int i=0; i<FILTER_SAMPLE_SIZE; i++) {xValues[i]=0; yValues[i]=0; twistValues[i]=0;}
        // call when teleop starts
    }

    public void teleopPeriodic()
    {
        // called each time new driver station data is available


        xValues[position] = super.getAxis(AxisType.kX);
        yValues[position] = super.getAxis(AxisType.kY);
        twistValues[position] = super.getAxis(AxisType.kTwist);
        position++;
        if (position>=FILTER_SAMPLE_SIZE) position = 0;

        double averageX = averageArray(xValues);
        double averageY = averageArray(yValues);
        double averageTwist = averageArray(twistValues);

        setMagnitudeAngleTwist(averageX, averageY, averageTwist);

    }

    public double averageArray(double [] array)
    {
        double sum = 0;
        for(int i=0; i<array.length; i++)
            sum+=array[i];
        return sum/array.length;
    }

    public void setMagnitudeAngleTwist(double averageX, double averageY, double averageTwist)
    {
        synchronized (this)
        {
            currentMagnitude = Math.sqrt(averageX*averageX+averageY*averageY);
            if (currentMagnitude>1.0) currentMagnitude = 1.0;

            currentAngle = Math.toDegrees(MathUtils.atan2(averageX, -averageY));
            currentTwist = averageTwist;
        }
    }
}

The following snippets of code show setup the hardware(We used CAN bus for motor control) and how to pass data from joystick to robot drive. Our full implementation has a gyro for stabilization when not intentionally using twist as well as a stabilized "idle" mode (robot not moving, but gyro engaged so that if robot is bumped it will attempt to stay in position) This was accomplished with a state machine implementation with the following states:

STATE_IDLE
STATE_DRIVER_XY
STATE_DRIVER_TWIST
STATE_IDLE_WITH_GYRO

Code:
    // drive motors
    public CANJaguar leftFrontMotor;
    public CANJaguar leftRearMotor;
    public CANJaguar rightFrontMotor;
    public CANJaguar rightRearMotor;

    // robot drive instance
    public RobotDrive robotDrive;

    // our joystick class
    public JoystickFRC623Drive driveJoystick;

    public void robotInit() {

    try {
            leftFrontMotor = new CANJaguar(12);
            rightFrontMotor = new CANJaguar(13);
            leftRearMotor = new CANJaguar(14);
            rightRearMotor = new CANJaguar(11);

        } catch (CANTimeoutException ex) {
            System.out.println("Stuck in CANTimeoutError");
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kMain6, 1, "testing");
            DriverStationLCD.getInstance().updateLCD();
        }

        driveJoystick = new JoystickFRC623Drive(1);

        robotDrive = new RobotDrive(leftFrontMotor, leftRearMotor, rightFrontMotor, rightRearMotor);
        robotDrive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true);
        robotDrive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);

        // create gyro instance
        steeringGyro = new Gyro(1, 2);
    }

    public void teleopInit() {
        // call teleop init for joysticks
        this.driveJoystick.teleopInit();
    }

    public void teleopPeriodic() {
        // call telop periodic for joysticks to preprocess inputs
        this.driveJoystick.teleopPeriodic();

        this.robotDrive.mecanumDrive_Polar(
                     this.driveJoystick.getCurrentMagnitude(),
                     this.driveJoystick.getCurrentAngle(),
                     this.driveJoystick.getCurrentTwist() );

}

If you would like to see state machine implementation let me know.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
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 00:39.

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