-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.java
More file actions
71 lines (57 loc) · 2.46 KB
/
robot.java
File metadata and controls
71 lines (57 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
/** This is a demo program showing how to use Mecanum control with the MecanumDrive class. */
public class Robot extends TimedRobot {
private MecanumDrive m_robotDrive ;
private Joystick stick;
@Override
public void robotInit() {
TalonFX frontLeft = new TalonFX(ConstantID.kFrontLeftChannel);
TalonFX rearLeft = new TalonFX(ConstantID.kRearLeftChannel);
TalonFX frontRight = new TalonFX(ConstantID.kFrontRightChannel);
TalonFX rearRight = new TalonFX(ConstantID.kRearRightChannel);
PWMSparkMax UpperIntake = new PWMSparkMax(kUpperIntake);
PWMSparkMax LowerIntake = new PWMSparkMax(kLowerIntake);
rearRight.setInverted(false);
SendableRegistry.addChild(m_robotDrive, frontLeft);
SendableRegistry.addChild(m_robotDrive, rearLeft);
SendableRegistry.addChild(m_robotDrive, frontRight);
SendableRegistry.addChild(m_robotDrive, rearRight);
// Invert the right side motors.
// You may need to change or remove this to match your robot.
//frontRight.setInverted(true);
m_robotDrive = new MecanumDrive(frontLeft::set, rearLeft::set, frontRight::set, rearRight::set);
stick = new Joystick(ConstantID.kJoystickChannel);
XboxController controller = new XboxController(1);
// motor = new PWMSparkMax(13);
}
@Override
public void teleopPeriodic() {
// Use the joystick Y axis for forward movement, X axis for lateral
// movement, and Z axis for rotation.
double speedMultiplier = 0.5;
m_robotDrive.driveCartesian(-stick.getY()*-1*speedMultiplier, -stick.getZ()*speedMultiplier, -stick.getX()*speedMultiplier);
if (controller.getXButtonPressed){
UpperIntake.set(0.1);
LowerIntake.set(0.1);
} else {
UpperIntake.set(0);
LowerIntake.set(0);
}
// frontRight.setInverted(true);
// rearRight.setInverted(true);
// frontLeft.set(.1);
// rearLeft.set(.1);
// frontRight.set(.1);
// rearRight.set(.1);
}
}