Help with v5 mecanum wheels Programming

Hi, so my team and I are having trouble trying to program our mecanum wheel drive. the motors won’t move unless we angle the joysticks a certain way.

Heres our logic:

#include “robot-config.h”

int main() {
while(true){

//*************************Forward and Backwards
Back_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);

//**************** Striafe L and R (invesrse in right)*********************
Back_left.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::rev, Controller1.Axis1.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::rev, Controller1.Axis1.value(), vex::velocityUnits::pct);

//Turning left***
if(Controller1.ButtonL1.pressing()) {
Back_left.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
}
else if(Controller1.ButtonR1.pressing()) {
Back_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
}
else {
Back_left.stop(brakeType::hold);
Back_right.stop(brakeType::hold);
Front_left.stop(brakeType::hold);
Front_right.stop(brakeType::hold);
}
}
}

Heres our logic

PORT11 IIIIIIIIIIIIII PORT1
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PORT20 IIIIIIIIIIIIIII PORT10

#include “robot-config.h”

int main() {
while(true){

//*************************Forward and Backwards
Back_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);

//**************** Striafe L and R (invesrse in right)*********************
Back_left.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::rev, Controller1.Axis1.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::rev, Controller1.Axis1.value(), vex::velocityUnits::pct);

//Turning left***
if(Controller1.ButtonL1.pressing()) {
Back_left.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
}
else if(Controller1.ButtonR1.pressing()) {
Back_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Back_right.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_right.spin(vex::directionType::rev, Controller1.Axis3.value(), vex::velocityUnits::pct);
Front_left.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
}
else {
Back_left.stop(brakeType::hold);
Back_right.stop(brakeType::hold);
Front_left.stop(brakeType::hold);
Front_right.stop(brakeType::hold);
}
}
}

You need to change a lot of this. Trying to set a motor more than once in a given loop will result in unpredictable behavior. Your loop here sets your motor 2-3 times per loop and potentially stops it as well.

Rather than command a motor with one stick then command it with a different stick then command it based on a button, you need to blend the sticks and buttons into a single motor command. For one way of doing holonomic drive command blending, you could take a look at the algorithm that I use in my RMS holonomic example. It looks like you’re using a slightly different control scheme than me, as I was using axes 3 and 4 for XY translation and axis 1 for Z axis rotation and you were using axes 3 and 1 for XY and a button for rotation.

does the code you use apply to mecanum wheels as well?

http://www.robotc.net/blog/2011/11/22/vex-mecanum-drive-using-robotc/

see the code in the link. Although it is RobotC. Same algorithm should apply.

Mechanums control just like an X drive does, yes.

Hey, just tried the code and there was a line in the code that said “#include “vex.h”” and it seems to be a file that we don’t have that is keeping the code from downloading to the robot. Is there some way to create this file, and if so how to we create it and what goes in it, or do we have to download it from somewhere?

You neither create nor download it. It’s a part of Robot Mesh Studio. You won’t be able to copy my code into VCS without making changes. (Though the things that would have to be changed are fairly minimal in this example.)

This is what I used when I built a mecanum drive to test it:
int main()
{
while(true)
{
BackLeft.spin(directionType::fwd,Controller1.Axis3.value()-Controller1.Axis4.value()+Controller1.Axis1.value() , velocityUnits::pct);
FrontLeft.spin(directionType::fwd,Controller1.Axis3.value()+Controller1.Axis4.value()+Controller1.Axis1.value() , velocityUnits::pct);
BackRight.spin(directionType::rev,Controller1.Axis3.value()+Controller1.Axis4.value()-Controller1.Axis1.value() , velocityUnits::pct);
FrontRight.spin(directionType::rev,Controller1.Axis3.value()-Controller1.Axis4.value()-Controller1.Axis1.value() , velocityUnits::pct);
}
}

Can someone insert a complete v5 mecanum wheel program?

@rellstel The holonomic example I posted earlier in this thread is a complete mecanum wheel program. As is the one posted by @langchen. They control just like an X-drive holonomic robot.

The holonomic example and mecanum wheels programs are interchangeable?

what are the things that would have to be changed?