Skip to content

Commit 898e0c9

Browse files
committed
update configs
1 parent 2d4a8cd commit 898e0c9

File tree

9 files changed

+34
-56
lines changed

9 files changed

+34
-56
lines changed

src/main/deploy/swerve/modules/backleft.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"drive": {
33
"type": "sparkmax_neo",
4-
"id": 7,
4+
"id": 5,
55
"canbus": null
66
},
77
"angle": {
88
"type": "sparkmax_neo",
9-
"id": 8,
9+
"id": 6,
1010
"canbus": null
1111
},
1212
"encoder": {
1313
"type": "cancoder",
14-
"id": 12,
14+
"id": 3,
1515
"canbus": null
1616
},
1717
"inverted": {

src/main/deploy/swerve/modules/backright.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"drive": {
33
"type": "sparkmax_neo",
4-
"id": 5,
4+
"id": 7,
55
"canbus": null
66
},
77
"angle": {
88
"type": "sparkmax_neo",
9-
"id": 6,
9+
"id": 8,
1010
"canbus": null
1111
},
1212
"encoder": {
1313
"type": "cancoder",
14-
"id": 11,
14+
"id": 4,
1515
"canbus": null
1616
},
1717
"inverted": {

src/main/deploy/swerve/modules/frontleft.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"drive": {
33
"type": "sparkmax_neo",
4-
"id": 4,
4+
"id": 1,
55
"canbus": null
66
},
77
"angle": {
88
"type": "sparkmax_neo",
9-
"id": 3,
9+
"id": 2,
1010
"canbus": null
1111
},
1212
"encoder": {
1313
"type": "cancoder",
14-
"id": 9,
14+
"id": 1,
1515
"canbus": null
1616
},
1717
"inverted": {

src/main/deploy/swerve/modules/frontright.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"drive": {
33
"type": "sparkmax_neo",
4-
"id": 2,
4+
"id": 3,
55
"canbus": null
66
},
77
"angle": {
88
"type": "sparkmax_neo",
9-
"id": 1,
9+
"id": 4,
1010
"canbus": null
1111
},
1212
"encoder": {
1313
"type": "cancoder",
14-
"id": 10,
14+
"id": 2,
1515
"canbus": null
1616
},
1717
"inverted": {

src/main/deploy/swerve/modules/physicalproperties.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
22
"conversionFactors": {
3-
"angle": {
4-
"gearRatio": 12.8,
5-
"factor": 0
6-
},
7-
"drive": {
8-
"gearRatio": 8.14,
9-
"diameter": 4,
10-
"factor": 0
11-
}
12-
},
3+
"angle": {"gearRatio": 21.4285714286},
4+
"drive": {"gearRatio": 6.75, "diameter": 4}
5+
},
136
"currentLimit": {
147
"drive": 40,
158
"angle": 20

src/main/java/frc/robot/Constants.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
package frc.robot;
66

7+
import edu.wpi.first.math.geometry.Translation2d;
78
import edu.wpi.first.math.geometry.Translation3d;
8-
import edu.wpi.first.math.util.Units;
99
import swervelib.math.Matter;
1010
import swervelib.math.SwerveMath;
11-
import swervelib.parser.PIDFConfig;
11+
import swervelib.parser.SwerveDriveConfiguration;
1212

1313
/**
1414
* Classe de constantes
@@ -19,12 +19,15 @@ public final class Constants {
1919
public static final class Dimensoes {
2020
// Tempo de loop (sparkMax + normal = 130ms)
2121
public static final double LOOP_TIME = 0.13;
22-
// Massa do robô
22+
// Massa do robô *DEVE SER CONFIGURADO PARA O SEU ROBÔ*
2323
public static final double ROBOT_MASS = 38;
24-
//Velocidade máxima
24+
//Velocidade máxima *DEVE SER CONFIGURADO PARA O SEU ROBÔ*
2525
public static final double MAX_SPEED = 4;
26+
//Posição do módulo mais longe *COLOQUE OS MESMOS VALORES DO JSON*
27+
private static final Translation2d FURTHEST_MODULE_POSE = new Translation2d(MAX_SPEED, LOOP_TIME);
28+
public static final double MAX_ANGULAR_SPEED = SwerveMath.calculateMaxAngularVelocity(MAX_SPEED, FURTHEST_MODULE_POSE.getX(), FURTHEST_MODULE_POSE.getY());
2629

27-
//Posições do centro de massa
30+
//Posições do centro de massa *DEVE SER CONFIGURADO PARA SEU ROBÔ*
2831
private static final double xMass = 0;
2932
private static final double yMass = 0;
3033
private static final double zMass = .08;
@@ -33,16 +36,6 @@ public static final class Dimensoes {
3336
public static final Matter CHASSIS = new Matter(new Translation3d(xMass, yMass, (zMass)), ROBOT_MASS);
3437
}
3538

36-
// Classe que contém os PID para o autônomo
37-
public static final class PID {
38-
// PID para frente e para trás
39-
public static final PIDFConfig xAutoPID = new PIDFConfig(0.65, 0, 0.05);
40-
// PID para esquerda e direita
41-
public static final PIDFConfig yAutoPID = new PIDFConfig(0.6, 0, 0);
42-
// PID de rotação
43-
public static final PIDFConfig angleAutoPID = new PIDFConfig(0.1, 0, 0.01);
44-
}
45-
4639
// Contem a porta em que o controle está
4740
public static final class Controle {
4841
// Porta do controle
@@ -52,11 +45,7 @@ public static final class Controle {
5245
public static final double DEADBAND = 0.2;
5346
}
5447

55-
public static final class Tracao {
56-
// Define se a tração vai ser orientada ao campo (sim = true)
57-
public static final boolean fieldRelative = true;
58-
// false para malha-fechada
59-
public static final boolean isOpenLoop = false;
48+
public static final class SwerveConfigs {
6049
// true para correção de aceleração
6150
public static final boolean accelCorrection = false;
6251
// constante para diminuir o input do joystick (0 < multiplicadorRotacional <= 1)
@@ -68,9 +57,6 @@ public static final class Tracao {
6857

6958
public static final double TURN_CONSTANT = 0.75;
7059

71-
// constante que define a velocidade máxima
72-
public static final double MAX_SPEED = 4.4;
73-
7460
public static final double dt = 0.02;
7561

7662
public static final double constantRotation = 4;

src/main/java/frc/robot/RobotContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public RobotContainer() {
5151

5252
// Função onde os eventos (triggers) são configurados
5353
private void configureBindings() {
54-
controleXbox.a().onTrue(swerve.driveCommandAlignWithJoystick(
54+
controleXbox.a().onTrue(swerve.driveCommandAlinharComJoystick(
5555
() -> MathUtil.applyDeadband(controleXbox.getLeftY(), Constants.Controle.DEADBAND),
5656
() -> MathUtil.applyDeadband(controleXbox.getLeftX(), Constants.Controle.DEADBAND),
5757
() -> controleXbox.getRightX(),

src/main/java/frc/robot/commands/Teleop.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import edu.wpi.first.math.geometry.Translation2d;
1111
import edu.wpi.first.wpilibj2.command.Command;
1212
import frc.robot.Constants.Dimensoes;
13-
import frc.robot.Constants.Tracao;
13+
import frc.robot.Constants.SwerveConfigs;
1414
import frc.robot.subsystems.SwerveSubsystem;
1515
import swervelib.SwerveController;
1616
import swervelib.math.SwerveMath;
@@ -54,24 +54,24 @@ public void initialize()
5454
// Abaixo calculamos os valores de saída a partir dos nossos inputs
5555
@Override
5656
public void execute() {
57-
double xVelocity = y.getAsDouble() * Tracao.multiplicadorTranslacionalY;
58-
double yVelocity = x.getAsDouble() * Tracao.multiplicadorTranslacionalX;
59-
double angVelocity = turn.getAsDouble() * Tracao.multiplicadorRotacional;
57+
double xVelocity = y.getAsDouble() * SwerveConfigs.multiplicadorTranslacionalY;
58+
double yVelocity = x.getAsDouble() * SwerveConfigs.multiplicadorTranslacionalX;
59+
double angVelocity = turn.getAsDouble() * SwerveConfigs.multiplicadorRotacional;
6060

61-
translation = new Translation2d(xVelocity * Tracao.MAX_SPEED, yVelocity * Tracao.MAX_SPEED);
61+
translation = new Translation2d(xVelocity * Dimensoes.MAX_SPEED, yVelocity * Dimensoes.MAX_SPEED);
6262

6363
omega = controller.config.maxAngularVelocity * angVelocity;
6464

6565
// Caso essa função seja verdadeira a aceleração do robô será limitada
66-
if(Tracao.accelCorrection) {
66+
if(SwerveConfigs.accelCorrection) {
6767
translation = SwerveMath.limitVelocity(translation, swerve.getFieldVelocity(), swerve.getPose(),
6868
Dimensoes.LOOP_TIME, Dimensoes.ROBOT_MASS,
6969
List.of(Dimensoes.CHASSIS),
7070
swerve.getSwerveDriveConfiguration());
7171
}
7272

7373
// Aqui temos nossa função definida dentro da classe de subsistema a qual comandara o swerve
74-
swerve.drive(translation, omega, Tracao.fieldRelative);
74+
swerve.drive(translation, omega, true);
7575
}
7676

7777

src/main/java/frc/robot/subsystems/SwerveSubsystem.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import edu.wpi.first.wpilibj2.command.Command;
2323
import edu.wpi.first.wpilibj2.command.SubsystemBase;
2424
import frc.robot.Constants;
25-
import frc.robot.Constants.Tracao;
2625
import swervelib.SwerveController;
2726
import swervelib.SwerveDrive;
2827
import swervelib.telemetry.SwerveDriveTelemetry;
@@ -122,7 +121,7 @@ public void setupPathPlanner() {
122121
}
123122

124123
//Movimenta o robô com o joystick esquerdo, e mira o robo no ângulo no qual o joystick está apontando
125-
public Command driveCommandAlignWithJoystick(DoubleSupplier translationX, DoubleSupplier translationY, DoubleSupplier headingX,
124+
public Command driveCommandAlinharComJoystick(DoubleSupplier translationX, DoubleSupplier translationY, DoubleSupplier headingX,
126125
DoubleSupplier headingY)
127126
{
128127
return run(() -> {
@@ -172,7 +171,7 @@ public ChassisSpeeds getTargetSpeeds(double xInput, double yInput, double headin
172171

173172
public ChassisSpeeds getTargetSpeeds(double xInput, double yInput)
174173
{
175-
return swerveDrive.swerveController.getTargetSpeeds(xInput, yInput, 0, 0, 0, Tracao.MAX_SPEED);
174+
return new ChassisSpeeds(xInput, yInput, 0);
176175
}
177176

178177
// Função que retorna a posição do robô (translação e ângulo), (Usado no autônomo)

0 commit comments

Comments
 (0)