Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.firstinspires.ftc.teamcode;
- import com.qualcomm.robotcore.hardware.DcMotor;
- public class Test_Driving_State_Machine
- {
- public enum state
- {
- sIdle,
- sDrive
- }
- private static Test_Driving_State_Machine m_instance = null;
- private HardWare11226 m_hardware = new HardWare11226();
- private state m_state;
- private double m_left_power;
- private double m_right_power;
- public Test_Driving_State_Machine()
- {
- m_hardware = HardWare11226.GetInstance();
- m_state = state.sIdle;
- }
- public void init()
- {
- m_left_power = 0;
- m_right_power = 0;
- }
- public void Right_Driving(double p_rightP)
- {
- m_right_power = p_rightP;
- m_state = state.sDrive;
- }
- public void left_Driving(double p_leftP)
- {
- m_left_power = p_leftP;
- m_state = state.sDrive;
- }
- public void Pulse()
- {
- switch (m_state) {
- case sIdle:
- sfIdle();
- break;
- case sDrive:
- sfDrive();
- break;
- }
- }
- public static Test_Driving_State_Machine Get_Instance()
- {
- if(m_instance == null)
- m_instance = new Test_Driving_State_Machine();
- return m_instance;
- }
- private void sfIdle()
- {
- if (HardWare11226.GetInstance().leftMotor != null)
- {
- HardWare11226.GetInstance().leftMotor.setPower(0);
- }
- if (HardWare11226.GetInstance().rightMotor != null)
- {
- HardWare11226.GetInstance().rightMotor.setPower(0);
- }
- }
- private void sfDrive()
- {
- if (m_hardware.GetInstance().leftMotor != null)
- {
- m_hardware.GetInstance().leftMotor.setPower(m_left_power);
- }
- if (m_hardware.GetInstance().rightMotor != null)
- {
- m_hardware.GetInstance().rightMotor.setPower(m_right_power);
- }
- m_state = state.sIdle;
- }
- }
Add Comment
Please, Sign In to add comment