/
Robot.java
66 lines (56 loc) · 2.28 KB
/
Robot.java
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
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkLowLevel.MotorType;
/**
* This sample program shows how to read basic bus measurements from the SparkMax
*/
public class Robot extends TimedRobot {
/**
* Parameters for the SparkMax are defined below. Be sure to change the deviceID
* and motor type to match your setup.
*/
private static final int deviceID = 1;
private static final MotorType motorType = MotorType.kBrushless;
private CANSparkMax m_motor;
/**
* A single joystick will be used to control motor outputs when the robot is
* enabled.
*/
private static final int kJoystickPort = 0;
private Joystick m_joystick;
@Override
public void robotInit() {
m_motor = new CANSparkMax(deviceID, motorType);
m_joystick = new Joystick(kJoystickPort);
}
@Override
public void robotPeriodic() {
/**
* There are several useful bus measurements you can get from the SparkMax.
* This includes bus voltage (V), output current (A), Applied Output
* (duty cycle), and motor temperature (C)
*/
double busVoltage = m_motor.getBusVoltage();
double current = m_motor.getOutputCurrent();
double appliedOut = m_motor.getAppliedOutput();
double temperature = m_motor.getMotorTemperature();
// Open SmartDashboard when your program is running to see the values
SmartDashboard.putNumber("Bus Voltage", busVoltage);
SmartDashboard.putNumber("Current", current);
SmartDashboard.putNumber("Applied Output", appliedOut);
SmartDashboard.putNumber("Motor Temperature", temperature);
}
@Override
public void teleopPeriodic() {
m_motor.set(m_joystick.getY());
}
}