Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  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. * Motor channel: Manipulator drive motor: " arm"
  19. * Servo channel: Servo to open left claw: "left_hand"
  20. * Servo channel: Servo to open right claw: "right_hand"t
  21. */
  22. public class TestBotNN
  23. {
  24. /* Public OpMode members. */
  25. public DcMotor leftMotor = null;
  26. public DcMotor rightMotor = null;
  27. public ColorSensor colorSensor1;
  28. public Servo grabberServo;
  29.  
  30. /* local OpMode members. */
  31. HardwareMap hwMap = null;
  32. private ElapsedTime period = new ElapsedTime();
  33.  
  34. /* Constructor */
  35. public TestBotNN(){
  36.  
  37. }
  38.  
  39. /* Initialize standard Hardware interfaces */
  40. public void init(HardwareMap ahwMap) {
  41. // Save reference to Hardware map
  42. hwMap = ahwMap;
  43.  
  44. // Define and Initialize Motors
  45. leftMotor = hwMap.dcMotor.get("left motor");
  46. rightMotor = hwMap.dcMotor.get("right motor");
  47. grabberServo = hwMap.servo.get("grabber servo");
  48. colorSensor1 = hwMap.colorSensor.get("color sensor 1");
  49. colorSensor1.enableLed(false);
  50. leftMotor.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
  51. rightMotor.setDirection(DcMotor.Direction.FORWARD);// Set to FORWARD if using AndyMark motors
  52.  
  53. // Set all motors to zero power
  54. leftMotor.setPower(0);
  55. rightMotor.setPower(0);
  56. // Set all motors to run without encoders.
  57. // May want to use RUN_USING_ENCODERS if encoders are installed.
  58. leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  59. rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);;
  60. // rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  61. //leftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  62. }
  63.  
  64. /***
  65. *
  66. * waitForTick implements a periodic delay. However, this acts like a metronome with a regular
  67. * periodic tick. This is used to compensate for varying processing times for each cycle.
  68. * The function looks at the elapsed cycle time, and sleeps for the remaining time interval.
  69. *
  70. * @param periodMs Length of wait cycle in mSec.
  71. */
  72. public void waitForTick(long periodMs) {
  73.  
  74. long remaining = periodMs - (long)period.milliseconds();
  75.  
  76. // sleep for the remaining portion of the regular cycle period.
  77. if (remaining > 0) {
  78. try {
  79. Thread.sleep(remaining);
  80. } catch (InterruptedException e) {
  81. Thread.currentThread().interrupt();
  82. }
  83. }
  84.  
  85. // Reset the cycle clock for the next pass.
  86. period.reset();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement