예제 #1
0
def test_chooser_control(nt):

    c = ChooserControl('Autonomous Mode')

    assert c.getChoices() == ()
    assert c.getSelected() is None

    c.setSelected("foo")
    assert c.getSelected() == 'foo'

    t = nt.getTable('/SmartDashboard/Autonomous Mode')
    assert t.getString('selected', None) == 'foo'

    t.putStringArray('options', ('option1', 'option2'))
    assert c.getChoices() == ('option1', 'option2')
예제 #2
0
def test_chooser_control(nt):

    c = ChooserControl("Autonomous Mode", inst=nt)

    assert c.getChoices() == ()
    assert c.getSelected() is None

    c.setSelected("foo")
    assert c.getSelected() == "foo"

    t = nt.getTable("/SmartDashboard/Autonomous Mode")
    assert t.getString("selected", None) == "foo"

    t.putStringArray("options", ("option1", "option2"))
    assert c.getChoices() == ("option1", "option2")
예제 #3
0
def test_chooser_control(nt):

    c = ChooserControl("Autonomous Mode")

    assert c.getChoices() == ()
    assert c.getSelected() is None

    c.setSelected("foo")
    assert c.getSelected() == "foo"

    t = nt.getTable("/SmartDashboard/Autonomous Mode")
    assert t.getString("selected", None) == "foo"

    t.putStringArray("options", ("option1", "option2"))
    assert c.getChoices() == ("option1", "option2")
예제 #4
0
def test_chooser_control(nt):
    
    c = ChooserControl('Autonomous Mode')
    
    assert c.getChoices() == ()
    assert c.getSelected() is None
    
    c.setSelected("foo")
    assert c.getSelected() == 'foo'
    
    t = nt.getTable('/SmartDashboard/Autonomous Mode')
    assert t.getString('selected') == 'foo'
    
    t.putStringArray('options', ('option1', 'option2'))
    assert c.getChoices() == ('option1', 'option2')
    
    
    class AutonomousTester:
        def __init__(self):
            self.initialized = False
            self.init_time = None
            self.chooser = None

            self.state = "auto"
            self.currentChoice = None
            self.until = None

        def initialize_chooser(self, tm):

            if self.chooser is None:
                self.chooser = ChooserControl("Autonomous Mode")

            self.choices = self.chooser.getChoices()
            if len(self.choices) == 0:
                return False

            self.state = "disabled"
            self.currentChoice = -1
            self.until = tm
            self.init_time = tm
            self.initialized = True
            return True

        def on_step(self, tm):

            if not self.initialized:
                if not self.initialize_chooser(tm):
                    assert (
                        tm < 10
                    ), "Robot didn't create a chooser within 10 seconds, probably an error"
                    return True

            if self.state == "auto":
                if tm >= self.until:
                    self.until = tm + 1
                    self.state = "disabled"
                    control.set_operator_control(enabled=False)

            elif self.state == "disabled":
                if tm >= self.until:

                    control.set_autonomous()

                    self.state = "auto"
                    self.until = tm + autonomous_seconds
                    self.currentChoice += 1
                    if self.currentChoice >= len(self.choices):
                        return False

                    self.chooser.setSelected(self.choices[self.currentChoice])

            return True
예제 #6
0
    class AutonomousTester:
        def __init__(self):
            self.initialized = False
            self.init_time = None
            self.chooser = None

            self.state = "auto"
            self.currentChoice = None
            self.until = None

        def initialize_chooser(self, tm):

            if self.chooser is None:
                self.chooser = ChooserControl("Autonomous Mode")

            self.choices = self.chooser.getChoices()
            if len(self.choices) == 0:
                return False

            self.state = "disabled"
            self.currentChoice = -1
            self.until = tm
            self.init_time = tm
            self.initialized = True
            return True

        def on_step(self, tm):

            if not self.initialized:
                if not self.initialize_chooser(tm):
                    assert (
                        tm < 10
                    ), "Robot didn't create a chooser within 10 seconds, probably an error"
                    return True

            if self.state == "auto":
                if tm >= self.until:
                    self.until = tm + 1
                    self.state = "disabled"
                    control.set_operator_control(enabled=False)

            elif self.state == "disabled":
                if tm >= self.until:

                    control.set_autonomous()

                    self.state = "auto"
                    self.until = tm + autonomous_seconds
                    self.currentChoice += 1
                    if self.currentChoice >= len(self.choices):
                        return False

                    self.chooser.setSelected(self.choices[self.currentChoice])

            return True