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