Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. /* Copyright (c) 2017 FIRST. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted (subject to the limitations in the disclaimer below) provided that
  5. * the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this list
  8. * of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice, this
  11. * list of conditions and the following disclaimer in the documentation and/or
  12. * other materials provided with the distribution.
  13. *
  14. * Neither the name of FIRST nor the names of its contributors may be used to endorse or
  15. * promote products derived from this software without specific prior written permission.
  16. *
  17. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
  18. * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29.  
  30. package org.firstinspires.ftc.teamcode;
  31.  
  32. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  33. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  34. import com.qualcomm.robotcore.hardware.DcMotor;
  35. import com.qualcomm.robotcore.hardware.DcMotorSimple;
  36. import com.qualcomm.robotcore.util.ElapsedTime;
  37. import com.qualcomm.robotcore.hardware.Servo;
  38. import com.qualcomm.robotcore.util.Range;
  39.  
  40. @TeleOp(name="OPMode_Principal_Vijai", group="Linear Opmode")
  41.  
  42. public class OPMode_Principal extends LinearOpMode {
  43.  
  44. // Declaram motoarele si runtime-ul pentru telemetrie
  45.  
  46. private ElapsedTime runtime = new ElapsedTime();
  47. private DcMotor FrontRightMotor = null;
  48. private DcMotor BackRightMotor = null;
  49. private DcMotor FrontLeftMotor = null;
  50. private DcMotor BackLeftMotor = null;
  51. private DcMotor HookMotor1 = null;
  52. private DcMotor HookMotor2 = null;
  53. public Servo Hook = null;
  54. private static double MAX_POWER = 1.0, MIN_POWER = -1.0, NULL_POWER = 0.0;
  55. double pozitie;
  56.  
  57. private void MotorSetter(double BackLeft, double FrontRight, double FrontLeft, double BackRight){
  58. BackLeftMotor.setPower(BackLeft);
  59. FrontRightMotor.setPower(FrontRight);
  60. FrontLeftMotor.setPower(FrontLeft);
  61. BackRightMotor.setPower(BackRight);
  62. }
  63.  
  64. @Override
  65. public void runOpMode() {
  66. telemetry.addData("Status", "Initialized");
  67. telemetry.update();
  68.  
  69. // Initializam motoare cu nume explicite pentru a putea fi selectate eficient la configurare
  70.  
  71. BackLeftMotor = hardwareMap.get(DcMotor.class, "Left_Back");
  72. FrontRightMotor = hardwareMap.get(DcMotor.class, "Right_Front");
  73. FrontLeftMotor = hardwareMap.get(DcMotor.class, "Left_Front");
  74. BackRightMotor = hardwareMap.get(DcMotor.class, "Right_Back");
  75. HookMotor1 = hardwareMap. get(DcMotor.class, "Hook_Motor_1");
  76. HookMotor2 = hardwareMap. get(DcMotor.class, "Hook_Motor_2");
  77. Hook = hardwareMap.get(Servo.class, "Hook_Servo");
  78.  
  79.  
  80. // Datorita regulii maini drepte, inversam motoarele din dreapta si le lasam normale pe cele din dreapta pentru a putea merge drept
  81.  
  82. FrontLeftMotor.setDirection(DcMotor.Direction.FORWARD);
  83. FrontRightMotor.setDirection(DcMotor.Direction.REVERSE);
  84. BackLeftMotor.setDirection(DcMotor.Direction.FORWARD);
  85. BackRightMotor.setDirection(DcMotor.Direction.REVERSE);
  86. HookMotor1.setDirection(DcMotor.Direction.FORWARD);
  87. HookMotor2.setDirection(DcMotor.Direction.FORWARD);
  88.  
  89. // De aici coach-ul apasa start si OpMode-ul va rula pana va apasa stop de pe Driver Station
  90.  
  91. Hook.setPosition(pozitie);
  92.  
  93.  
  94. waitForStart();
  95. runtime.reset();
  96.  
  97.  
  98. if(gamepad2.x)
  99. Hook.setPosition(0.2);
  100. else
  101. Hook.setPosition(0.2);
  102.  
  103.  
  104.  
  105. // Atata timp cat OpMode-ul este activ va rula pana la oprire urmatorul cod
  106. while (opModeIsActive()) {
  107.  
  108. double Drive, Turn, leftPower ,rightPower;
  109.  
  110.  
  111. //Primirea datelor de la joystick-uri
  112. Drive = -gamepad1.left_stick_y;
  113. Turn = gamepad1.right_stick_x;
  114.  
  115.  
  116. //Calcularea puterii redate motoarelor
  117. leftPower = Range.clip(Drive + Turn, -1.0, 1.0) ;
  118. rightPower = Range.clip(Drive - Turn, -1.0, 1.0) ;
  119.  
  120. //Puterile calculte sunt redate motoarelor
  121.  
  122.  
  123. if (gamepad1.a) {
  124.  
  125. BackLeftMotor.setPower(rightPower);
  126. FrontRightMotor.setPower(leftPower);
  127. FrontLeftMotor.setPower(leftPower);
  128. BackRightMotor.setPower(rightPower);
  129.  
  130.  
  131. }
  132. else{
  133. BackLeftMotor.setPower(leftPower);
  134. FrontRightMotor.setPower(rightPower);
  135. FrontLeftMotor.setPower(leftPower);
  136. BackRightMotor.setPower(rightPower);
  137. }
  138.  
  139.  
  140.  
  141. if(gamepad2.a){
  142. HookMotor1.setPower(MAX_POWER);
  143. HookMotor2.setPower(MAX_POWER);
  144.  
  145. }
  146. else{
  147. HookMotor1.setPower(NULL_POWER);
  148. HookMotor2.setPower(NULL_POWER);
  149. }
  150.  
  151. if(gamepad2.y){
  152. HookMotor1.setPower(MIN_POWER);
  153. HookMotor2.setPower(MIN_POWER);
  154. }
  155. else{
  156. HookMotor1.setPower(NULL_POWER);
  157. HookMotor2.setPower(NULL_POWER);
  158. }
  159.  
  160.  
  161. //Setarea puterii pentru diagonale
  162. if(gamepad1.left_trigger!=0){
  163. MotorSetter(MAX_POWER, MAX_POWER, NULL_POWER, NULL_POWER);
  164.  
  165. }
  166.  
  167. if(gamepad1.right_trigger!=0){
  168. MotorSetter(NULL_POWER, NULL_POWER, MAX_POWER, MAX_POWER );
  169.  
  170. }
  171.  
  172. if(gamepad1.left_bumper==true){
  173. MotorSetter(NULL_POWER, NULL_POWER, MIN_POWER, MIN_POWER );
  174.  
  175. }
  176.  
  177. if(gamepad1.right_bumper==true){
  178. MotorSetter(MIN_POWER, MIN_POWER, NULL_POWER, NULL_POWER );
  179.  
  180. }
  181.  
  182.  
  183. // Afisam pe Driver Station timpul in care robotul a rulat si puterea rotilor
  184. telemetry.addData("Status", "Run Time: " + runtime.toString());
  185. telemetry.addData("FrontMotors", "Left (%.2f), Right (%.2f)",leftPower, rightPower);
  186. telemetry.update();
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement