How to Program Mecanum

Okay I have posted multiple posts and tried hours worth of useless troubleshooting and I still do not have a working program. I have gotten code from other people, but that code never works. I have gotten suggestions here but none of them seem to fix it. Our team is about to give up and redesign our chassis to put normal wheels in. In a last ditch effort I made this program. In Robot.java under autonomous you will see a lot of commented out mecanumDrive(value, value, value, value) those were used for testing when the mecanumDrive method used to be located there. They all worked for the intended direction in autonomous. I simply can’t get our XBox controller to work with it. I want buttons LB and RB to control straffing and the left joystick to control forward/backward and turning. So I programmed it for that - using if statements in drivetele - thats because none of the built in polar or cartesian commands worked(everything was messed up) - and none of the buttons or joysticks on the controller make the robot do anything. I know my XBox class works because we used it for tank drive last year. I am lost and have no idea what to do so PLEASE help!

Here is the code: https://github.com/MrSTUDofCODE/NewMecanumCode/tree/master/Copy%20of%20Copy%20of%20Getting%20Started/src/org/usfirst/frc/team4623/robot

THANKS!!

Given the changes to the driver station this year, that is not a correct assumption. The xBox controller mapping changed.

Agreed. As a quick test, try loading last year’s tank drive software and see how it drives with mecanum. While you won’t get anywhere near the performance that you would with rubber tires, tank mode commands on a mecanum platform shall produce the desired results for forward, reverse, spin left, and spin right.

Okay - that would explain the problems I was having - the wrong joysticks were running the wrong things - what are the new mappings?

I googled “WPI xbox controller mapping 2015” and followed it to the following image on the team358 page:

http://team358.org/files/programming/ControlSystem2015-2019/images/XBoxControlMapping.jpg

If you are using the SmartDashboard, you can display the values of each axis and play around with the controller to determine which axis is altered by what. Our team has gotten mecanum wheels working on a test chassis successfully using a sidewinder joystick. We are currently in the process of implementing an XBox controller system as well. We are, however, also working with field orientation which may not be helpful for you. If you would like, here is our drive code though it is still in the works.

After taking a quick glance at your code, you may also run into issues with strafing.

If you want to strafe to the left, you want to drive the front left forward and rear left backwards while driving the front right backwards and the back right forwards. This creates a vector in only the left direction.

You are currently, with this line:


CommandBase.mecanum.mecanumDrive(-.3, .3, -.3, .3);

driving your front left backwards and rear left forwards. This will result in your end vector heading towards the middle of your robot causing it to spin it’s wheels and get nowhere.

A similar approach is required for strafing right, with the wheels driving the opposite direction of strafing left.

Not. The wheel speeds described above are all the reverse of what they should be.

Or perhaps team 3786 has their wheels mounted incorrectly? The rollers should form an “X” when viewed from above, and a diamond when viewed from below.

This is supported by the following observation, which shouldn’t ever happen with properly oriented mecanums; if the torques add up to zero, and the translation adds up to zero, and the wheels are spinning, something’s wrong.

This will result in your end vector heading towards the middle of your robot causing it to spin it’s wheels and get nowhere.

Correction: this is possible, with the front wheels spinning backwards and the rear wheels forwards (or vice versa), but the force doesn’t putsh “towards the middle”.

Those values are not the ones that are supposed to work - the ones that were suggested didn’t work and I had to play around with them to make them work - all of that was already tested in autonomous and works

Do your rollers form an X when viewed from above? Are you able to rotate?

Our wheels are mounted correctly and form an “X”, perhaps I was just thinking wrong at the time as I did not have access to view our chassis. At any rate, when strafing, one side should have the wheels rotating towards the outside when viewed side on, and the other side should be rotating inwards.

Just to be clear:

Assuming your wheels are mounted correctly,

Strafe Left:

  • Left wheels rotate “inward”
  • Right wheels rotate “outward”

Strafe Right:

  • Left wheels rotate “outward”
  • Right wheels rotate “inward”

… which is not the same as this:

Yes, you are correct. I was mistaken.

Okay I redid the program again and will test everything again tomorrow and get back to you - hopefully it works this time!

THANKS!

Okay that didn’t work either. Nothing works. The program uploads - the DS doesn’t through any errors - it shows all green lights - but nothing happens with the Joysticks - I can press anything on the XBox controller and nothing happens. I can still make the robot move using ,my preassigned values in autonomous.

Here is the upload for Eclipse:

Buildfile: C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build.xml
Trying to override old definition of task classloader
clean:
   [delete] Deleting directory C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build
   [delete] Deleting directory C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\dist
compile:
    [mkdir] Created dir: C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build
     [echo] [athena-compile] Compiling src with classpath=C:\Users\Kristen/wpilib/java/current/lib/WPILib.jar:C:\Users\Kristen/wpilib/java/current/lib/NetworkTables.jar to build
    [javac] Compiling 8 source files to C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build
jar:
     [echo] [athena-jar] Making jar dist/FRCUserProgram.jar.
    [mkdir] Created dir: C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\dist
    [mkdir] Created dir: C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build\jars
     [echo] [athena-jar] Copying jars from C:\Users\Kristen/wpilib/java/current/lib/WPILib.jar:C:\Users\Kristen/wpilib/java/current/lib/NetworkTables.jar to build/jars.
     [copy] Copying 2 files to C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\build\jars
      [jar] Building jar: C:\Users\Kristen\Documents\GitHub\Copy of Copy of Getting Started\dist\FRCUserProgram.jar
