[Documentation] [TitleIndex] [WordIndex

API Examples

   1 sm = StateMachine(['aborted','preempted'])
   2 sm2 = StateMachine(['done'])
   3 sm3 = StateMachine(['done'])
   4 sm4 = StateMachine(['done'])
   5 sm5 = StateMachine(['done'])
   6 
   7 sm5.add('T6',SPAState(),
   8   { 'succeeded':'SETTER',
   9     'aborted':'T6',
  10     'preempted':'SETTER'})
  11 sm5.add('SETTER',Setter(),
  12   { 'done':'done'})
  13 
  14 con_split = ConcurrentSplit(default_outcome = 'succeeded')
  15 con_split.add('SETTER', Setter())
  16 con_split.add('RADICAL',sm5)
  17 con_split.add('GETTER', Getter())
  18 
  19 con_split.add_outcome_map(({'SETTER':'done'},'succeeded'))
  20 
  21 with sm.sequence('done'):
  22   sm.add('GETTER1', Getter())
  23 
  24   sm.add('S2',sm2)
  25   sm2.add('SETTER', Setter(), {'done':'A_SPLIT'})
  26   sm2.add('A_SPLIT', con_split, {'succeeded':'done'})
  27 
  28   sm.add('S3',sm3,{'done':'TRINARY!'})
  29   sm3.add('SETTER', Setter(), {'done':'RADICAL'})
  30   sm3.add('RADICAL', sm4, {'done':'SETTER2'})
  31 
  32   sm4.add('T5',SPAState(),
  33       { 'succeeded':'SETTER',
  34         'aborted':'T5',
  35         'preempted':'SETTER'})
  36   sm4.add('SETTER',Setter(),{'done':'done'})
  37 
  38   sm3.add('SETTER2', Setter(), {'done':'done'})
  39 
  40 sm.add('TRINARY!',SPAState(),
  41     {'succeeded':'T2','aborted':'T3','preempted':'T4'})
  42 
  43 with sm.sequence('succeeded'):
  44   sm.add('T2',SPAState(),{})
  45   sm.add('T3',SPAState(),{'aborted':'S2'})
  46   sm.add('T4',SPAState(),{'succeeded':'GETTER2','aborted':'TRINARY!'})
  47 
  48 sm.add(('GETTER2', Getter(), {'done':'GETTER1'}))
  49 
  50 # Set default initial states
  51 sm.set_initial_state(['GETTER1'],smach.UserData())
  52 sm2.set_initial_state(['SETTER'],smach.UserData())
  53 sm3.set_initial_state(['SETTER'],smach.UserData())
  54 sm4.set_initial_state(['T5'],smach.UserData())
  55 sm5.set_initial_state(['T6'],smach.UserData())

Lexical shadowing of currently "open" smach container

   1 sc = StateMachine(['aborted','preempted'])
   2 sc.set_initial_state(['GETTER1'],scach.UserData())
   3 
   4 with sc.connect_outcomes('done') as sc:
   5   sc.add('GETTER1', Getter())
   6   
   7   with sc.add('S2',StateMachine(['done'])) as sc:
   8     sc.set_initial_state(['SETTER'])
   9     sc.add('SETTER', Setter(), {'done':'A_SPLIT'})
  10 
  11     with sc.add('A_SPLIT',ConcurrentSplit(default_outcome = 'succeeded'), {'succeeded':'done'}) as sc:
  12       sc.add_outcome_map(({'SETTER':'done'},'succeeded'))
  13 
  14       sc.add('SETTER',Setter())
  15       sc.add('GETTER',Getter())
  16       
  17       with sc.add('RADICAL',StateMachine(['done'])) as sc:
  18         sc.add('T6', SPAState(),
  19           { 'succeeded':'SETTER',
  20             'aborted':'T6',
  21             'preempted':'SETTER'})
  22         sc.add('SETTER',Setter(), { 'done':'done'})
  23   
  24   with sc.add('S3',StateMachine(['done']),{'done':'TRINARY!'}) as sc:
  25     sc.add('SETTER', Setter(), {'done':'RADICAL'})
  26     sc.set_initial_state(['SETTER'])
  27 
  28     with sc.add('RADICAL',StateMachine(['done']),{'done':'SETTER2'}) as sc:
  29       sc.set_initial_state(['T5'])
  30       sc.add('T5',SPAState(),
  31           { 'succeeded':'SETTER',
  32             'aborted':'T5',
  33             'preempted':'SETTER'})
  34       sc.add('SETTER',Setter(),{'done':'done'})
  35 
  36     sc.add('SETTER2', Setter(), {'done':'done'})
  37 
  38 sc.add('TRINARY!',SPAState(),
  39     {'succeeded':'T2','aborted':'T3','preempted':'T4'})
  40 
  41 with sc.connect_outcomes('succeeded') as sc:
  42   sc.add('T2',SPAState(),{})
  43   sc.add('T3',SPAState(),{'aborted':'S2'})
  44   sc.add('T4',SPAState(),{'succeeded':'GETTER2','aborted':'TRINARY!'})

Method redirection using modification of smach namespace behavior

   1 sc_root = StateMachine(['aborted','preempted'])
   2 smach.set_initial_state(['GETTER1'],smach.UserData())
   3 
   4 with smach.connect_outcomes('done'):
   5   smach.add('GETTER1', Getter())
   6   
   7   with smach.add('S2',StateMachine(['done'])):
   8     smach.set_initial_state(['SETTER'])
   9     smach.add('SETTER', Setter(), {'done':'A_SPLIT'})
  10 
  11     with smach.add('A_SPLIT',ConcurrentSplit(default_outcome = 'succeeded'), {'succeeded':'done'}):
  12       smach.add_outcome_map(({'SETTER':'done'},'succeeded'))
  13 
  14       smach.add('SETTER',Setter())
  15       smach.add('GETTER',Getter())
  16       
  17       with smach.add('RADICAL',StateMachine(['done'])):
  18         smach.add('T6', SPAState(),
  19           { 'succeeded':'SETTER',
  20             'aborted':'T6',
  21             'preempted':'SETTER'})
  22         smach.add('SETTER',Setter(), { 'done':'done'})
  23   
  24   with smach.add('S3',StateMachine(['done']),{'done':'TRINARY!'}):
  25     smach.add('SETTER', Setter(), {'done':'RADICAL'})
  26     smach.set_initial_state(['SETTER'])
  27 
  28     with smach.add('RADICAL',StateMachine(['done']),{'done':'SETTER2'}):
  29       smach.set_initial_state(['T5'])
  30       smach.add('T5',SPAState(),
  31           { 'succeeded':'SETTER',
  32             'aborted':'T5',
  33             'preempted':'SETTER'})
  34       smach.add('SETTER',Setter(),{'done':'done'})
  35 
  36     smach.add('SETTER2', Setter(), {'done':'done'})
  37 
  38 smach.add('TRINARY!',SPAState(),{'succeeded':'T2','aborted':'T3','preempted':'T4'})
  39 
  40 with smach.connect_outcomes('succeeded'):
  41   smach.add('T2',SPAState(),{})
  42   smach.add('T3',SPAState(),{'aborted':'S2'})
  43   smach.add('T4',SPAState(),{'succeeded':'GETTER2','aborted':'TRINARY!'})

2024-12-07 18:21