Mecanum Drive in VCS

Our team decided to do a mecanum drive for our robot base, and I wrote the program. I got the driving to work, but I’ve seen many mecanum drives have a “deadzone” , and I can’t figure out how to make one in Vex Coding Studio. My program so far is below, any help is appreciated. Thanks.

int main() {


LeftFront.spin(vex::directionType::fwd, (Controller1.Axis3.value()  + Controller1.Axis1.value() + Controller1.Axis4.value() ), vex::velocityUnits::pct); 
LeftBack.spin(vex::directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis1.value() - Controller1.Axis4.value()), vex::velocityUnits::pct); 
RightFront.spin(vex::directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis1.value() - Controller1.Axis4.value()), vex::velocityUnits::pct);
RightBack.spin(vex::directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis1.value() + Controller1.Axis4.value()), vex::velocityUnits::pct);

if (Controller1.Axis3.value() > 15) {
    Controller1.Axis3.value() = Controller1.Axis3.value()
else {
  Controller1.Axis3.value() = 0

    if (Controller1.Axis4.value() > 15) {
 Controller1.Axis4.value() =  Controller1.Axis4.value()

else {
 Controller1.Axis4.value() = 0

if (Controller1.Axis1.value() > 15) {

 Controller1.Axis1.value() =  Controller1.Axis4.value()

else {
 Controller1.Axis1.value() = 0



Hi Nex,

What you are looking for is commonly called a “deadband”, although deadzone sounds good too, especially if you are a Stephen King fan.

A deadband can prevent your robot from creeping when you have a sticky joystick. In the code you posted, it looks like you are trying to ignore any controller value of less than 15. Keep in mind that the range of a joystick axis is between 100 and -100. So if you filtered out everything below 15 you would prevent your robot from moving backward.

What you want to do instead is filter out anything with an absolute value of less than 15. The abs() function will do this for you:

if (abs(Controller1.Axis3.value()) > 15)   
    outside the deadband, don't change the value
    inside the deadband, set to zero

I’m not sure if Vex Code Studio includes support for the abs() function. But this code would do the same thing:

if ((Controller1.Axis3.value() > 15) || (Controller1.Axis3.value() < -15) )

A bigger issue with your code is that you are trying to assign a value to the joystick. The following command would attempt to change the value on the joystick to zero:

Controller1.Axis3.value() = 0

You are allowed to read the joystick value, but you can’t change it. What you want to do instead is create variables for each axis and then modify those values before setting the motor speeds. The pseudocode would be like this:

//declare variables
int deadband_axis1, deadband_axis3, deadband_axis4

repeat forever    
    // set the values of the deadband variables    
    if abs(Controller.Axis1.value()) > 15        
        deadband_axis1 = Controller.Axis1.value()    
        deadband_axis1 = 0    
    // now do the same thing for axis3 & axis4    ....   
    // then set the motor speeds     
    LeftFront.spin(..., deadband_axis3 + deadband_axis1 + deadband_axis4, ...)    
    // follow pattern for other motors

Hope that helps. BTW - 15 seems kinda big for a controller deadband, you might want to try something smaller.


To add to @jrp62 advice you can use fabs() function and if you still have problem with small deadband, please, try to re-calibrate your joystick.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.