Search in sources :

Example 11 with Translation

use of me.wobblyyyy.pathfinder2.geometry.Translation in project Pathfinder2 by Wobblyyyy.

the class SwerveDrive method setTranslation.

/**
 * Set a translation to the robot. In the case of this swerve chassis,
 * this does a couple of things. Firstly, it applies the modifier to
 * the inputted translation. Secondly, it calculates a swerve chassis
 * state based on the translation. Thirdly, it determines the swerve
 * module states of each individual module. And finally, it sets the
 * state to each of these modules, making the robot move.
 *
 * @param translation a translation the robot should act upon. This
 *                    translation should always be <em>relative</em>,
 *                    meaning whatever the translation says should make
 *                    the robot act accordingly according to the robot's
 *                    position and the robot's current heading. I'm
 *                    currently exhausted and just about entirely unable
 *                    to type, so this isn't coherent, but guess what -
 */
@Override
public void setTranslation(Translation translation) {
    translation = modifier.apply(translation);
    this.translation = translation;
    RelativeSwerveState state = kinematics.calculate(translation);
    RelativeSwerveModuleState frState = state.fr();
    RelativeSwerveModuleState flState = state.fl();
    RelativeSwerveModuleState brState = state.br();
    RelativeSwerveModuleState blState = state.bl();
    this.frontRightModule.set(frState);
    this.frontLeftModule.set(flState);
    this.backRightModule.set(brState);
    this.backLeftModule.set(blState);
}
Also used : RelativeSwerveModuleState(me.wobblyyyy.pathfinder2.kinematics.RelativeSwerveModuleState) RelativeSwerveState(me.wobblyyyy.pathfinder2.kinematics.RelativeSwerveState)

Example 12 with Translation

use of me.wobblyyyy.pathfinder2.geometry.Translation in project Pathfinder2 by Wobblyyyy.

the class Follower method getRelativeTranslation.

/**
 * Get a relative translation by first generating an absolute translation
 * and then converting it into a relative one.
 *
 * @param current the robot's current position.
 * @param target  the robot's target point / marker.
 * @param speed   the speed at which the robot should move.
 * @param turn    how much the robot should turn.
 * @return a relative translation. This translation, like any absolute
 * translation, will always have X and Y values that fit within the bounds
 * (-1.0, 1.0). The Z aspect of the translation will always be equal to
 * whatever turn value is provided.
 */
static Translation getRelativeTranslation(PointXYZ current, PointXYZ target, double speed, double turn) {
    Translation absoluteTranslation = getAbsoluteTranslation(current, target, speed, turn);
    Translation relativeTranslation = absoluteTranslation.toRelative(current.z());
    Logger.trace(Follower.class, "absolute translation: <%s> relative translation: <%s> " + "current: <%s> target: <%s> speed: <%s> turn: <%s>", absoluteTranslation, relativeTranslation, current, target, speed, turn);
    return relativeTranslation;
}
Also used : Translation(me.wobblyyyy.pathfinder2.geometry.Translation)

Example 13 with Translation

use of me.wobblyyyy.pathfinder2.geometry.Translation in project Pathfinder2 by Wobblyyyy.

the class GenericFollower method tick.

