Mecanum strafe problems

//-----Drive Controll-----//
//right drive = (axis3 - axis4) * /2
//left drive = (axis3 + axis4) * /2
backRightDrive.spin(directionType::fwd, (controller1.Axis3.position(percentUnits::pct) - controller1.Axis4.position(percentUnits::pct)) * driveSpeed / 2, velocityUnits::pct);
backLeftDrive.spin(directionType::fwd, (controller1.Axis3.position(percentUnits::pct) + controller1.Axis4.position(percentUnits::pct)) * driveSpeed / 2, velocityUnits::pct);
frontLeftDrive.spin(directionType::fwd, (controller1.Axis3.position(percentUnits::pct) + controller1.Axis4.position(percentUnits::pct)) * driveSpeed / 2, velocityUnits::pct);
frontRightDrive.spin(directionType::fwd, (controller1.Axis3.position(percentUnits::pct) - controller1.Axis4.position(percentUnits::pct)) * driveSpeed / 2, velocityUnits::pct);

if(controller1.ButtonA.pressing() ) {
  frontLeftDrive.spin(directionType::fwd, strafe, percentUnits::pct);
  frontRightDrive.spin(directionType::fwd, strafe, percentUnits::pct);
  backLeftDrive.spin(directionType::rev, strafe, percentUnits::pct);
  backRightDrive.spin(directionType::rev, strafe, percentUnits::pct);

} else if (controller1.ButtonY.pressing() ) {
  frontLeftDrive.spin(directionType::rev, strafe, percentUnits::pct);
  frontRightDrive.spin(directionType::rev, strafe, percentUnits::pct);
  backLeftDrive.spin(directionType::fwd, strafe, percentUnits::pct);
  backRightDrive.spin(directionType::fwd, strafe, percentUnits::pct);

} else {
  frontLeftDrive.stop();
  frontRightDrive.stop();
  backLeftDrive.stop();
  backRightDrive.stop();
}

This is my program for arcade drive and a strafe with mecanum wheels. The problem is, when i download it to the robot, only the strafing works and not the drive. please help

PercentUnits::pct is a parameter for the motor, it doesn’t do anything to the axis value itself. Your spin params should just be (direction, axis3 - axis4, units), not (direction, axis3,units,axis4, units).

To clarify, to get the axis values, just do controller.axisx.position()

1 Like

im still having the same problem where only the Y and A buttons work and the Axis3/Axis4 joystick does nothing

Can you post your updated code? Be sure to place it around [code] [/code] tags so we can read it a bit easier

how do i place it around a tag?

Wait a minute I see the issue

Your else statement at the end is turning your motors off from the previous statements. Try changing it to else if axis3 < 10 and axis 3 > -10 and axis4 < 10 and axis4 >-10

3 Likes

A more accurate description of what you want to to is “wrap the code in code tags”. You can accomplish this in one of three ways:

  1. Place the string [code] before the start of your code, and the string [/code] after the end of your code.
  2. Place three backtick characters (```) both before and after your code.
  3. In the post edit/compose window, highlight you code and press the </> button.
1 Like

I am going off of this code.
if(controller1.ButtonA.pressing() ) {
frontLeftDrive.spin(directionType::fwd, strafe, percentUnits::pct);
frontRightDrive.spin(directionType::fwd, strafe, percentUnits::pct);
backLeftDrive.spin(directionType::rev, strafe, percentUnits::pct);
backRightDrive.spin(directionType::rev, strafe, percentUnits::pct);

} else if (controller1.ButtonY.pressing() ) {
frontLeftDrive.spin(directionType::rev, strafe, percentUnits::pct);
frontRightDrive.spin(directionType::rev, strafe, percentUnits::pct);
backLeftDrive.spin(directionType::fwd, strafe, percentUnits::pct);
backRightDrive.spin(directionType::fwd, strafe, percentUnits::pct);

} else {
frontLeftDrive.stop();
frontRightDrive.stop();
backLeftDrive.stop();
backRightDrive.stop();
}

Basically you are telling the robot if A is pressed, strafe one direction and if Y is pressed, strafe the other way. Though you are telling the robot that if neither of those buttons are pressed, then none of the wheels should move.

This topic is pretty old, I’m sure @ColeDeas’s problem is solved as there has been no questions from him, so please don’t revive it.