Skip to content

Commit 072dbad

Browse files
committed
Lots of fixes
1 parent ff66b50 commit 072dbad

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

InertialNavigation.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import edu.wpi.first.wpilibj.Timer;
44
import frc.libzodiac.util.Vec2D;
55

6-
public class InertialNavigation extends Zubsystem {
6+
public class InertialNavigation extends Zubsystem implements ZmartDash {
77
private final Gyro gyro;
88

99
private final Timer timer = new Timer();
1010

1111
private double zero = 0;
12+
private Vec2D gravity = new Vec2D(0,0);
1213
private Vec2D pos = new Vec2D(0, 0);
1314
private Vec2D speed = new Vec2D(0, 0);
1415

@@ -26,6 +27,7 @@ public InertialNavigation init() {
2627

2728
public InertialNavigation setZero() {
2829
this.zero = this.gyro.getYaw();
30+
// this.gravity = this.gyro.getAcceleration();
2931
return this;
3032
}
3133

@@ -35,10 +37,13 @@ public InertialNavigation setZero(double zero) {
3537
}
3638

3739
private Vec2D getAcceleration() {
38-
return this.gyro.getAcceleration().rot(-this.zero);
40+
return this.gyro.getAcceleration().sub(gravity).mul(10);//.rot(-this.zero);
3941
}
4042

4143
public InertialNavigation update() {
44+
this.debug("posinav", "" + this.getPosition());
45+
this.debug("yawinav", this.getYaw());
46+
this.debug("acc", "" + this.getAcceleration());
4247
final var loopTime = timer.get();
4348
timer.reset();
4449
this.speed = this.speed.add(this.getAcceleration().mul(loopTime));
@@ -59,6 +64,11 @@ public double getYaw() {
5964
return this.gyro.getYaw() - this.zero;
6065
}
6166

67+
@Override
68+
public String key() {
69+
return "inav";
70+
}
71+
6272
public interface Gyro {
6373
double getYaw();
6474

Zwerve.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import edu.wpi.first.wpilibj.Timer;
44
import frc.libzodiac.ui.Axis;
55
import frc.libzodiac.util.Vec2D;
6-
import frc.robot.subsystems.Chassis;
76

87
import java.util.ArrayDeque;
98

@@ -12,6 +11,7 @@
1211
*/
1312
public abstract class Zwerve extends Zubsystem implements ZmartDash {
1413
private static final double POS_FIX_KP = 1;
14+
private static final double ROTATION_OUTPUT = 1;
1515
public final Vec2D shape;
1616
/**
1717
* Gyro.
@@ -128,7 +128,6 @@ public Zwerve init() {
128128
* @param rot rotate velocity, CCW positive
129129
*/
130130
public Zwerve go(Vec2D vel, double rot) {
131-
this.debug("pos", ""+Chassis.inav.getPosition());
132131
// direction adjustment
133132
final var curr_yaw = this.yaw.get();
134133
this.debug("desired", this.desired_yaw);
@@ -160,7 +159,7 @@ public Zwerve go(Vec2D vel, double rot) {
160159
final var w = this.shape.y / 2;
161160
Vec2D[] v = { new Vec2D(l, w), new Vec2D(-l, w), new Vec2D(-l, -w), new Vec2D(l, -w) };
162161
for (var i = 0; i < 4; i++) {
163-
v[i] = v[i].rot(Math.PI / 2).with_r(rot).add(vt);
162+
v[i] = v[i].rot(Math.PI / 2).with_r(rot*ROTATION_OUTPUT).add(vt);
164163
}
165164
for (int i = 0; i < 4; i++) {
166165
this.module[i].go(v[i].mul(this.output));

hardware/Pigeon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public double getYaw() {
6363

6464
@Override
6565
public Vec2D getAcceleration() {
66-
return new Vec2D(this.pigeon.getAccelerationX().refresh().getValue(), this.pigeon.getAccelerationY().refresh().getValue());
66+
return new Vec2D(this.pigeon.getAccelerationX().refresh().getValue()-this.pigeon.getGravityVectorX().refresh().getValue(), this.pigeon.getAccelerationY().refresh().getValue()-this.pigeon.getGravityVectorY().refresh().getValue());
6767
}
6868
}

0 commit comments

Comments
 (0)