HolonomicDrive
Holonomic Drive
HolonomicDrive supports two configurations: three motors with configurable translation directions, or four motors using the same style of mixing as MecanumDrive. Choose the constructor that matches the drivebase; the number of stored motors determines the calculation path.
Three motor configuration
The constructor order is left, right, slide. Each parameter is an initialized EasyControllable object. The translation command is projected onto each configured direction, and the same turn input is added to all three projected values.
import dev.easyfamily.easystack.drivebase.HolonomicDrive;
HolonomicDrive drive new HolonomicDrive(left, right, slide);
drive.;| Direction | Default angle | Radians |
|---|---|---|
| Left motor | 120 degrees | 2 × Math.PI / 3 |
| Right motor | 60 degrees | Math.PI / 3 |
| Slide motor | 270 degrees | 3 × Math.PI / 2 |
These are the actual defaults in the supplied class. They are projection directions, not automatically detected mounting angles. Confirm the wheel drive direction and coordinate convention for your mechanism.
Custom motor angles
Supply angles in radians after the three actuators, or call setMotorAngles() later. Both use left, right, slide order.
drive.setMotorAngles(
Math.toRadians(120.0),
Math.toRadians(60.0),
Math.toRadians(270.0)
);getLeftMotorAngle(), getRightMotorAngle(), and getSlideMotorAngle() return the stored angles. The three motor output path does not automatically invert the right actuator.
HolonomicDrive has no squareInputs overload. If you want signed squaring, apply Math.copySign(value * value, value) to each joystick value before calling the drive method. drive(DrivePowers) delegates to robot centric control.
Holonomic driving methods
Robot centric and field centric movement
Both hardware configurations use the same movement methods. Robot centric control takes strafe, forward, and turn. Field centric control adds heading in radians and rotates the translation vector by negative heading.
drive.driveRobotCentric(
gamepad1.left_stick_x,
-gamepad1.left_stick_y,
gamepad1.right_stick_x
);
drive.driveFieldCentric(
gamepad1.left_stick_x,
-gamepad1.left_stick_y,
gamepad1.right_stick_x,
headingRadians
);The two calls illustrate alternatives; choose one for each loop. The second call would overwrite the first if both were executed together. The class clips each input axis and normalizes the mixed commands before applying maxOutput.
Four motor configuration
HolonomicDrive drive = new HolonomicDrive(
frontLeft, frontRight, backLeft, backRight
);The four motor path uses a fixed mecanum style mix. setMotorAngles() only affects the three motor path; it does not configure arbitrary angles for four wheels.
Unlike MecanumDrive, the four motor HolonomicDrive path always negates front right and back right outputs. It has no autoInvert constructor argument and no setRightSideInverted() method. Account for this fixed inversion when configuring hardware.
Direct motor power
Use setMotorPowers(left, right, slide) only for a three motor instance, or setMotorPowers(frontLeft, frontRight, backLeft, backRight) for a four motor instance. These overloads do not validate the configuration: four inputs on a three motor instance attempt to access a missing motor, while three inputs on a four motor instance leave the fourth motor untouched.
Both paths apply maxOutput without clipping or normalizing direct inputs. The four motor path also applies its fixed right side inversion. stop() iterates over the actual stored motor array and sends zero to every actuator.
Holonomic control example
This helper works with either a three motor or four motor HolonomicDrive. Hardware selection remains in the constructor used to create the drive instance. A fresh heading is required only for the field centric branch.
import com.qualcomm.robotcore.hardware.Gamepad;
import dev.easyfamily.easystack.drivebase.HolonomicDrive;
public class HolonomicControls {
private final HolonomicDrive drive;
public HolonomicControls(HolonomicDrive drive) {
this.drive = drive;
drive.setMaxOutput(0.6);
}
public void update(Gamepad pad, double headingRadians,
boolean fieldCentric) {
if (fieldCentric) {
drive.driveFieldCentric(pad.left_stick_x,
-pad.left_stick_y, pad.right_stick_x,
headingRadians);
} else {
drive.driveRobotCentric(pad.left_stick_x, -pad.left_stick_y, pad.right_stick_x);
}
}
public void stop() {
drive.stop();
}
}Holonomic setup checks
If changing motor angles has no effect, check which constructor was used. setMotorAngles() only changes the three motor path; four motor mixing uses fixed directions and right side inversion.
Use the direct power overload that matches the number of motors. For field centric issues, check heading units, sign, and zero reference before changing motor configuration.
Última atualização 2026-11-16