roll11226

drive new new new

Jan 8th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.hardware.DcMotor;
  4.  
  5.  
  6. public class Test_Driving_State_Machine
  7. {
  8. public enum state
  9. {
  10. sIdle,
  11. sDrive
  12. }
  13.  
  14. private static Test_Driving_State_Machine m_instance = null;
  15. private HardWare11226 m_hardware = new HardWare11226();
  16. private state m_state;
  17. private double m_left_power;
  18. private double m_right_power;
  19.  
  20. public Test_Driving_State_Machine()
  21. {
  22. m_hardware = HardWare11226.GetInstance();
  23. m_state = state.sIdle;
  24. }
  25.  
  26. public void init()
  27. {
  28. m_left_power = 0;
  29. m_right_power = 0;
  30. }
  31.  
  32. public void Right_Driving(double p_rightP)
  33. {
  34. m_right_power = p_rightP;
  35.  
  36. m_state = state.sDrive;
  37. }
  38.  
  39. public void left_Driving(double p_leftP)
  40. {
  41. m_left_power = p_leftP;
  42.  
  43. m_state = state.sDrive;
  44. }
  45. public void Pulse()
  46. {
  47. switch (m_state) {
  48.  
  49. case sIdle:
  50. sfIdle();
  51. break;
  52. case sDrive:
  53. sfDrive();
  54. break;
  55.  
  56.  
  57. }
  58. }
  59.  
  60. public static Test_Driving_State_Machine Get_Instance()
  61. {
  62. if(m_instance == null)
  63. m_instance = new Test_Driving_State_Machine();
  64. return m_instance;
  65.  
  66. }
  67.  
  68. private void sfIdle()
  69. {
  70. if (HardWare11226.GetInstance().leftMotor != null)
  71. {
  72. HardWare11226.GetInstance().leftMotor.setPower(0);
  73.  
  74. }
  75. if (HardWare11226.GetInstance().rightMotor != null)
  76. {
  77. HardWare11226.GetInstance().rightMotor.setPower(0);
  78.  
  79. }
  80.  
  81. }
  82.  
  83. private void sfDrive()
  84. {
  85. if (m_hardware.GetInstance().leftMotor != null)
  86. {
  87. m_hardware.GetInstance().leftMotor.setPower(m_left_power);
  88.  
  89. }
  90. if (m_hardware.GetInstance().rightMotor != null)
  91. {
  92. m_hardware.GetInstance().rightMotor.setPower(m_right_power);
  93.  
  94. }
  95. m_state = state.sIdle;
  96. }
  97.  
  98. }
Add Comment
Please, Sign In to add comment