Advertisement
DeadPixeI

HardwarePushbot (Hardware Initialize class)

Jan 19th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. package org.firstinspires.ftc.robotcontroller.external.samples;
  2.  
  3. import com.qualcomm.robotcore.hardware.ColorSensor;
  4. import com.qualcomm.robotcore.hardware.DcMotor;
  5. import com.qualcomm.robotcore.hardware.HardwareMap;
  6. import com.qualcomm.robotcore.hardware.Servo;
  7. import com.qualcomm.robotcore.util.ElapsedTime;
  8.  
  9. /**
  10. * This is NOT an opmode.
  11. *
  12. * This class can be used to define all the specific hardware for a single robot.
  13. * In this case that robot is a Pushbot.
  14. * See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
  15. *
  16. * This hardware class assumes the following device names have been configured on the robot:
  17. * Note: All names are lower case and some have single spaces between words.
  18. *
  19. * Motor channel: Left drive motor: "left_drive"
  20. * Motor channel: Right drive motor: "right_drive"
  21. * Motor channel: Manipulator drive motor: "left_arm"
  22. * Servo channel: Servo to open left claw: "left_hand"
  23. * Servo channel: Servo to open right claw: "right_hand"
  24. */
  25. public class HardwarePushbot
  26. {
  27. /* Public OpMode members. */
  28. public DcMotor leftMotor = null;
  29. public DcMotor rightMotor = null;
  30. public DcMotor armMotor = null;
  31. public DcMotor arm2Motor = null;
  32.  
  33. public DcMotor leftShooter = null; //This is for the shooter motors
  34. public DcMotor rightShooter = null; //This is for the shooter motors
  35.  
  36. public DcMotor liftLeft = null; //This is for the left side that moves the yoga ball lift
  37. public DcMotor liftRight = null; //This is for the right side that moves the yoga ball lift
  38.  
  39. public Servo ballPusher = null; //This is for the pusher thing that pushes the ball into the shooter
  40. public Servo liftHolder = null; //This is for the servo that pushes the button on the beacon
  41.  
  42. public Servo liftArmLeft = null; //This is for the left arm connected to the servo to grab onto the yoga ball
  43. public Servo liftArmRight = null; //This is for the right arm connected to the servo to grab onto the yoga ball.
  44.  
  45. public ColorSensor beaconSensor = null;
  46.  
  47. public static final double MID_SERVO = 1.0 ;
  48. public static final double ARM_UP_POWER = 0.45 ;
  49. public static final double ARM_DOWN_POWER = -0.45 ;
  50.  
  51. /* local OpMode members. */
  52. HardwareMap hwMap = null;
  53. private ElapsedTime period = new ElapsedTime();
  54.  
  55. /* Constructor */
  56. public HardwarePushbot(){
  57.  
  58. }
  59.  
  60. /* Initialize standard Hardware interfaces */
  61. public void init(HardwareMap ahwMap) {
  62. // Save reference to Hardware map
  63. hwMap = ahwMap;
  64.  
  65. // Define and Initialize Motors
  66. leftMotor = hwMap.dcMotor.get("left_drive");
  67. rightMotor = hwMap.dcMotor.get("right_drive");
  68.  
  69. armMotor = hwMap.dcMotor.get("left_arm");
  70. //arm2Motor = hwMap.dcMotor.get("right_arm");
  71.  
  72. leftShooter = hwMap.dcMotor.get("left_drive2");
  73. rightShooter = hwMap.dcMotor.get("right_drive2");
  74.  
  75. liftLeft = hwMap.dcMotor.get("lift_left");
  76. liftRight = hwMap.dcMotor.get("lift_right");
  77.  
  78. // Define and Initialize Servos
  79. ballPusher = hwMap.servo.get("left_hand");
  80. liftHolder = hwMap.servo.get("right_hand");
  81.  
  82.  
  83.  
  84. //Define and Initialize Sensors
  85. beaconSensor = hwMap.colorSensor.get("colorSensor");
  86.  
  87.  
  88. leftMotor.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
  89. rightMotor.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors
  90.  
  91. // Set all motors to zero power
  92. leftMotor.setPower(0);
  93. rightMotor.setPower(0);
  94. armMotor.setPower(0);
  95. leftShooter.setPower(0);
  96. rightShooter.setPower(0);
  97.  
  98. // Set all motors to run without encoders.
  99. // May want to use RUN_USING_ENCODERS if encoders are installed.
  100. leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  101. rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  102. //armMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  103.  
  104. // Define and initialize ALL installed servos.
  105. //leftClaw = hwMap.servo.get("left_hand");
  106. //rightClaw = hwMap.servo.get("right_hand");
  107. //leftClaw.setPosition(MID_SERVO);
  108. //rightClaw.setPosition(MID_SERVO);
  109. }
  110.  
  111. /***
  112. *
  113. * waitForTick implements a periodic delay. However, this acts like a metronome with a regular
  114. * periodic tick. This is used to compensate for varying processing times for each cycle.
  115. * The function looks at the elapsed cycle time, and sleeps for the remaining time interval.
  116. *
  117. * @param periodMs Length of wait cycle in mSec.
  118. */
  119. public void waitForTick(long periodMs) {
  120.  
  121. long remaining = periodMs - (long)period.milliseconds();
  122.  
  123. // sleep for the remaining portion of the regular cycle period.
  124. if (remaining > 0) {
  125. try {
  126. Thread.sleep(remaining);
  127. } catch (InterruptedException e) {
  128. Thread.currentThread().interrupt();
  129. }
  130. }
  131.  
  132. // Reset the cycle clock for the next pass.
  133. period.reset();
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement