ros melodic library with custom message

Dependents:   Robot_team1_QEI_Douglas Robot_team1

Committer:
florine_van
Date:
Tue Nov 12 13:54:52 2019 +0000
Revision:
1:afa33e06a2ca
Parent:
0:020db18a476d
Remove errors from library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scarter1 0:020db18a476d 1 /*
scarter1 0:020db18a476d 2 * Software License Agreement (BSD License)
scarter1 0:020db18a476d 3 *
scarter1 0:020db18a476d 4 * Copyright (c) 2011, Willow Garage, Inc.
scarter1 0:020db18a476d 5 * All rights reserved.
scarter1 0:020db18a476d 6 *
scarter1 0:020db18a476d 7 * Redistribution and use in source and binary forms, with or without
scarter1 0:020db18a476d 8 * modification, are permitted provided that the following conditions
scarter1 0:020db18a476d 9 * are met:
scarter1 0:020db18a476d 10 *
scarter1 0:020db18a476d 11 * * Redistributions of source code must retain the above copyright
scarter1 0:020db18a476d 12 * notice, this list of conditions and the following disclaimer.
scarter1 0:020db18a476d 13 * * Redistributions in binary form must reproduce the above
scarter1 0:020db18a476d 14 * copyright notice, this list of conditions and the following
scarter1 0:020db18a476d 15 * disclaimer in the documentation and/or other materials provided
scarter1 0:020db18a476d 16 * with the distribution.
scarter1 0:020db18a476d 17 * * Neither the name of Willow Garage, Inc. nor the names of its
scarter1 0:020db18a476d 18 * contributors may be used to endorse or promote prducts derived
scarter1 0:020db18a476d 19 * from this software without specific prior written permission.
scarter1 0:020db18a476d 20 *
scarter1 0:020db18a476d 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
scarter1 0:020db18a476d 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
scarter1 0:020db18a476d 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
scarter1 0:020db18a476d 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
scarter1 0:020db18a476d 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
scarter1 0:020db18a476d 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
scarter1 0:020db18a476d 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
scarter1 0:020db18a476d 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
scarter1 0:020db18a476d 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
scarter1 0:020db18a476d 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
scarter1 0:020db18a476d 31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
scarter1 0:020db18a476d 32 * POSSIBILITY OF SUCH DAMAGE.
scarter1 0:020db18a476d 33 */
scarter1 0:020db18a476d 34
scarter1 0:020db18a476d 35 #ifndef ROS_TIME_H_
scarter1 0:020db18a476d 36 #define ROS_TIME_H_
scarter1 0:020db18a476d 37
scarter1 0:020db18a476d 38 #include "ros/duration.h"
scarter1 0:020db18a476d 39 #include <math.h>
scarter1 0:020db18a476d 40 #include <stdint.h>
scarter1 0:020db18a476d 41
scarter1 0:020db18a476d 42 namespace ros
scarter1 0:020db18a476d 43 {
florine_van 1:afa33e06a2ca 44 void normalizeSecNSec(uint32_t &sec, uint32_t &nsec);
scarter1 0:020db18a476d 45
florine_van 1:afa33e06a2ca 46 class Time
florine_van 1:afa33e06a2ca 47 {
florine_van 1:afa33e06a2ca 48 public:
florine_van 1:afa33e06a2ca 49 uint32_t sec, nsec;
florine_van 1:afa33e06a2ca 50
florine_van 1:afa33e06a2ca 51 Time() : sec(0), nsec(0) {}
florine_van 1:afa33e06a2ca 52 Time(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec)
florine_van 1:afa33e06a2ca 53 {
florine_van 1:afa33e06a2ca 54 normalizeSecNSec(sec, nsec);
florine_van 1:afa33e06a2ca 55 }
scarter1 0:020db18a476d 56
florine_van 1:afa33e06a2ca 57 double round(double number) { return number < 0.0 ? ceil(number - 0.5): floor(number + 0.5); }
florine_van 1:afa33e06a2ca 58 double toSec() const { return (double)sec + 1e-9*(double)nsec; };
florine_van 1:afa33e06a2ca 59 void fromSec(double t) { sec = (uint32_t) floor(t); nsec = (uint32_t) round((t-sec) * 1e9); };
scarter1 0:020db18a476d 60
florine_van 1:afa33e06a2ca 61 uint32_t toNsec() { return (uint32_t)sec*1000000000ull + (uint32_t)nsec; };
florine_van 1:afa33e06a2ca 62 Time& fromNSec(int32_t t);
florine_van 1:afa33e06a2ca 63
florine_van 1:afa33e06a2ca 64 Time& operator +=(const Duration &rhs);
florine_van 1:afa33e06a2ca 65 Time& operator -=(const Duration &rhs);
florine_van 1:afa33e06a2ca 66
florine_van 1:afa33e06a2ca 67 static Time now();
florine_van 1:afa33e06a2ca 68 static void setNow( Time & new_now);
scarter1 0:020db18a476d 69 };
scarter1 0:020db18a476d 70
scarter1 0:020db18a476d 71 }
scarter1 0:020db18a476d 72
scarter1 0:020db18a476d 73 #endif