@Override
public boolean tick(PointXYZ current, Consumer<Translation> consumer) {
    // alright - i'm writing this comment maybe... say... four months?
    // after writing this initial bit of code, and i would just like to
    // say - if you're here because you're trying to figure out what makes
    // the robot move, congrats! you've found it! enjoy some stupidly
    // thoroughly commented and insanely simple code!
    // with love,
    // - colin <3
    // Tue Jan 18 22:34:58
    // p.s. i also made all of the comments in this method lowercase now
    // so it matches the vibe better. you know what i mean?
    ValidationUtils.validate(current, "current");
    ValidationUtils.validate(consumer, "consumer");
    Logger.trace(GenericFollower.class, "Ticking follower (current pos: <%s>)", current, consumer);
    // right here.
    if (trajectory.isDone(current)) {
        Logger.debug(GenericFollower.class, "Finished follower for trajectory <%s>", trajectory);
        // because the trajectory has finished, we give the robot a
        // translation of zero - there's no point in moving anymore, right?
        consumer.accept(Translation.ZERO);
        // rest of the method won't get executed.
        return true;
    }
    // assuming the follower hasn't finished executing its trajectory,
    // we continue by finding a couple values and generating a shiny
    // new translation for the robot to follow.
    // get the next marker by calling the trajectory's nextMarker
    // method. this method should always return a target point we can
    // use to generate a new translation.
    PointXYZ nextMarker = trajectory.nextMarker(current);
    // and of course, the speed, because some trajectories can control
    // speed differently.
    double speed = trajectory.speed(current);
    // determine the delta between the two angles, so we can calculate
    // turn in just a moment.
    double angleDelta = Angle.minimumDelta(current.z(), nextMarker.z());
    // and calculate turn. remember, the turn controller's only job is to
    // get the delta to zero, so by feeding it the delta it should output
    // a value that will minimize that aforementioned delta.
    double turn = turnController.calculate(angleDelta);
    // getRelativeTranslation returns a RELATIVE translation (meaning it
    // can be applied to the robot)
    Translation translation = Follower.getRelativeTranslation(current, nextMarker, speed, turn);
    Logger.trace(GenericFollower.class, "Next marker: <%s>, speed: <%s>, angle delta: <%s deg>, " + "turn value: <%s>, current translation: <%s>", nextMarker, speed, angleDelta, turn, translation);
    // use the consumer to accept a translation we create.
    // instead of creating an absolute translation, which would only help
    // if the robot is facing straight forwards, we have to use a relative
    // translation. the follower interface's static method that we
    // call here (getRelativeTranslation) first generates an absolute
    // translation and then converts it to a relative one. epic sauce.
    consumer.accept(translation);
    // we're not done yet, so return false.
    return false;
}
Also used : Translation(me.wobblyyyy.pathfinder2.geometry.Translation) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

Example 14 with Translation

use of me.wobblyyyy.pathfinder2.geometry.Translation in project Pathfinder2 by Wobblyyyy.

the class AutoRotator method apply.

@Override
public Translation apply(Translation translation) {
    if (!isActive)
        return translation;
    if (centerPoint == null)
        throw new NullPointerException("Attempted to use an AutoRotator without having previously " + "set a center point, make sure to use the" + "setCenterPoint(PointXY) method to do that.");
    PointXYZ position = pathfinder.getPosition();
    double delta = Angle.minimumDelta(position.z(), position.angleTo(centerPoint).add(angleOffset));
    return translation.withVz(turnController.calculate(delta));
}
Also used : PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

Example 15 with Translation

use of me.wobblyyyy.pathfinder2.geometry.Translation in project Pathfinder2 by Wobblyyyy.

the class MecanumKinematics method toTranslation.

public Translation toTranslation(MecanumState state) {
    SimpleMatrix wheelSpeedsMatrix = new SimpleMatrix(4, 1);
    wheelSpeedsMatrix.setColumn(0, 0, state.fl(), state.fr(), state.bl(), state.br());
    SimpleMatrix speedVector = forwardsKinematics.mult(wheelSpeedsMatrix);
    return new Translation(speedVector.get(0, 0), speedVector.get(1, 0), speedVector.get(2, 0));
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Translation(me.wobblyyyy.pathfinder2.geometry.Translation)

Aggregations

Translation (me.wobblyyyy.pathfinder2.geometry.Translation)20 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)11 Angle (me.wobblyyyy.pathfinder2.geometry.Angle)6 Pathfinder (me.wobblyyyy.pathfinder2.Pathfinder)5 SimpleMatrix (org.ejml.simple.SimpleMatrix)4 ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)3 Test (org.junit.jupiter.api.Test)3 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)2 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)2 ChassisSpeeds (edu.wpi.first.math.kinematics.ChassisSpeeds)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MecanumState (me.wobblyyyy.pathfinder2.kinematics.MecanumState)1 RelativeSwerveModuleState (me.wobblyyyy.pathfinder2.kinematics.RelativeSwerveModuleState)1 RelativeSwerveState (me.wobblyyyy.pathfinder2.kinematics.RelativeSwerveState)1 ListenerMode (me.wobblyyyy.pathfinder2.listening.ListenerMode)1 SimulatedRobot (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot)1 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)1 Trajectory (me.wobblyyyy.pathfinder2.trajectory.Trajectory)1 AdvancedSplineTrajectoryBuilder (me.wobblyyyy.pathfinder2.trajectory.spline.AdvancedSplineTrajectoryBuilder)1