#------------------------------ L4 branch ...leafs
CHARGE_ROBOT_TASK = ServiceTask("CHARGE_ROBOT", result_cb = self.recharge_cb)
NAV_DOCK_TASK = SimpleActionTask("NAV_DOCK_TASK", MoveAction, goal, reset_after=True, feedback_cb=self.update_robot_position)
#------------------------------ L3 branch ... leafs & composites
CHECK_BATTERY = MonitorTask("CHECK_BATTERY", "battert_level", Float32, self.check_battery)
RECHARGE = Sequece("RECHARGE", [ NAV_DOCK_TASK
CHARGE_ROBOT_TASK ] )
TALK_MODE = Sequence( "TALK_MODE" , [ CheckDialogInitLeaf( ),
DialogLeaf( ) ] )
LEARN_COURSE = Sequence ("LEARN_COURSE", [ CheckFollowModeLeaf(),
CheckCourseStatusLeaf(), #already learned? what process is?
LearnCourseLeaf() ] )
OBJECT_RECOG = Sequence("OBJECT_RECOG", [ ObjRecognizeLeaf( ),
RecordLeaf( ) ] ) # if nothing recognized?
#------------------------------ L2 branch
STAY_BATT_HEALTHY = Sequence("STAY_BATT_HLTH", [ CHECK_BATTERY,
RECHARGE ] )
STAY_MCHN_HLTH=Sequence ("STAY_MCHN_HLTH", [ CheckMechnicLeaf( ),
HaveRestLeaf( ) ] )
FACE_RECOG = Sequence("FACE_RECOG", [ FaceDetectLeaf( ),
FaceRecognizeLeaf( ) ] )
CHATTER_MODE = Selector("CHATTER_MODE", [ ChatterRandomLeaf( ),
ReportRandomLeaf( ),
TALK_MODE,
LEARN_COURSE ] )
SELF_LEARN = Sequence("SELF_LEARN", [ CheckEnergyLeaf( ),
OBJECT_RECOG ] )
FOLLOW_MODE = Sequence("FOLLOW_MODE", [ CheckCpLeaf( ),
FollowCpLeaf( ) ] )
PLAY_ALONE = Sequence( "PLAY_ALONE", [ CheckEnergyLeaf( ),
PlayRandom() ] )
HAVE_REST = Sequence ( "HAVe_REST", [ CheckEnergyLeaf( )
HaveRestLeaf( ) ] )
#------------------------------ L1 branch
STAY_HEALTHY = Selector("STAY_HEALTHY", [ STAY_BATT_HEALTHY,
STAY_MCHN_HLTH ] )
SUDDEN_SEE = Sequence("SUDDEN_SEE", [ MotionDetectLeaf( ),
FACE_RECOG
#ObjRecognizeLeaf( )
] )
SUDDEN_HEAR = Sequence("SUDDEN_HEAR", [ SoundEvtDetectLeaf( ),
SoundAnalyzeLeaf( ) ] )
BRAIN_STORM = Selector("BRAIN_STORM", [ CHATTER_MODE,
SELF_LEARN,
SHORE_ARROW ] )
ROBOT_ACTIONS = Selector("ROBOT_ACTIONS", [ FOLLOW_MODE,
PLAY_ALONE,
HAVE_REST ] )
#+++ L1 add
PARALLEL_ROOT.add_child(STAY_HEALTHY)
PARALLEL_ROOT.add_child(SUDDEN_SEE)
PARALLEL_ROOT.add_child(SUDDEN_HEAR)
PARALLEL_ROOT.add_child(BRAIN_STORM)
PARALLEL_ROOT.add_child(ROBOT_ACTIONS)
now I'm feeling easy to add/delete any node once needed with pi_trees now. It's clear and looks close to the tree we drew on paper.
regarding 2), I just see "Selector" and "RandomSelector" shares most of the code but inserting the random to self.children. So is there a way to write RandomSelector(also the one I want "WeightRandomSelector") with @Selector, then write "WeightRandomSelector" with @RandomSelector. Actually I don't understand the python @ well So I asked :-)
Thanks for your patient and help!
Nick Qian
在 2016年8月16日星期二 UTC+8上午10:21:02,Pi Robot写道: