Beispiel #1
0
    def test_sequence(self):
        p = ParallelAnyTask()
        with p:
            ParallelAnyTask.add(TrueTask())
            ParallelAnyTask.add(FalseTask())

        s = SequenceTask()
        with s:
            SequenceTask.add(p)
            SequenceTask.add(FalseTask())

        p2 = ParallelAnyTask()
        with p2:
            ParallelAllTask.add(s)
            ParallelAllTask.add(SleepTask(1.0, succeed=False))

        s2 = SelectorTask()
        with s2:
            SelectorTask.add(p2)
            SelectorTask.add(SleepTask(1.0))

        bt = smach_bt.BehaviorTreeContainer()
        bt.set_root(s2)
        sis = smach_ros.IntrospectionServer('server_name', bt, '/SM_ROOT')
        sis.start()
        wait_start = rospy.Time.now()
        while (rospy.Time.now() -
               wait_start).to_sec() < 10 and not rospy.is_shutdown():
            rospy.sleep(0.1)
            rospy.loginfo("Executing...")
            outcome = bt.execute()
Beispiel #2
0
 def test_preempt(self):
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(SleepTask(1000))
     thread = threading.Thread(name='test_preempt',
                               target=self._preempt_thread,
                               args=(bt, ))
     thread.start()
     self.assertEqual(bt.execute(), 'preempted')
Beispiel #3
0
 def test_run_false(self):
     seq = SequenceTask()
     with seq:
         SequenceTask.add(SleepTask(0.1))
         SequenceTask.add(FalseTask())
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(seq)
     self.assertEqual(bt.execute(), 'aborted')
Beispiel #4
0
 def test_run_true(self):
     seq = SequenceTask()
     with seq:
         SequenceTask.add(SleepTask(0.1))
         SequenceTask.add(TrueTask())
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(seq)
     self.assertEqual(bt.execute(), 'succeeded')
Beispiel #5
0
 def test_remap(self):
     bt = smach_bt.BehaviorTreeContainer()
     seq = smach_bt.SequenceTask(output_keys=['test_key'])
     with seq:
         smach_bt.SequenceTask.add(SetUserDataTask(key="data",
                                                   value="test"),
                                   remapping={'data': 'test_key'})
     bt.set_root(seq)
     self.assertEqual(bt.execute(), 'succeeded')
     self.assertEqual(bt.userdata["test_key"], "test")
Beispiel #6
0
 def test_set(self):
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(SetUserDataTask(key="data", value="test"))
     self.assertEqual(bt.execute(), 'succeeded')
     self.assertEqual(bt.userdata["data"], "test")
Beispiel #7
0
 def test_false(self):
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(FalseTask())
     self.assertEqual(bt.execute(), 'aborted')
Beispiel #8
0
 def test_true(self):
     bt = smach_bt.BehaviorTreeContainer()
     bt.set_root(TrueTask())
     self.assertEqual(bt.execute(), 'succeeded')
Beispiel #9
0
 def test_empty(self):
     bt = smach_bt.BehaviorTreeContainer()
     self.assertRaises(smach.InvalidTransitionError, bt.execute)