-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into fileconfig-cleanup
- Loading branch information
Showing
51 changed files
with
3,181 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
experimental/C/src/ModalModels/BehaviorTrees/robohub_example_advanced.lf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Implements a modal LF version of the hierarchical statemachine | ||
* for the behavior tree in presented in this article: | ||
* https://robohub.org/introduction-to-behavior-trees/ | ||
* | ||
* Compared to the simple variant this uses modes more extensively, which | ||
* results in the correct behavior. | ||
* Moreover, modeling the sequence in Nominal as modal enables the potential | ||
* use of a history transition that could allow modeling the continuation | ||
* of the task squecnce at the point where it was left when the battery ran out. | ||
*/ | ||
target C { | ||
// logging: debug | ||
} | ||
|
||
reactor GenericTask(name:string("")) { | ||
output success:bool | ||
output failure:bool | ||
|
||
initial mode Running { | ||
// Just for testing | ||
timer work(0, 250msec) | ||
timer finish(1sec, 1sec) | ||
|
||
reaction(work) {= | ||
printf("%s\n", self->name); | ||
=} | ||
|
||
reaction(finish) -> success, Succeeded, failure, Failed {= | ||
int r = rand() % 6; | ||
if (r == 0) { | ||
SET(failure, true); | ||
SET_MODE(Failed); | ||
} else { | ||
SET(success, true); | ||
SET_MODE(Succeeded); | ||
} | ||
=} | ||
} | ||
|
||
mode Succeeded {} | ||
mode Failed {} | ||
} | ||
|
||
reactor NominalBehavior { | ||
input BatteryOK:bool | ||
|
||
output success:bool | ||
output failure:bool | ||
|
||
initial mode MoveToObj { | ||
MoveToObjTask = new GenericTask(name="MoveToObj") | ||
|
||
MoveToObjTask.failure -> failure | ||
|
||
reaction(MoveToObjTask.success) -> CloseGrip {= | ||
SET_MODE(CloseGrip); | ||
=} | ||
} | ||
|
||
mode CloseGrip { | ||
CloseGripTask = new GenericTask(name="CloseGrip") | ||
|
||
CloseGripTask.failure -> failure | ||
|
||
reaction(CloseGripTask.success) -> MoveHome {= | ||
SET_MODE(MoveHome); | ||
=} | ||
} | ||
|
||
mode MoveHome { | ||
MoveHomeTask = new GenericTask(name="MoveHome") | ||
|
||
MoveHomeTask.failure -> failure | ||
|
||
reaction(MoveHomeTask.success) -> success {= | ||
SET(success, true); | ||
=} | ||
} | ||
} | ||
|
||
reactor Robot { | ||
input BatteryOK:bool | ||
|
||
output success:bool | ||
output failure:bool | ||
|
||
initial mode Nominal { | ||
NominalBehavior = new NominalBehavior() | ||
|
||
NominalBehavior.success -> success | ||
NominalBehavior.failure -> failure | ||
|
||
reaction(BatteryOK) -> Charging {= | ||
if (!BatteryOK->value) { | ||
SET_MODE(Charging); | ||
printf("Battery empty\n"); | ||
} | ||
=} | ||
} | ||
|
||
mode Charging { | ||
GoCharge = new GenericTask(name="GoCharge") | ||
|
||
GoCharge.failure -> failure | ||
|
||
reaction(BatteryOK, GoCharge.success) -> Nominal {= | ||
// Assumes simultaneous presence | ||
if (BatteryOK->value && GoCharge.success->value) { | ||
SET_MODE(Nominal); | ||
printf("Battery charged\n"); | ||
} | ||
=} | ||
} | ||
} | ||
|
||
main reactor { | ||
timer Battery(1sec, 1sec) | ||
state battery_state:int(1) | ||
|
||
robot = new Robot() | ||
|
||
reaction(Battery) -> robot.BatteryOK {= | ||
self->battery_state--; | ||
SET(robot.BatteryOK, self->battery_state > 0); | ||
if (self->battery_state <= 0) { | ||
self->battery_state = 5; | ||
} | ||
=} | ||
|
||
reaction(robot.success) {= | ||
printf("Total success\n"); | ||
request_stop(); | ||
=} | ||
|
||
reaction(robot.failure) {= | ||
printf("Utter failure\n"); | ||
request_stop(); | ||
=} | ||
|
||
} |
Oops, something went wrong.