Zürcher Eliteeinheit / Mbed 2 deprecated ROME2_P4

Dependencies:   ROME2_P2 mbed

Fork of ROME2_P3 by Zürcher Eliteeinheit

Committer:
matajarb
Date:
Thu Apr 26 12:22:58 2018 +0000
Revision:
6:67263dc2c2cf
s?mme du schluch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matajarb 6:67263dc2c2cf 1 /*
matajarb 6:67263dc2c2cf 2 * TaskMove.cpp
matajarb 6:67263dc2c2cf 3 * Copyright (c) 2018, ZHAW
matajarb 6:67263dc2c2cf 4 * All rights reserved.
matajarb 6:67263dc2c2cf 5 */
matajarb 6:67263dc2c2cf 6
matajarb 6:67263dc2c2cf 7 #include <cmath>
matajarb 6:67263dc2c2cf 8 #include "TaskMove.h"
matajarb 6:67263dc2c2cf 9
matajarb 6:67263dc2c2cf 10 using namespace std;
matajarb 6:67263dc2c2cf 11
matajarb 6:67263dc2c2cf 12 const float TaskMove::DEFAULT_DURATION = 3600.0f;
matajarb 6:67263dc2c2cf 13
matajarb 6:67263dc2c2cf 14 /**
matajarb 6:67263dc2c2cf 15 * Creates a task object that moves the robot with given velocities.
matajarb 6:67263dc2c2cf 16 * @param conroller a reference to the controller object of the robot.
matajarb 6:67263dc2c2cf 17 * @param translationalVelocity the translational velocity, given in [m/s].
matajarb 6:67263dc2c2cf 18 * @param rotationalVelocity the rotational velocity, given in [rad/s].
matajarb 6:67263dc2c2cf 19 */
matajarb 6:67263dc2c2cf 20 TaskMove::TaskMove(Controller& controller, float translationalVelocity, float rotationalVelocity) : controller(controller) {
matajarb 6:67263dc2c2cf 21
matajarb 6:67263dc2c2cf 22 this->translationalVelocity = translationalVelocity;
matajarb 6:67263dc2c2cf 23 this->rotationalVelocity = rotationalVelocity;
matajarb 6:67263dc2c2cf 24 this->duration = DEFAULT_DURATION;
matajarb 6:67263dc2c2cf 25
matajarb 6:67263dc2c2cf 26 time = 0.0f;
matajarb 6:67263dc2c2cf 27 }
matajarb 6:67263dc2c2cf 28
matajarb 6:67263dc2c2cf 29 /**
matajarb 6:67263dc2c2cf 30 * Creates a task object that moves the robot with given velocities.
matajarb 6:67263dc2c2cf 31 * @param conroller a reference to the controller object of the robot.
matajarb 6:67263dc2c2cf 32 * @param translationalVelocity the translational velocity, given in [m/s].
matajarb 6:67263dc2c2cf 33 * @param rotationalVelocity the rotational velocity, given in [rad/s].
matajarb 6:67263dc2c2cf 34 * @param duration the duration to move the robot, given in [s].
matajarb 6:67263dc2c2cf 35 */
matajarb 6:67263dc2c2cf 36 TaskMove::TaskMove(Controller& controller, float translationalVelocity, float rotationalVelocity, float duration) : controller(controller) {
matajarb 6:67263dc2c2cf 37
matajarb 6:67263dc2c2cf 38 this->translationalVelocity = translationalVelocity;
matajarb 6:67263dc2c2cf 39 this->rotationalVelocity = rotationalVelocity;
matajarb 6:67263dc2c2cf 40 this->duration = duration;
matajarb 6:67263dc2c2cf 41
matajarb 6:67263dc2c2cf 42 time = 0.0f;
matajarb 6:67263dc2c2cf 43 }
matajarb 6:67263dc2c2cf 44
matajarb 6:67263dc2c2cf 45 /**
matajarb 6:67263dc2c2cf 46 * Deletes the task object.
matajarb 6:67263dc2c2cf 47 */
matajarb 6:67263dc2c2cf 48 TaskMove::~TaskMove() {}
matajarb 6:67263dc2c2cf 49
matajarb 6:67263dc2c2cf 50 /**
matajarb 6:67263dc2c2cf 51 * This method is called periodically by a task sequencer.
matajarb 6:67263dc2c2cf 52 * @param period the period of the task sequencer, given in [s].
matajarb 6:67263dc2c2cf 53 * @return the status of this task, i.e. RUNNING or DONE.
matajarb 6:67263dc2c2cf 54 */
matajarb 6:67263dc2c2cf 55 int TaskMove::run(float period) {
matajarb 6:67263dc2c2cf 56
matajarb 6:67263dc2c2cf 57 time += period;
matajarb 6:67263dc2c2cf 58
matajarb 6:67263dc2c2cf 59 if (time < duration) {
matajarb 6:67263dc2c2cf 60
matajarb 6:67263dc2c2cf 61 controller.setTranslationalVelocity(translationalVelocity);
matajarb 6:67263dc2c2cf 62 controller.setRotationalVelocity(rotationalVelocity);
matajarb 6:67263dc2c2cf 63
matajarb 6:67263dc2c2cf 64 return RUNNING;
matajarb 6:67263dc2c2cf 65
matajarb 6:67263dc2c2cf 66 } else {
matajarb 6:67263dc2c2cf 67
matajarb 6:67263dc2c2cf 68 controller.setTranslationalVelocity(0.0f);
matajarb 6:67263dc2c2cf 69 controller.setRotationalVelocity(0.0f);
matajarb 6:67263dc2c2cf 70
matajarb 6:67263dc2c2cf 71 return DONE;
matajarb 6:67263dc2c2cf 72 }
matajarb 6:67263dc2c2cf 73 }
matajarb 6:67263dc2c2cf 74