From 85280067969ea05f6e4f35ff28883a07803370b5 Mon Sep 17 00:00:00 2001 From: "Simon D. Levy" Date: Sun, 7 Sep 2014 20:59:51 -0400 Subject: [PATCH] Create Velocities.hpp --- cpp/Velocities.hpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 cpp/Velocities.hpp diff --git a/cpp/Velocities.hpp b/cpp/Velocities.hpp new file mode 100644 index 0000000..4baf59c --- /dev/null +++ b/cpp/Velocities.hpp @@ -0,0 +1,93 @@ +/** +* +* Velocities.hpp - C++ header for Velocities class +* +* Copyright (C) 2014 Simon D. Levy + +* This code is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This code is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this code. If not, see . +*/ + +#include +#include + +#include +#include +using namespace std; + + +/** +* A class representing the forward and angular velocities of a robot. +*/ +class Velocities +{ + friend class Scan; + +public: + +/** +* Creates a new Velocities object with specified velocities. +*/ +Velocities(double dxy_mm, double dtheta_degrees, double dtSeconds) +{ + this->dxy_mm = dxy_mm; + this->dtheta_degrees = dtheta_degrees; + this->dt_seconds = dtSeconds; +} + +/** +* Creates a new Velocities object with zero velocities. +*/ +Velocities(void) +{ + this->dxy_mm = 0; + this->dtheta_degrees = 0; + this->dt_seconds = 0; +} + + + +/** +* Updates this Velocities object. +* @param dxy_mm new forward distance traveled in millimeters +* @param dtheta_degrees new angular rotation in degrees +* @param dtSeconds time in seconds since last velocities +*/ +void update(double dxy_mm, double dtheta_degrees, double dtSeconds) +{ + double velocity_factor = (dtSeconds > 0) ? (1 / dtSeconds) : 0; + + this->dxy_mm = dxy_mm * velocity_factor; + + this->dtheta_degrees = dtheta_degrees * velocity_factor; +} + +friend ostream& operator<< (ostream & out, Velocities & velocities) +{ + char str[100]; + + sprintf(str, "