-
Notifications
You must be signed in to change notification settings - Fork 0
/
robots
146 lines (120 loc) · 4.99 KB
/
robots
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package frc.robot
import edu.wpi.first.wpilibj.TimedRobot
import edu.wpi.first.wpilibj.XboxController
import edu.wpi.first.wpilibj2.command.Command
import com.revrobotics.CANSparkMax
import com.revrobotics.CANSparkMaxLowLevel
import edu.wpi.first.networktables.NetworkTable
import edu.wpi.first.networktables.NetworkTableInstance
import edu.wpi.first.wpilibj2.command.CommandScheduler
import kotlin.math.abs
/**
* The VM is configured to automatically run this object (which basically functions as a singleton class),
* and to call the functions corresponding to each mode, as described in the TimedRobot documentation.
* This is written as an object rather than a class since there should only ever be a single instance, and
* it cannot take any constructor arguments. This makes it a natural fit to be an object in Kotlin.
*
* If you change the name of this object or its package after creating this project, you must also update
* the `Main.kt` file in the project. (If you use the IDE's Rename or Move refactorings when renaming the
* object or package, it will get changed everywhere.)
*/
object Robot : TimedRobot()
{
/** The autonomous command to run. It is set in [autonomousInit]. */
private var autonomousCommand: Command? = null
private var controller0: XboxController = XboxController(0)
private var leftSide: CANSparkMax = CANSparkMax(1, CANSparkMaxLowLevel.MotorType.kBrushless) // idk about this
private var rightSide: CANSparkMax = CANSparkMax(2, CANSparkMaxLowLevel.MotorType.kBrushless) // idk about this
var NTTable: NetworkTable = NetworkTableInstance.getDefault().getTable("randomshit")
/**
* This method is run when the robot is first started up and should be used for any
* initialization code.
*/
override fun robotInit()
{
// Access the RobotContainer object so that it is initialized
RobotContainer
}
/**
* This method is called every robot packet, no matter the mode. Use this for items like
* diagnostics that you want ran during disabled, autonomous, teleoperated and test.
*
* This runs after the mode specific periodic methods, but before LiveWindow and
* SmartDashboard integrated updating.
*/
override fun robotPeriodic()
{
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run()
}
/** This method is called once each time the robot enters Disabled mode. */
override fun disabledInit()
{
}
override fun disabledPeriodic()
{
}
/** This autonomous runs the autonomous command selected by your [RobotContainer] class. */
override fun autonomousInit()
{
// We store the command as a Robot property in the rare event that the selector on the dashboard
// is modified while the command is running since we need to access it again in teleopInit()
autonomousCommand = RobotContainer.selectedAutonomousCommand
autonomousCommand?.schedule()
}
/** This method is called periodically during autonomous. */
override fun autonomousPeriodic()
{
}
override fun teleopInit()
{
// This makes sure that the autonomous stops running when teleop starts running. If you want the
// autonomous to continue until interrupted by another command, remove this line or comment it out.
autonomousCommand?.cancel()
}
/** This method is called periodically during operator control. */
override fun teleopPeriodic()
{
val x = controller0.leftX
val y = controller0.leftY
var rightVoltage = 0.0
var leftVoltage = 0.0
val difference = 2 - abs(x)
if (x > -0.9 && x < 0.9){
rightVoltage = y
leftVoltage = y
} else if (y > -0.9 && y < 0.9) {
rightVoltage = -x
leftVoltage = x
} else if (y < 0 && x > 0) {
rightVoltage = y * difference
leftVoltage = y * abs(x)
}
else if (y < 0 && x < 0) {
rightVoltage = y * abs(x)
leftVoltage = y * difference
}
else if (y > 0 && x > 0) {
rightVoltage = -y * difference
leftVoltage = -y * abs(x)
}
else if (y > 0 && x < 0) {
rightVoltage = -y * abs(x)
leftVoltage = -y * difference
}
rightSide.setVoltage(leftVoltage * 6)
leftSide.setVoltage(rightVoltage * 6)
}
override fun testInit()
{
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll()
}
/** This method is called periodically during test mode. */
override fun testPeriodic()
{
}
}