Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaOlio.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: librnr_dynamixel
6 //
7 // File: DynaOlio.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-01-12 10:56:06 -0700 (Mon, 12 Jan 2015) $
12  * $Rev: 3845 $
13  *
14  * \ingroup dyna_lib_hdrs
15  *
16  * \brief Miscellaneous collection of useful utilities.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  *
20  * \copyright
21  * \h_copy 2011-2017. RoadNarrows LLC.\n
22  * http://www.roadnarrows.com\n
23  * All Rights Reserved
24  */
25 /*
26  * @EulaBegin@
27  *
28  * Unless otherwise stated explicitly, all materials contained are copyrighted
29  * and may not be used without RoadNarrows LLC's written consent,
30  * except as provided in these terms and conditions or in the copyright
31  * notice (documents and software) or other proprietary notice provided with
32  * the relevant materials.
33  *
34  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
35  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
36  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
37  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
38  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
39  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
42  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
43  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
44  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
45  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
46  *
47  * @EulaEnd@
48  */
49 ////////////////////////////////////////////////////////////////////////////////
50 
51 #ifndef _DYNA_OLIO_H
52 #define _DYNA_OLIO_H
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/units.h"
56 
57 
58 /*!
59  * \brief Return maximum integer of a and b.
60  *
61  * \param a Integer value a.
62  * \param b Integer value b.
63  *
64  * \return Maximum value.
65  */
66 INLINE_IN_H int imax(int a, int b)
67 {
68  return a>=b? a: b;
69 }
70 
71 /*!
72  * \brief Return minimum integer of a and b.
73  *
74  * \param a Integer value a.
75  * \param b Integer value b.
76  *
77  * \return Minimum value.
78  */
79 INLINE_IN_H int imin(int a, int b)
80 {
81  return a<=b? a: b;
82 }
83 
84 /*!
85  * \brief Return absolute value of a.
86  *
87  * \param a Integer value a.
88  *
89  * \return Absolute value.
90  */
91 INLINE_IN_H int iabs(int a)
92 {
93  return a>=0? a: -a;
94 }
95 
96 /*!
97  * \brief Return value of a within minimum,maximum range.
98  *
99  * \param a Integer value a.
100  * \param m Minimum value of a.
101  * \param M Maximum value of a.
102  *
103  * \return Adjusted value of a in range [m,M].
104  */
105 INLINE_IN_H int irange(int a, int m, int M)
106 {
107  return a<m? m: a>M? M: a;
108 }
109 
110 
111 /*!
112  * \brief a mod b, \h_ge 0.
113  *
114  * param a The dividend.
115  * param b The divisor.
116  *
117  * \return The remainder in [0, b-1].
118  */
119 INLINE_IN_H int imod(int a, int b)
120 {
121  a = a % b;
122  return a >= 0? a: a+b;
123 }
124 
125 /*!
126  * \brief Convert units to short symbol name.
127  *
128  * \param u Units to look up.
129  *
130  * \return Symbol name string.
131  */
132 INLINE_IN_H const char *dynaUnitsSym(units_t u)
133 {
134  return u==units_raw? "": units_shortname(u);
135 }
136 
137 
138 #endif // _DYNA_OLIO_H
INLINE_IN_H const char * dynaUnitsSym(units_t u)
Convert units to short symbol name.
Definition: DynaOlio.h:132
INLINE_IN_H int irange(int a, int m, int M)
Return value of a within minimum,maximum range.
Definition: DynaOlio.h:105
INLINE_IN_H int iabs(int a)
Return absolute value of a.
Definition: DynaOlio.h:91
INLINE_IN_H int imax(int a, int b)
Return maximum integer of a and b.
Definition: DynaOlio.h:66
INLINE_IN_H int imod(int a, int b)
a mod b, &ge; 0.
Definition: DynaOlio.h:119
INLINE_IN_H int imin(int a, int b)
Return minimum integer of a and b.
Definition: DynaOlio.h:79