Advertisement
Guest User

Untitled

a guest
May 30th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1.  
  2. package org.usfirst.frc.team4085.robot;
  3.  
  4. import edu.wpi.first.wpilibj.IterativeRobot;
  5. import edu.wpi.first.wpilibj.command.Command;
  6. import edu.wpi.first.wpilibj.command.Scheduler;
  7. import edu.wpi.first.wpilibj.livewindow.LiveWindow;
  8.  
  9. import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
  10. import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;
  11.  
  12. import edu.wpi.first.wpilibj.RobotDrive.MotorType;
  13. import edu.wpi.first.wpilibj.CANTalon;
  14. import edu.wpi.first.wpilibj.Joystick;
  15. import edu.wpi.first.wpilibj.RobotDrive;
  16. import edu.wpi.first.wpilibj.Solenoid;
  17. import edu.wpi.first.wpilibj.Compressor;
  18. import edu.wpi.first.wpilibj.AnalogInput;
  19. import edu.wpi.first.wpilibj.smartdashboard.*;
  20. import edu.wpi.first.wpilibj.Timer;
  21.  
  22.  
  23.  
  24.  
  25. /**
  26. * The VM is configured to automatically run this class, and to call the
  27. * functions corresponding to each mode, as described in the IterativeRobot
  28. * documentation. If you change the name of this class or the package after
  29. * creating this project, you must also update the manifest file in the resource
  30. * directory.
  31. */
  32. public class Robot extends IterativeRobot {
  33.  
  34. public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
  35. public static OI oi;
  36.  
  37. CANTalon dmotor1 = new CANTalon(1);//Front Left Drive Motor
  38. CANTalon dmotor2 = new CANTalon(2);//Front Right Drive Motor
  39. CANTalon dmotor3 = new CANTalon(3);//Back Left Drive Motor
  40. CANTalon dmotor4 = new CANTalon(4);//Back Right Drive Motor
  41. CANTalon wmotor2 = new CANTalon(5);//Left Wheel Arm
  42. CANTalon wmotor1 = new CANTalon(6);//Right Wheel Arm
  43. CANTalon lmotor1 = new CANTalon(7);//Winch Motor
  44.  
  45. Solenoid solenoid1 = new Solenoid(1); // Left Wheel Arm Solenoid
  46. Solenoid solenoid2 = new Solenoid(2); // Right Wheel Arm Solenoid
  47. Solenoid solenoid3 = new Solenoid(3); // Fork Arm Solenoid
  48. Compressor comp = new Compressor();
  49.  
  50.  
  51.  
  52. RobotDrive rdrive = new RobotDrive(dmotor1,dmotor2,dmotor3,dmotor4);//Defines The Location of The Drive Motors
  53.  
  54. Joystick Xbox = new Joystick(0);// Driver Controls
  55. Joystick lStick = new Joystick(1);//Left Wheel Arm Set Control
  56. Joystick rStick = new Joystick(2);//Right Wheel Arm Set Control
  57.  
  58. Command autonomousCommand;
  59.  
  60. AnalogInput sonar = new AnalogInput(0);// Sonar Sensor
  61. SmartDashboard smart = new SmartDashboard();
  62.  
  63. /**
  64. * This function is run when the robot is first started up and should be
  65. * used for any initialization code.
  66. */
  67. public void robotInit() {
  68. oi = new OI();
  69. // instantiate the command used for the autonomous period
  70. autonomousCommand = new ExampleCommand();
  71.  
  72. //Inverts Right Drive Motors, Needed For Correct Mecanum Code
  73. rdrive.setInvertedMotor(MotorType.kFrontRight, true);
  74. rdrive.setInvertedMotor(MotorType.kRearRight, true);
  75. rdrive.setInvertedMotor(MotorType.kFrontLeft, false);
  76. rdrive.setInvertedMotor(MotorType.kRearLeft, false);
  77.  
  78. /* CameraServer.getInstance().setQuality(1/1000);
  79.  
  80. CameraServer.getInstance().startAutomaticCapture("cam0");
  81. */
  82. }
  83.  
  84. public void disabledPeriodic() {
  85. Scheduler.getInstance().run();
  86. }
  87.  
  88. public void autonomousInit() {
  89. // schedule the autonomous command (example)
  90. if (autonomousCommand != null) autonomousCommand.start();
  91. dmotor1.setPosition(0);
  92. }
  93.  
  94. /**
  95. * This function is called periodically during autonomous
  96. */
  97. public void autonomousPeriodic() {
  98. Scheduler.getInstance().run();
  99. /*smart.putString("Encoder Position", "" + dmotor1.getEncPosition());
  100.  
  101. dmotor1.setPosition(0);
  102.  
  103.  
  104. double P;
  105. P = dmotor1.getEncPosition();
  106. */
  107.  
  108. // Opens All of The Arms
  109. solenoid1.set(true);
  110. //Timer.delay(1);
  111. solenoid2.set(true);
  112. //Timer.delay(1);
  113. solenoid3.set(true);
  114. Timer.delay(.5);
  115.  
  116. //Drive Forward
  117. rdrive.mecanumDrive_Polar(-1, 0, 0);
  118. Timer.delay(.5);
  119. rdrive.mecanumDrive_Polar(-1, 0, 0);
  120. Timer.delay(.5);
  121.  
  122. //if(P <= -475){
  123. //Stop, and Pick up
  124. rdrive.mecanumDrive_Polar(0,0,0);
  125. Timer.delay(.5);
  126. solenoid1.set(false);
  127. //Timer.delay(1);
  128. solenoid2.set(false);
  129. //Timer.delay(1);
  130.  
  131. solenoid3.set(false);
  132. Timer.delay(.5);
  133.  
  134. dmotor1.setPosition(0);
  135.  
  136.  
  137.  
  138.  
  139. // }
  140. //Drive Backward
  141. rdrive.mecanumDrive_Polar(1, 0, 0);
  142. Timer.delay(.5);
  143. rdrive.mecanumDrive_Polar(1, 0, 0);
  144. Timer.delay(.5);
  145. rdrive.mecanumDrive_Polar(1, 0, 0);
  146. Timer.delay(.5);
  147. rdrive.mecanumDrive_Polar(1, 0, 0);
  148. Timer.delay(.5);
  149.  
  150.  
  151.  
  152.  
  153. //if(P > 800){
  154. //Rotate and Drop
  155. rdrive.mecanumDrive_Polar(0, 0, 1);//2 = 60degrees
  156. Timer.delay(.5);
  157. rdrive.mecanumDrive_Polar(0, 0, 1);
  158. Timer.delay(.5);
  159. rdrive.mecanumDrive_Polar(0, 0, 1);
  160. Timer.delay(.5);
  161. rdrive.mecanumDrive_Polar(0, 0, 1);
  162. Timer.delay(.5);
  163. rdrive.mecanumDrive_Polar(0, 0, 0);
  164. Timer.delay(.5);
  165. solenoid1.set(true);
  166. //Timer.delay(1);
  167. solenoid2.set(true);
  168. //Timer.delay(1);
  169. solenoid3.set(true);
  170. Timer.delay(.5);
  171.  
  172. //Back off the Tote
  173. rdrive.mecanumDrive_Polar(1, 0, 0);
  174. Timer.delay(.5);
  175. rdrive.mecanumDrive_Polar(1, 0, 0);
  176. Timer.delay(.5);
  177. rdrive.mecanumDrive_Polar(0, 0, 0);
  178. Timer.delay(.5);
  179.  
  180. //}
  181.  
  182.  
  183.  
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191. public void teleopInit() {
  192. // This makes sure that the autonomous stops running when
  193. // teleop starts running. If you want the autonomous to
  194. // continue until interrupted by another command, remove
  195. // this line or comment it out.
  196. if (autonomousCommand != null) autonomousCommand.cancel();
  197.  
  198.  
  199.  
  200. }
  201.  
  202. /**
  203. * This function is called when the disabled button is hit.
  204. * You can use it to reset subsystems before shutting down.
  205. */
  206. public void disabledInit(){
  207.  
  208. }
  209.  
  210. /**
  211. * This function is called periodically during operator control
  212. */
  213. public void teleopPeriodic() {
  214.  
  215. Scheduler.getInstance().run();
  216.  
  217. //Compressor
  218. comp.start();
  219.  
  220. //Solenoid Control
  221. double X1, X2;
  222.  
  223. X1 = lStick.getX();
  224. X2 = rStick.getX();
  225.  
  226.  
  227. //Left Arm
  228. if(X1 > .5){//Open
  229. solenoid1.set(false);
  230. }
  231.  
  232.  
  233. if(X1 < -.5){//Close
  234. solenoid1.set(true);
  235. }
  236.  
  237.  
  238. //Right Arm
  239. if(X2 > .5){//Close
  240. solenoid2.set(true);
  241. }
  242.  
  243.  
  244. if(X2 < -.5){//Open
  245. solenoid2.set(false);
  246. }
  247.  
  248.  
  249. //Fork Arms
  250. if(lStick.getRawButton(1)){//Close
  251. solenoid3.set(true);
  252. }
  253.  
  254. if(rStick.getRawButton(1)){//Open
  255. solenoid3.set(false);
  256. }
  257.  
  258.  
  259.  
  260. //Lift Control
  261. if(lStick.getRawButton(3)){//Lift Up
  262. lmotor1.set(1);
  263. }
  264.  
  265. if(lStick.getRawButton(2)){//Lift Down
  266. lmotor1.set(-1);
  267. }
  268.  
  269. if(rStick.getRawButton(3)){//Stop Lift
  270. lmotor1.set(0);
  271. }
  272.  
  273.  
  274. //Wheel Motor Control
  275. double Y1, Y2;
  276.  
  277. Y1 = lStick.getY();
  278. Y2 = rStick.getY();
  279.  
  280. wmotor1.set(Y2*-1);
  281. wmotor2.set(Y1*-1);
  282.  
  283. //Drive Control
  284. double X,Y,Z;
  285.  
  286. X = Xbox.getRawAxis(0);
  287. Y = Xbox.getRawAxis(1);
  288. Z = Xbox.getRawAxis(4);
  289.  
  290. //Left Stick Deadzone
  291.  
  292. double mag = Math.sqrt((X*X)+(Y*Y));
  293.  
  294. if(Math.abs(mag) < .3){
  295. mag = 0;
  296. }
  297.  
  298. //Right Stick Deadzone
  299. if(Math.abs(Z) < .3){
  300. Z = 0;
  301. }
  302.  
  303.  
  304.  
  305. //Mecanum Drive Statement
  306. rdrive.mecanumDrive_Polar(mag*-1 , Xbox.getDirectionDegrees(), Z);
  307. }
  308.  
  309. /**
  310. * This function is called periodically during test mode
  311. */
  312. public void testPeriodic() {
  313. LiveWindow.run();
  314. }
  315.  
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement