-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathjoints.h
More file actions
175 lines (137 loc) · 6.16 KB
/
joints.h
File metadata and controls
175 lines (137 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/****************************************************************************
**
** Copyright (c) 2015-2026 RoboDK Global.
** Contact: https://robodk.com/
**
** This file is part of the RoboDK API.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
** RoboDK is a registered trademark of RoboDK Global.
**
****************************************************************************/
#ifndef ROBODK_JOINTS_H
#define ROBODK_JOINTS_H
#ifdef QT_GUI_LIB
#include <QString>
#else
#error "This class cannot yet be used without the Qt Framework"
#endif
namespace robodk
{
namespace legacy
{
struct Matrix2D;
}
/// The Joints class represents a joint position of a robot (robot axes).
class Joints
{
public:
/// \brief Joints
Joints();
/// \brief Joints
/// \param ndofs number of robot joint axes or degrees of freedom
explicit Joints(int ndofs);
/// \brief Set joint values given a double array and the number of joint values
/// \param joints Pointer to the joint values
/// \param ndofs Number of joints
Joints(const double* joints, int ndofs = 0);
/// \brief Set joint values given a float array and the number of joint values
/// \param joints Pointer to the joint values
/// \param ndofs Number of joints
Joints(const float* joints, int ndofs = 0);
/// \brief Create a copy of an object
/// \param jnts
Joints(const Joints& joints) = default;
Joints& operator=(const Joints& joints) = default;
/// \brief Create joint values given a 2D matrix and the column selecting the desired values
/// \param mat2d
/// \param column
/// \param ndofs
Joints(const legacy::Matrix2D* mat2d, int column = 0, int ndofs = -1);
/// \brief Convert a string to joint values
/// \param str Comma separated joint values (spaces or tabs are also accepted)
Joints(const QString& str);
~Joints() = default;
/// \brief Joint values
/// \return Returns a pointer to the joint data array (doubles)
const double* ValuesD() const;
/// \brief Joint values
/// \return Returns a pointer to the joint data array (floats)
const float* ValuesF() const;
#ifdef ROBODK_API_FLOATS
/// \brief Joint values
/// \return Returns a pointer to the joint data array (doubles or floats if ROBODK_API_FLOATS is defined)
const float* Values() const;
#else
/// \brief Joint values
/// \return Returns a pointer to the joint data array (doubles or floats if ROBODK_API_FLOATS is defined)
const double* Values() const;
#endif
double Compare(const Joints &other) const;
/// \brief
/// \return Data same as Values. The only difference is that the array pointer is not const. This is provided for backwards compatibility.
double *Data();
/// \brief Number of joint axes of the robot (or degrees of freedom)
/// \return
int Length() const;
/// Set the length of the array (only shrinking the array is allowed)
void setLength(int new_length);
/// \brief Check if the joints are valid. For example, when we request the Inverse kinematics and there is no solution the joints will not be valid.
/// (for example, an invalid result after calling class: IItem::SolveIK returns a non valid joints)
/// \return true if it has 1 degree of freedom or more
bool Valid();
/// \brief GetValues
/// \param joints joint values in deg or mm
/// \return returns the number of degrees of freedom
int GetValues(double *joints);
/// \brief Set the joint values in deg or mm. You can also important provide the number of degrees of freedom (6 for a 6 axis robot).
/// \param joints joint values in deg or mm
/// \param ndofs number of degrees of freedom (number of axes or joints)
void SetValues(const double *joints, int ndofs = -1);
/// \brief Set the joint values in deg or mm (floats). You can also important provide the number of degrees of freedom (6 for a 6 axis robot).
/// \param joints joint values in deg or mm
/// \param ndofs number of degrees of freedom (number of axes or joints)
void SetValues(const float *joints, int ndofs = -1);
#ifdef QT_GUI_LIB
/// To String operator (use with qDebug() << Joints;
inline operator QString() const { return ToString(); }
/// \brief Retrieve a string representation of the joint values.
/// \param separator String to add between consecutive joint values
/// \param precision Number of decimals
/// \return string as a QString
QString ToString(
const QString& separator = QLatin1String(", "),
int precision = 3) const;
/// \brief Set the joint values given a comma-separated string. Tabs and spaces are also allowed.
/// \param str string. Such as "10, 20, 30, 40, 50, 60"
/// \return false if parsing the string failed. True otherwise.
bool FromString(const QString& str);
#endif
public:
static constexpr int MaximumJoints = 12;
/// number of degrees of freedom
int _dofCount;
/// joint values (doubles, used to store the joint values)
double _joints[MaximumJoints];
/// joint values (floats, used to return a copy as a float pointer)
mutable float _jointsFloat[MaximumJoints];
};
} // namespace robodk
#endif // ROBODK_JOINTS_H