![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
duration.cpp@1:098e75fd5ad2, 2011-10-16 (annotated)
- Committer:
- nucho
- Date:
- Sun Oct 16 07:17:43 2011 +0000
- Revision:
- 1:098e75fd5ad2
- Parent:
- 0:06fc856e99ca
This program supported the revision of 143 of rosserial.
And the bug fix of receive of array data.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:06fc856e99ca | 1 | /* |
nucho | 0:06fc856e99ca | 2 | * Software License Agreement (BSD License) |
nucho | 0:06fc856e99ca | 3 | * |
nucho | 0:06fc856e99ca | 4 | * Copyright (c) 2011, Willow Garage, Inc. |
nucho | 0:06fc856e99ca | 5 | * All rights reserved. |
nucho | 0:06fc856e99ca | 6 | * |
nucho | 0:06fc856e99ca | 7 | * Redistribution and use in source and binary forms, with or without |
nucho | 0:06fc856e99ca | 8 | * modification, are permitted provided that the following conditions |
nucho | 0:06fc856e99ca | 9 | * are met: |
nucho | 0:06fc856e99ca | 10 | * |
nucho | 0:06fc856e99ca | 11 | * * Redistributions of source code must retain the above copyright |
nucho | 0:06fc856e99ca | 12 | * notice, this list of conditions and the following disclaimer. |
nucho | 0:06fc856e99ca | 13 | * * Redistributions in binary form must reproduce the above |
nucho | 0:06fc856e99ca | 14 | * copyright notice, this list of conditions and the following |
nucho | 0:06fc856e99ca | 15 | * disclaimer in the documentation and/or other materials provided |
nucho | 0:06fc856e99ca | 16 | * with the distribution. |
nucho | 0:06fc856e99ca | 17 | * * Neither the name of Willow Garage, Inc. nor the names of its |
nucho | 0:06fc856e99ca | 18 | * contributors may be used to endorse or promote prducts derived |
nucho | 0:06fc856e99ca | 19 | * from this software without specific prior written permission. |
nucho | 0:06fc856e99ca | 20 | * |
nucho | 0:06fc856e99ca | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
nucho | 0:06fc856e99ca | 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
nucho | 0:06fc856e99ca | 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
nucho | 0:06fc856e99ca | 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
nucho | 0:06fc856e99ca | 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
nucho | 0:06fc856e99ca | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
nucho | 0:06fc856e99ca | 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
nucho | 0:06fc856e99ca | 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nucho | 0:06fc856e99ca | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
nucho | 0:06fc856e99ca | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
nucho | 0:06fc856e99ca | 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
nucho | 0:06fc856e99ca | 32 | * POSSIBILITY OF SUCH DAMAGE. |
nucho | 0:06fc856e99ca | 33 | */ |
nucho | 0:06fc856e99ca | 34 | |
nucho | 1:098e75fd5ad2 | 35 | #include <math.h> |
nucho | 0:06fc856e99ca | 36 | #include "ros/duration.h" |
nucho | 0:06fc856e99ca | 37 | |
nucho | 0:06fc856e99ca | 38 | namespace ros |
nucho | 0:06fc856e99ca | 39 | { |
nucho | 0:06fc856e99ca | 40 | void normalizeSecNSecSigned(long &sec, long &nsec) |
nucho | 0:06fc856e99ca | 41 | { |
nucho | 0:06fc856e99ca | 42 | long nsec_part = nsec; |
nucho | 0:06fc856e99ca | 43 | long sec_part = sec; |
nucho | 0:06fc856e99ca | 44 | |
nucho | 0:06fc856e99ca | 45 | while (nsec_part > 1000000000L) |
nucho | 0:06fc856e99ca | 46 | { |
nucho | 0:06fc856e99ca | 47 | nsec_part -= 1000000000L; |
nucho | 0:06fc856e99ca | 48 | ++sec_part; |
nucho | 0:06fc856e99ca | 49 | } |
nucho | 0:06fc856e99ca | 50 | while (nsec_part < 0) |
nucho | 0:06fc856e99ca | 51 | { |
nucho | 0:06fc856e99ca | 52 | nsec_part += 1000000000L; |
nucho | 0:06fc856e99ca | 53 | --sec_part; |
nucho | 0:06fc856e99ca | 54 | } |
nucho | 0:06fc856e99ca | 55 | sec = sec_part; |
nucho | 0:06fc856e99ca | 56 | nsec = nsec_part; |
nucho | 0:06fc856e99ca | 57 | } |
nucho | 0:06fc856e99ca | 58 | |
nucho | 0:06fc856e99ca | 59 | Duration& Duration::operator+=(const Duration &rhs) |
nucho | 0:06fc856e99ca | 60 | { |
nucho | 0:06fc856e99ca | 61 | sec += rhs.sec; |
nucho | 0:06fc856e99ca | 62 | nsec += rhs.nsec; |
nucho | 0:06fc856e99ca | 63 | normalizeSecNSecSigned(sec, nsec); |
nucho | 0:06fc856e99ca | 64 | return *this; |
nucho | 0:06fc856e99ca | 65 | } |
nucho | 0:06fc856e99ca | 66 | |
nucho | 0:06fc856e99ca | 67 | Duration& Duration::operator-=(const Duration &rhs){ |
nucho | 0:06fc856e99ca | 68 | sec += -rhs.sec; |
nucho | 0:06fc856e99ca | 69 | nsec += -rhs.nsec; |
nucho | 0:06fc856e99ca | 70 | normalizeSecNSecSigned(sec, nsec); |
nucho | 0:06fc856e99ca | 71 | return *this; |
nucho | 0:06fc856e99ca | 72 | } |
nucho | 0:06fc856e99ca | 73 | |
nucho | 0:06fc856e99ca | 74 | Duration& Duration::operator*=(double scale){ |
nucho | 0:06fc856e99ca | 75 | sec *= scale; |
nucho | 0:06fc856e99ca | 76 | nsec *= scale; |
nucho | 0:06fc856e99ca | 77 | normalizeSecNSecSigned(sec, nsec); |
nucho | 0:06fc856e99ca | 78 | return *this; |
nucho | 0:06fc856e99ca | 79 | } |
nucho | 0:06fc856e99ca | 80 | |
nucho | 1:098e75fd5ad2 | 81 | } |