Skip to content

Commit

Permalink
Add documentation regarding TaskBundles to quickstart-guide.md and ta…
Browse files Browse the repository at this point in the history
…sk-bundle.md
  • Loading branch information
lenalinke committed Apr 27, 2024
1 parent 501e836 commit 96479bc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public AgentBaseTask PickUp(GameObject pickupObject, int priority = 0, SocketId
/// <returns></returns>
public AgentBaseTask GoToAndPickUp(GameObject destinationObject, int priority = 0, SocketId bodyAttachPoint = SocketId.RightHand, float minDistance = 0.3f)
{
AgentMovementTask goToTask = (AgentMovementTask)GoTo(destinationObject, default, priority, true);
// TODO: return this as TaskBundle
AgentMovementTask goToTask = (AgentMovementTask) GoTo(destinationObject, default, priority, true);
goToTask.MinDistance = minDistance;

AgentBaseTask pickUpTask = PickUp(destinationObject, priority, bodyAttachPoint);
Expand Down Expand Up @@ -154,6 +155,7 @@ public AgentBaseTask DropItem(GameObject dropObject = null, int priority = 0)
/// <returns></returns>
public AgentBaseTask GoToAndDropItem(Vector3 destinationCoordinates, GameObject dropObject = null, int priority = 0)
{
// TODO: return this as TaskBundle
AgentBaseTask goToTask = GoTo(destinationCoordinates, priority);
AgentBaseTask dropTask = DropItem(dropObject, priority);
return dropTask;
Expand All @@ -168,6 +170,7 @@ public AgentBaseTask GoToAndDropItem(Vector3 destinationCoordinates, GameObject
/// <returns></returns>
public AgentBaseTask GoToAndDropItem(Transform destinationTransform, GameObject dropObject = null, int priority = 0)
{
// TODO: return this as TaskBundle
AgentBaseTask goToTask = GoTo(destinationTransform, default, priority);
AgentBaseTask dropTask = DropItem(dropObject, priority);
return dropTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override void Start()
// Parameters can be added in brackets on the left side of the arrow
preconditions.Add(() =>
{
// This lambda function checks if the agent is close to the first waypoint
// This lambda function checks if the agent is close to the last waypoint
// If a precondition is not met, the TaskBundle will not be executed
// Compare vectors equality with accuracy of 0.5
float distance = Vector3.Distance(waypoints[waypoints.Count -1].position, agent.transform.position);
Expand All @@ -44,6 +44,7 @@ protected override void Start()
// This TaskBundle will be executed because the agent is not close to the last waypoint
TaskBundle taskBundleSuccess = new TaskBundle(this, tasks, preconditions);


// Create a new TaskBundle with the tasks and preconditions
// This TaskBundle will not be executed
// because after executing the taskBundleSuccess the agent is close to the last waypoint
Expand Down
9 changes: 5 additions & 4 deletions Documentation/manual/quickstart-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ Going from least to most complex, it is recommended to look at the samples in th
1. Navigation Sample
2. Wait Sample
3. Dynamic Navigation Sample
4. Parallel Task Sample ([manual page](parallel-tasks.md))
5. Aiming Sample ([manual page](aiming.md))
6. Adaptive Gaze Sample ([manual page](adaptive-gaze.md))
7. Item Pickup Sample ([manual page](items.md))
4. TaskBundle Sample ([manual page](task-bundle.md))
5. Parallel Task Sample ([manual page](parallel-tasks.md))
6. Aiming Sample ([manual page](aiming.md))
7. Adaptive Gaze Sample ([manual page](adaptive-gaze.md))
8. Item Pickup Sample ([manual page](items.md))

## Customization of agents
To make the application look more appealing from the beginning custom agent models can be used, see [Adding Own Agent Models and Animations](own-agents.md) for that.
47 changes: 47 additions & 0 deletions Documentation/manual/task-bundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# TaskBundles
TaskBundles are a way to group multiple sub-tasks together.
The resulting task bundle can be added to a task system like any other task.
A TaskBundle can also include a list of boolean preconditions.
They are checked beforehand and determine if the TaskBundle prematurely finishes, in the event that one of the preconditions is not met.
Tasks in a TaskBundle are executed back to back in sequence and cannot be interrupted by other tasks.

# Construct a TaskBundle
The are three TaskBundle constructors, that can be used to create a TaskBundle:
1. `TaskBundle(MonoBehaviour coroutineHost)`
2. `TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks)`
3. `TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks, List<Func <bool>> preconditions)`

The `coroutineHost` is the MonoBehaviour that will host the coroutine that executes the TaskBundle.
`tasks` is a list of subtasks. Of note is, that TaskActions cannot be used here, as they would also add the sub-tasks to the regular scheduler.
`preconditions` is a list of boolean functions, so in particular lambda expressions can be used.
Other functions may be evaluated beforehand, so are not suitable for this purpose.
The lambda functions must return a boolean value. `() => {...}` syntax is a lambda expression that defines an anonymous function inline.
Parameters can be added in brackets on the left side of the arrow.

Example:
```csharp
public List<Transform> waypoints;
List<AgentBaseTask> tasks = new List<AgentBaseTask>();
List<System.Func<bool>> preconditions = new List<System.Func<bool>>();
preconditions.Add(() =>
{
// This lambda function checks if the agent is close to the last waypoint
// Compare vectors equality with accuracy of 0.5
float distance = Vector3.Distance(waypoints[waypoints.Count -1].position, agent.transform.position);
return distance > 1.0f;
});
for (int i = 0; i < waypoints.Count; i++)
{
tasks.Add(new AgentMovementTask(waypoints[i].position));
}
TaskBundle myTaskBundle = new TaskBundle(this, tasks, preconditions);
```


# Example Scene

The framework contains one example scene that more comprehensively demonstrates the use of TaskBundles.
In the `TaskBundleSample` the agent attempts to execute two TaskBundles, of which only one's preconditions are met.

The `TaskBundleController` has the option to add multiple waypoints where the agent should walk.
At the end of the execution of the first TaskBundle, the agent is close to the last waypoint, which leads to the precondition of the second bundle to fail.
2 changes: 2 additions & 0 deletions Documentation/manual/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
href: adaptive-gaze.md
- name: Aiming and Pointing
href: aiming.md
- name: TaskBundles
href: task-bundle.md
- name: Customization
items:
- name: Adding Own Agent Models and Animations
Expand Down

0 comments on commit 96479bc

Please sign in to comment.