get-target-ip:
     [echo] Trying Target: roboRIO-4623.local
     [echo] roboRIO found via mDNS
dependencies:
     [echo] roboRIO image version validated
     [echo] Checking for JRE. If this fails install the JRE using these instructions: https://wpilib.screenstepslive.com/s/4485/m/13503/l/288822-installing-java-8-on-the-roborio-using-the-frc-roborio-java-installer-java-only
  [sshexec] Connecting to roboRIO-4623.local:22
  [sshexec] cmd : test -d /usr/local/frc/JRE
deploy:
     [echo] [athena-deploy] Copying code over.
      [scp] Connecting to roboRIO-4623.local:22
      [scp] done.
      [scp] Connecting to roboRIO-4623.local:22
      [scp] done.
     [echo] [athena-deploy] Starting program.
  [sshexec] Connecting to roboRIO-4623.local:22
  [sshexec] cmd : . /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t -r;
  [sshexec] stopped process in pidfile '/var/run/natinst/FRC_UserProgram.pid' (pid 4205)
BUILD SUCCESSFUL
Total time: 13 seconds

Here is the link to the updated code:

Also we have another person programming in labview - so I went into the web interface and checked disable RT startup - which should have switched it back to JAVA

PLEASE help - THANKS!

I think you need to add Scheduler.run() in TeleopPerodic()

Edit: Never go off memory-- it should be


    public void teleopPeriodic() {
        Scheduler.getInstance().run();
    }

Building on last post–

When you push teleop mode on Drive station, IterativeRobot will call teleopInit() and then call teleopPeriodic() every 20ms.

Similarly when you press Autonomous from drive station, it calls autonomousInit() and then autonomousPeriodic() every 20ms after that.

Your autonomousPeriodic() directly calls your drivetrain so you are making that call every 20ms in autonomous. This is why this mode works for you.

Note, you should never call any subsytem functionality from anything but a command. You are only asking for trouble.

Your autonomousPeriodic() should be:


    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

You should create a command field in your Robot class


public class Robot extends IterativeRobot {
    Command autonomousCommand;
    ...

and then you can do something like this in autonomousInit:


    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand == null) {
            autonomousCommand=new leftStraffe();
        } 
        autonomousCommand.start();
    }

Now, when you run autonomous, we simply run the scheduler. The autonomous starts your leftStraffe command (note, java convention is to name classes with a captial so LeftStraffe may be a better name because you will have to look back less to see how you spelled it if you are consistent with your naming conventions), so that command is now being controlled by the scheduler. It will call execute() which in turn will be the appropriate way call your mecanum drive function.

Just one more thing I’m compelled to point out…

FRC is the hardest fun you’ll ever have. If it always worked the first time you might have fun, but it wouldn’t be hard and you probably would learn less.

Wait a second! The above is in direct contradiction to your ‘Nothing Works’ assertion! (all is not lost-- your autonomous moves!!!)

Don’t be discouraged. You’re living the FRC dream my friend. You’re facing challenges looking for answers. This is my life too-- I’m a 25 year professional software engineer. I’ve had these moments too.

But the true joy will come in learning, and building on what you have learned. Every time I get stuck in my job, I’m on stackoverflow or google searching for a solution to my particular problem. But I would not have gotten as far as I have by concluding ‘Nothing Works’. Don’t go there.

You will get through this.

I’ve learned to trust Ether so I’m trying not to doubt this, but it seemed wrong to me the first time I read it.

[quote=Ether,post:12,topic:141307"]

Just to be clear:

Assuming your wheels are mounted correctly,

Strafe Left:

  • Left wheels rotate “inward”
  • Right wheels rotate “outward”

Strafe Right:

  • Left wheels rotate “outward”
  • Right wheels rotate “inward”

… which is not the same as this:

*[/quote]

The above didn’t help me as I’m not able to visualize inward outward-- I can interpret it two different ways-- inward from the top or inward from the bottom?

My thinking is that the left front wheel driving forward means the direction that would carry the robot toward what we are calling the front i.e. counterclockwise when viewed from the left side of the robot.

So on the bottom we have a diamond and that tells me that the wheel rotating that way should create force in the forward and the left direction. (in sand, all the sand would wind up on the right side of the wheel and behind the wheel).

Likewise if I drive the left rear wheel backwards (i.e. clockwise when viewed from the left) or the direction that would carry the robot to its rear if they were normal wheels then that diamond on the bottom will be forcing the robot backwards and to the left.

Summing those, the forward and back cancel and there should be a net left motion out of the left.

On the right if you drive the front right backward (counterclockwise when viewed from the right), the angle from below is identical to the back left wheel which we also drove backwards so again that wheel should be pushing backwards and left (in my eye).

And finally the rear right wheel driving forward (clockwise when viewed from right), so here as in the left front I see it should be pushing foward and left.

So the original position by 3786KRRobotics still seems correct to me. I count equal forces forward and backwards with his incantation and a left force from all wheels.

Yet everyone else seems to agree with Ether and common sense says I should too-- but I must be missing something obvious.

Can anyone point out where I’m thinking wrong?

I need an obviator-- one who can point out the obvious to me because at the moment I can’t see it.

Maybe there is something fundamental I’m just not grasping-- we used RobotDrive to handle all this for us and it works fine so I never had to properly think though it.

Okay THANKS for all the help! I changed it and it works for forwards/backwards and straffing - I am going to program turning with the buttons. Now I am trying to program pnuematics and I did it last year and it was easy but all my button assignments don’t work this year - I have the updated mappings too - here is the new code:

THANKS again!