Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.hardware.lynx.LynxI2cColorRangeSensor;
  4. import com.qualcomm.robotcore.hardware.ColorSensor;
  5. import com.qualcomm.robotcore.hardware.DcMotor;
  6. import com.qualcomm.robotcore.hardware.HardwareMap;
  7. import com.qualcomm.robotcore.hardware.Servo;
  8. import com.qualcomm.robotcore.util.ElapsedTime;
  9.  
  10. /**
  11. * This is NOT an opmode.
  12. *
  13. * This class can be used to define all the specific hardware for a single robot.
  14. * In this case that robot is a Pushbot.
  15. * See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
  16. *
  17. * This hardware class assumes the following device names have been configured on the robot:
  18. * Note: All names are lower case and some have single spaces between words.
  19. * Motor channel: Manipulator drive motor: " arm"
  20. * Servo channel: Servo to open left claw: "left_hand"
  21. * Servo channel: Servo to open right claw: "right_hand"t
  22. */
  23. public class TestBotNN
  24. {
  25. /* Public OpMode members. */
  26. public DcMotor leftMotor = null;
  27. public DcMotor rightMotor = null;
  28. public LynxI2cColorRangeSensor colorSensor;
  29. public Servo grabberServo;
  30.  
  31. /* local OpMode members. */
  32. HardwareMap hwMap = null;
  33. private ElapsedTime period = new ElapsedTime();
  34.  
  35. /* Constructor */
  36. public TestBotNN(){
  37.  
  38. }
  39.  
  40. /* Initialize standard Hardware interfaces */
  41. public void init(HardwareMap ahwMap) {
  42. // Save reference to Hardware map
  43. hwMap = ahwMap;
  44.  
  45. // Define and Initialize Motors
  46. leftMotor = hwMap.dcMotor.get("left motor");
  47. rightMotor = hwMap.dcMotor.get("right motor");
  48. grabberServo = hwMap.servo.get("grabber servo");
  49. colorSensor = hwMap.get(LynxI2cColorRangeSensor.class, "color sensor");
  50. colorSensor.enableLed(false);
  51. colorSensor.red();
  52. colorSensor.blue();
  53. leftMotor.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
  54. rightMotor.setDirection(DcMotor.Direction.FORWARD);// Set to FORWARD if using AndyMark motors
  55.  
  56. // Set all motors to zero power
  57. leftMotor.setPower(0);
  58. rightMotor.setPower(0);
  59. // Set all motors to run without encoders.
  60. // May want to use RUN_USING_ENCODERS if encoders are installed.
  61. leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  62. rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);;
  63. // rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  64. //leftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  65. }
  66.  
  67. /***
  68. *
  69. * waitForTick implements a periodic delay. However, this acts like a metronome with a regular
  70. * periodic tick. This is used to compensate for varying processing times for each cycle.
  71. * The function looks at the elapsed cycle time, and sleeps for the remaining time interval.
  72. *
  73. * @param periodMs Length of wait cycle in mSec.
  74. */
  75. public void waitForTick(long periodMs) {
  76.  
  77. long remaining = periodMs - (long)period.milliseconds();
  78.  
  79. // sleep for the remaining portion of the regular cycle period.
  80. if (remaining > 0) {
  81. try {
  82. Thread.sleep(remaining);
  83. } catch (InterruptedException e) {
  84. Thread.currentThread().interrupt();
  85. }
  86. }
  87.  
  88. // Reset the cycle clock for the next pass.
  89. period.reset();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement