Allan Brignoli
/
Rome2_P6
gugus
TaskWait.cpp@0:1a0321f1ffbc, 2018-05-18 (annotated)
- Committer:
- Brignall
- Date:
- Fri May 18 12:18:21 2018 +0000
- Revision:
- 0:1a0321f1ffbc
lala;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Brignall | 0:1a0321f1ffbc | 1 | /* |
Brignall | 0:1a0321f1ffbc | 2 | * TaskWait.cpp |
Brignall | 0:1a0321f1ffbc | 3 | * Copyright (c) 2018, ZHAW |
Brignall | 0:1a0321f1ffbc | 4 | * All rights reserved. |
Brignall | 0:1a0321f1ffbc | 5 | */ |
Brignall | 0:1a0321f1ffbc | 6 | |
Brignall | 0:1a0321f1ffbc | 7 | #include "TaskWait.h" |
Brignall | 0:1a0321f1ffbc | 8 | |
Brignall | 0:1a0321f1ffbc | 9 | using namespace std; |
Brignall | 0:1a0321f1ffbc | 10 | |
Brignall | 0:1a0321f1ffbc | 11 | /** |
Brignall | 0:1a0321f1ffbc | 12 | * Creates a task object that waits for a given duration. |
Brignall | 0:1a0321f1ffbc | 13 | */ |
Brignall | 0:1a0321f1ffbc | 14 | TaskWait::TaskWait(Controller& controller, float duration) : controller(controller) { |
Brignall | 0:1a0321f1ffbc | 15 | |
Brignall | 0:1a0321f1ffbc | 16 | this->duration = duration; |
Brignall | 0:1a0321f1ffbc | 17 | |
Brignall | 0:1a0321f1ffbc | 18 | time = 0.0f; |
Brignall | 0:1a0321f1ffbc | 19 | } |
Brignall | 0:1a0321f1ffbc | 20 | |
Brignall | 0:1a0321f1ffbc | 21 | /** |
Brignall | 0:1a0321f1ffbc | 22 | * Deletes the task object. |
Brignall | 0:1a0321f1ffbc | 23 | */ |
Brignall | 0:1a0321f1ffbc | 24 | TaskWait::~TaskWait() {} |
Brignall | 0:1a0321f1ffbc | 25 | |
Brignall | 0:1a0321f1ffbc | 26 | /** |
Brignall | 0:1a0321f1ffbc | 27 | * This method is called periodically by a task sequencer. |
Brignall | 0:1a0321f1ffbc | 28 | * @param period the period of the task sequencer, given in [s]. |
Brignall | 0:1a0321f1ffbc | 29 | * @return the status of this task, i.e. RUNNING or DONE. |
Brignall | 0:1a0321f1ffbc | 30 | */ |
Brignall | 0:1a0321f1ffbc | 31 | int TaskWait::run(float period) { |
Brignall | 0:1a0321f1ffbc | 32 | |
Brignall | 0:1a0321f1ffbc | 33 | controller.setTranslationalVelocity(0.0f); |
Brignall | 0:1a0321f1ffbc | 34 | controller.setRotationalVelocity(0.0f); |
Brignall | 0:1a0321f1ffbc | 35 | |
Brignall | 0:1a0321f1ffbc | 36 | time += period; |
Brignall | 0:1a0321f1ffbc | 37 | |
Brignall | 0:1a0321f1ffbc | 38 | if (time < duration) { |
Brignall | 0:1a0321f1ffbc | 39 | |
Brignall | 0:1a0321f1ffbc | 40 | return RUNNING; |
Brignall | 0:1a0321f1ffbc | 41 | |
Brignall | 0:1a0321f1ffbc | 42 | } else { |
Brignall | 0:1a0321f1ffbc | 43 | |
Brignall | 0:1a0321f1ffbc | 44 | return DONE; |
Brignall | 0:1a0321f1ffbc | 45 | } |
Brignall | 0:1a0321f1ffbc | 46 | } |
Brignall | 0:1a0321f1ffbc | 47 |