Mecanum code being weird, please help

Hey guys, so, I have mecanum code, and it’s being weird(as the title says). So, the controller configuration isn’t allowing me to map controls to the joysticks. Like, when I click the joysticks, nothing pops up, and I can’t map controls. Does anyone know what’s happening with this, and/or how to fix it? This is urgent.


Edit: It’s not a joystick issue, because it works with the preloaded drive codes.

1 Like

Only the drivetrain motor group can be assigned to the joysticks. Motors have to individually be programmed if not part of the drivetrain motor group.

2 Likes

The controller isn’t set up so you can code mecanums by setting joysticks anyway. It assumes a tank drive.

4 Likes

I don’t know anything about the joystick setup thing in vexcode, but I highly recommend you just program your own drivetrain. This is both better for learning code, and also more flexible since it’ll allow you to add things like deadzones. It’s not too hard, and you can find tons of example codes on the forums

2 Likes

To code drivercontrol for mecanum base, I would recommend using the motor-command-with-stick-output-as-speed-value way as detailed in my previous post here.
Hope that helps, and good luck! :grin:

2 Likes

I’ve set each motor up individually, not in a drivetrain.

If you want I can put on a code for it tomorrow. Don’t feel like writing down the program at the moment.

You can if you want.

HI, I spent a while trying to figure out mecanum drive and just resorted to a code where I map it in code

/*----------------------------------------------------------------------------*/

/* /
/
Module: main.cpp /
/
Author: danielsarasohn /
/
Created: Tue Nov 03 2020 /
/
Description: V5 project /
/
/
/
----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// BackLeft motor 1
// BackRight motor 10
// FrontRight motor 3
// FrontLeft motor 9
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”
using namespace vex;

void speed2()
{
FrontRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()- Controller1.Axis4.value())*2),velocityUnits::rpm);
BackRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()+ Controller1.Axis4.value())*2),velocityUnits::rpm);
FrontLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()+ Controller1.Axis4.value())*2),velocityUnits::rpm);
BackLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()- Controller1.Axis4.value())*2),velocityUnits::rpm);
}
void speed4()
{
FrontRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()- Controller1.Axis4.value())*4),velocityUnits::rpm);
BackRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()+ Controller1.Axis4.value())*4),velocityUnits::rpm);
FrontLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()+ Controller1.Axis4.value())*4),velocityUnits::rpm);
BackLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()- Controller1.Axis4.value())*4),velocityUnits::rpm);
}

void slow2()
{
FrontRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()- Controller1.Axis4.value())/2),velocityUnits::rpm);
BackRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()+ Controller1.Axis4.value())/2),velocityUnits::rpm);
FrontLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()+ Controller1.Axis4.value())/2),velocityUnits::rpm);
BackLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()- Controller1.Axis4.value())/2),velocityUnits::rpm);
}

void slow4()
{
FrontRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()- Controller1.Axis4.value())/4),velocityUnits::rpm);
BackRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()+ Controller1.Axis4.value())/4),velocityUnits::rpm);
FrontLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()+ Controller1.Axis4.value())/4),velocityUnits::rpm);
BackLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()- Controller1.Axis4.value())/4),velocityUnits::rpm);
}

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
while(true) {

if(Controller1.ButtonX.pressing())
{
speed4();
}
if(Controller1.ButtonY.pressing())
{
slow2();
}
if(Controller1.ButtonB.pressing())
{
slow4();
}
if(Controller1.ButtonA.pressing())
{
speed2();
}

FrontRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()- Controller1.Axis4.value())),velocityUnits::rpm);  
BackRight.spin(directionType::fwd,((Controller1.Axis3.value() - Controller1.Axis1.value()+ Controller1.Axis4.value())),velocityUnits::rpm);
FrontLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()+ Controller1.Axis4.value())),velocityUnits::rpm);
BackLeft.spin(directionType::fwd,((Controller1.Axis3.value() + Controller1.Axis1.value()- Controller1.Axis4.value())),velocityUnits::rpm);

}
}

1 Like

@JustALonelyAstronaut. That is the code my team got working for our mecanum wheels

1 Like
Drivetrain.drive(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis1.value()*2), vex::velocityUnits::pct);
  FrontRightMotor.spin(vex::directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis1.value()*2), vex::velocityUnits::pct);
  BackLeftMotor.spin(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis1.value()*2), vex::velocityUnits::pct);

Does anyone know what’s wrong with this code?

I mean, there likely nothing “wrong” with the code in the sense that it will compile and run. The robot will behave as instructed.

Assuming FrontRightMotor and BackRightMotor are motors included in the Drivetrain, these lines at best do nothing, and at worst interfere with the coder’s intents.

Beyond that, it seems strange that the coder would multiply the value of one of the joystick axis but not the other, especially considering the use of parenthesis.

Can lead to substantially different observed behavior than:
(Controller1.Axis3.value() + Controller1.Axis1.value())*2

But, perhaps this is intentional

2 Likes

The error I’m getting is with this line

Drivetrain.drive(vex::directionType::fwd, (Controller1.Axis3.value()Controller1.Axis1.value()*2), vex::velocityUnits::pct);

Your error is when you say : Controller1.Axis3.value()Controller1.Axis1.value()*2; there’s no operator between the two joystick values. My guess is what you mean is: Drivetrain.drive(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis1.value()) * 2, vex::velocityUnits::pct);

3 Likes