Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ROME2_P3 by
TaskMove.cpp
00001 /* 00002 * TaskMove.cpp 00003 * Copyright (c) 2018, ZHAW 00004 * All rights reserved. 00005 */ 00006 00007 #include <cmath> 00008 #include "TaskMove.h" 00009 00010 using namespace std; 00011 00012 const float TaskMove::DEFAULT_DURATION = 3600.0f; 00013 00014 /** 00015 * Creates a task object that moves the robot with given velocities. 00016 * @param conroller a reference to the controller object of the robot. 00017 * @param translationalVelocity the translational velocity, given in [m/s]. 00018 * @param rotationalVelocity the rotational velocity, given in [rad/s]. 00019 */ 00020 TaskMove::TaskMove(Controller& controller, float translationalVelocity, float rotationalVelocity) : controller(controller) { 00021 00022 this->translationalVelocity = translationalVelocity; 00023 this->rotationalVelocity = rotationalVelocity; 00024 this->duration = DEFAULT_DURATION; 00025 00026 time = 0.0f; 00027 } 00028 00029 /** 00030 * Creates a task object that moves the robot with given velocities. 00031 * @param conroller a reference to the controller object of the robot. 00032 * @param translationalVelocity the translational velocity, given in [m/s]. 00033 * @param rotationalVelocity the rotational velocity, given in [rad/s]. 00034 * @param duration the duration to move the robot, given in [s]. 00035 */ 00036 TaskMove::TaskMove(Controller& controller, float translationalVelocity, float rotationalVelocity, float duration) : controller(controller) { 00037 00038 this->translationalVelocity = translationalVelocity; 00039 this->rotationalVelocity = rotationalVelocity; 00040 this->duration = duration; 00041 00042 time = 0.0f; 00043 } 00044 00045 /** 00046 * Deletes the task object. 00047 */ 00048 TaskMove::~TaskMove() {} 00049 00050 /** 00051 * This method is called periodically by a task sequencer. 00052 * @param period the period of the task sequencer, given in [s]. 00053 * @return the status of this task, i.e. RUNNING or DONE. 00054 */ 00055 int TaskMove::run(float period) { 00056 00057 time += period; 00058 00059 if (time < duration) { 00060 00061 controller.setTranslationalVelocity(translationalVelocity); 00062 controller.setRotationalVelocity(rotationalVelocity); 00063 00064 return RUNNING; 00065 00066 } else { 00067 00068 controller.setTranslationalVelocity(0.0f); 00069 controller.setRotationalVelocity(0.0f); 00070 00071 return DONE; 00072 } 00073 } 00074
Generated on Thu Jul 14 2022 22:37:02 by
