30 double theta,
double d,
double a,
double alpha,
bool is_prismatic)
36 void CKinematicChain::removeLink(
const size_t idx)
39 m_links.erase(m_links.begin() + idx);
64 uint8_t CKinematicChain::serializeGetVersion()
const {
return 1; }
67 out << m_links << m_origin;
70 void CKinematicChain::serializeFrom(
95 void CKinematicChain::recomputeAllPoses(
100 const size_t N = m_links.size();
108 for (
size_t i = 0; i < N; i++)
111 const double th = m_links[i].theta;
112 const double alpha = m_links[i].alpha;
113 const double d = m_links[i].d;
114 const double a = m_links[i].a;
116 const double t_vals[3] = {
a * cos(th),
a * sin(th), d};
117 const double r_vals[3 * 3] = {cos(th),
118 -sin(th) * cos(
alpha),
119 sin(th) * sin(
alpha),
121 cos(th) * cos(
alpha),
122 -cos(th) * sin(
alpha),
132 p.composeFrom(
p, link);
138 const float R = 0.01f;
143 mrpt::make_aligned_shared<mrpt::opengl::CCylinder>(
R,
R, d);
145 gl_cyl->setName(
"cyl.d");
147 objs->insert(gl_cyl);
153 mrpt::make_aligned_shared<mrpt::opengl::CCylinder>(
R,
R, -
a);
156 gl_cyl2->setName(
"cyl.a");
158 objs->insert(gl_cyl2);
161 void CKinematicChain::getAs3DObject(
166 const size_t N = m_links.size();
170 recomputeAllPoses(all_poses);
172 m_last_gl_objects.resize(N + 1);
175 for (
size_t i = 0; i <= N; i++)
179 gl_corner->setPose(all_poses[i]);
181 gl_corner->setName(
mrpt::format(
"%u",
static_cast<unsigned int>(i)));
182 gl_corner->enableShowName();
184 if (i < N)
addBar_D(gl_corner, m_links[i].d);
185 if (i > 0)
addBar_A(gl_corner, m_links[i - 1].
a);
187 obj->insert(gl_corner);
188 m_last_gl_objects[i] = gl_corner;
191 if (out_all_poses) out_all_poses->swap(all_poses);
194 void CKinematicChain::update3DObject(
198 (m_links.size() + 1) == m_last_gl_objects.size(),
199 "The kinematic chain has changed since the last call to "
202 const size_t N = m_links.size();
206 recomputeAllPoses(all_poses);
208 for (
size_t i = 0; i <= N; i++)
211 std::dynamic_pointer_cast<mrpt::opengl::CSetOfObjects>(
212 m_last_gl_objects[i]);
213 gl_objs->setPose(all_poses[i]);
218 std::dynamic_pointer_cast<mrpt::opengl::CCylinder>(
219 gl_objs->getByName(
"cyl.d"));
220 const double d = m_links[i].d;
227 std::dynamic_pointer_cast<mrpt::opengl::CCylinder>(
228 gl_objs->getByName(
"cyl.a"));
229 const double a = m_links[i - 1].a;
231 glCyl2->setHeight(-
a);
235 if (out_all_poses) out_all_poses->swap(all_poses);
242 m_last_gl_objects.clear();
void addBar_A(mrpt::opengl::CSetOfObjects::Ptr &objs, const double a)
void addBar_D(mrpt::opengl::CSetOfObjects::Ptr &objs, const double d)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
A open-loop kinematic chain model, suitable to robotic manipulators.
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually,...
std::shared_ptr< CCylinder > Ptr
std::shared_ptr< CSetOfObjects > Ptr
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Virtual base class for "archives": classes abstracting I/O streams.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
#define ASSERT_(f)
Defines an assertion mechanism.
#define ASSERT_BELOW_(__A, __B)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
GLsizei GLsizei GLuint * obj
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLclampf GLclampf GLclampf alpha
GLubyte GLubyte GLubyte a
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void clear()
Clear the contents of this container.
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, TKinematicLink &o)
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const TKinematicLink &o)
This base provides a set of functions for maths stuff.
CSetOfObjects::Ptr CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
Returns three arrows representing a X,Y,Z 3D corner (just thick lines instead of complex arrows for f...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
double DEG2RAD(const double x)
Degrees to radians.
unsigned __int32 uint32_t
An individual kinematic chain element (one link) which builds up a CKinematicChain.
double alpha
Rotation along X_{i+1} to transform Z_i into Z_{i+1}.
double d
Distance along Z_i to the common normal between Z_i and Z_{i+1}.
double a
Distance along the common normal (in the same direction than the new X_{i+1})
double theta
Rotation from X_i to X_{i+1} (radians)
bool is_prismatic
"false": Is revolute ("q_i" is "theta"), "true": is prismatic ("q_i" is "d")