Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. package org.usfirst.frc.team1807.robot;
  2.  
  3. import edu.wpi.first.wpilibj.*;
  4. import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
  5.  
  6. public class Robot extends IterativeRobot {
  7. //Joysticks
  8. Joystick driveStickRight = new Joystick(0);
  9. Joystick driveStickLeft = new Joystick(1);
  10. Joystick joystickTodd = new Joystick(2);
  11. //Chassis
  12. Talon chassisDriveRight = new Talon(0);
  13. Talon chassisDriveLeft = new Talon(2);
  14.  
  15.  
  16.  
  17. //Collection
  18. Victor collectMotor = new Victor(2);
  19. DigitalInput collectSwitch = new DigitalInput(0);
  20. int collectState = 1;
  21. //Arm
  22. Talon largeArm = new Talon(3);
  23. Talon smallArm = new Talon(4);
  24. AnalogPotentiometer armPot = new AnalogPotentiometer(2);
  25. DigitalInput armSwitch = new DigitalInput(1);
  26. Encoder armEncoder = new Encoder(2, 3, true);
  27. int largeArmPos = 0;
  28. int smallArmPos = 0;
  29. int armEncDown;
  30. int armEncUp;
  31. Double armPotDown;
  32. Double armPotUp;
  33. //Elevator
  34. Talon elevatorMotor = new Talon(5);
  35. AnalogPotentiometer elevatorPot = new AnalogPotentiometer(3);
  36. int elevatorPos = 0;
  37. Double elevatorPotDown;
  38. Double elevatorPotUp;
  39.  
  40. public void robotInit() {
  41. //SmartDashboard.putNumber("Left", driveStickLeft.getRawAxis(1));
  42. //SmartDashboard.putNumber("Right", driveStickRight.getRawAxis(1));
  43. armPotDown = armPot.get();
  44. armPotUp = armPotDown + 0.02;
  45. armEncDown = 0;
  46. armEncUp = 200;
  47. elevatorPotUp = elevatorPot.get();
  48. elevatorPotDown = elevatorPotUp - 0;
  49. }
  50.  
  51. public void autonomousInit() {
  52.  
  53. }
  54.  
  55. public void autonomousPeriodic() {
  56. /*
  57. if (elevatorPot.get() > elevatorPotDown) {
  58. elevatorMotor.set(-0.5);
  59. }
  60. else {
  61. elevatorMotor.set(0);
  62. }
  63. */
  64. }
  65.  
  66. /*** This function is called periodically during operator control*/
  67. public void teleopPeriodic() {
  68. //SmartDashboard.putNumber("Encoder", armEncoder.get());
  69. //Collection System
  70. /*
  71. if (collectState == 1 && !joystickTodd.getRawButton(1)){
  72. collectMotor.set(0);
  73. collectState = 1;
  74. }
  75. else if (collectState == 1 && joystickTodd.getRawButton(1)){
  76. collectMotor.set(0.15);
  77. collectState = 2;
  78. }
  79. else if (collectState == 2 && !collectSwitch.get() && !joystickTodd.getRawButton(9)){
  80. collectMotor.set(0.15);
  81. collectState = 2;
  82. }
  83. else if (collectState == 2 && collectSwitch.get() && !joystickTodd.getRawButton(9)){
  84. collectMotor.set(0);
  85. collectState = 3;
  86. }
  87. else if (collectState == 2 && joystickTodd.getRawButton(9)){
  88. collectMotor.set(0);
  89. collectState = 1;
  90. }
  91. else if (collectState == 3 && joystickTodd.getRawButton(1)){
  92. collectMotor.set(0);
  93. collectState = 3;
  94. }
  95. else if (collectState == 3 && !joystickTodd.getRawButton(1)){
  96. collectMotor.set(0);
  97. collectState = 4;
  98. }
  99. else if (collectState == 4 && !joystickTodd.getRawButton(1)){
  100. collectMotor.set(0);
  101. collectState = 4;
  102. }
  103. else if (collectState == 4 && joystickTodd.getRawButton(1)){
  104. collectMotor.set(-0.15);
  105. collectState = 5;
  106. }
  107. else if (collectState == 5 && joystickTodd.getRawButton(1)){
  108. collectMotor.set(-0.15);
  109. collectState = 5;
  110. }
  111. else if (collectState == 5 && !joystickTodd.getRawButton(1)){
  112. collectMotor.set(0);
  113. collectState = 1;
  114. }
  115.  
  116. if(joystickTodd.getRawButton(4)){
  117. collectMotor.set(1);
  118. }
  119. else if(joystickTodd.getRawButton(2)){
  120. collectMotor.set(-1);
  121. }
  122. else{
  123. collectMotor.set(0);
  124. }
  125. */
  126. //Chassis System
  127.  
  128.  
  129.  
  130. chassisDriveLeft.set(driveStickLeft.getRawAxis(1));
  131. chassisDriveRight.set(driveStickRight.getRawAxis(1));
  132. //Arm Mechanism
  133. //SmartDashboard.putNumber("pot.get()", armPot.get());
  134.  
  135. if(joystickTodd.getRawButton(5)) {
  136. largeArmPos = 1;
  137. }else if(joystickTodd.getRawButton(3)) {
  138. largeArmPos = 2;
  139. }
  140.  
  141.  
  142.  
  143. if(largeArmPos == 1){
  144. if(armPot.get() >= armPotUp) {
  145. largeArmPos = 0;
  146. largeArm.set(0);
  147. } else if (armPot.get() < armPotUp) {
  148. largeArm.set(.5);
  149. } else {
  150. largeArm.set(0);
  151. largeArmPos = 0;
  152. }
  153. } else if (largeArmPos == 2){
  154. if(armPot.get() <= armPotDown){
  155. largeArmPos = 0;
  156. largeArm.set(0);
  157. }else if(armPot.get() > armPotDown){
  158. largeArm.set(-.2);
  159. } else {
  160. largeArm.set(0);
  161. largeArmPos = 0;
  162. }
  163. }
  164.  
  165.  
  166. if (joystickTodd.getRawButton(4)){
  167. smallArmPos = 1;
  168. }
  169. else if (joystickTodd.getRawButton(2)){
  170. smallArmPos = 2;
  171. }
  172.  
  173.  
  174. if (smallArmPos == 1){
  175. if (armEncoder.get() >= armEncUp){
  176. smallArm.set(0);
  177. smallArmPos = 0;
  178. }
  179. else if (armEncoder.get() < armEncUp){
  180. smallArm.set(-0.5);
  181. }
  182. else{
  183. smallArm.set(0);
  184. smallArmPos = 0;
  185. }
  186. }
  187. else if (smallArmPos == 2){
  188. if (armEncoder.get() <= armEncDown){
  189. smallArm.set(0);
  190. smallArmPos = 0;
  191. }
  192. else if (armEncoder.get() > armEncDown){
  193. smallArm.set(0.5);
  194. }
  195. else{
  196. smallArm.set(0);
  197. smallArmPos = 0;
  198. }
  199. }
  200. //Elevator
  201. SmartDashboard.getNumber("pot.get()", elevatorPot.get());
  202. if(joystickTodd.getRawButton(6)){
  203. elevatorPos = 1;
  204. }else if(joystickTodd.getRawButton(7)){
  205. elevatorPos = 2;
  206. }
  207. if(elevatorPos == 1){
  208. if(elevatorPot.get() >= elevatorPotUp) {
  209. elevatorPos = 0;
  210. elevatorMotor.set(0);
  211. }else if(elevatorPot.get() < elevatorPotUp){
  212. elevatorMotor.set(0.2);
  213. }else {
  214. elevatorMotor.set(0);
  215. elevatorPos = 0;
  216. }
  217. }
  218.  
  219. else if(elevatorPos == 2){
  220. if (elevatorPot.get() <= elevatorPotDown){
  221. elevatorPos = 0;
  222. elevatorMotor.set(0);
  223. }else if(elevatorPot.get() > elevatorPotDown){
  224. elevatorMotor.set(-0.2);
  225. }else {
  226. elevatorMotor.set(0);
  227. elevatorPos = 0;
  228. }
  229. }
  230.  
  231. //Dashboard
  232. //SmartDashboard.putNumber("Left", driveStickLeft.getRawAxis(1));
  233. //SmartDashboard.putNumber("Right", driveStickRight.getRawAxis(1));
  234. }
  235.  
  236. /*** This function is called periodically during test mode*/
  237. public void testPeriodic() {
  238.  
  239. }
  240.  
  241. public void print(String key, boolean value){
  242. SmartDashboard.putBoolean(key, value);
  243. }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement