RobotsIO
Loading...
Searching...
No Matches
TransformWithVelocityYarpPort.cpp
1/*
2 * Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <RobotsIO/Utils/TransformWithVelocityYarpPort.h>
9
10#include <yarp/eigen/Eigen.h>
11#include <yarp/sig/Vector.h>
12
13using namespace Eigen;
14using namespace RobotsIO::Utils;
15using namespace yarp::eigen;
16using namespace yarp::sig;
17
18
19TransformWithVelocityYarpPort::TransformWithVelocityYarpPort(const std::string& port_name) :
20 YarpBufferedPort<yarp::sig::Vector>(port_name)
21{}
22
23
24TransformWithVelocityYarpPort:: ~TransformWithVelocityYarpPort()
25{}
26
27
28Eigen::Transform<double, 3, Affine> TransformWithVelocityYarpPort::transform()
29{
30 return transform_;
31}
32
33
34Eigen::Vector3d TransformWithVelocityYarpPort::linear_velocity()
35{
36 return linear_velocity_;
37}
38
39
40Eigen::Vector3d TransformWithVelocityYarpPort::angular_velocity()
41{
42 return angular_velocity_;
43}
44
45
46bool TransformWithVelocityYarpPort::freeze(const bool blocking)
47{
48 yarp::sig::Vector* transform_yarp = receive_data(blocking);
49
50 if (transform_yarp == nullptr)
51 return false;
52
53 transform_ = Translation<double, 3>(toEigen(*transform_yarp).head<3>());
54 AngleAxisd rotation((*transform_yarp)(6), toEigen(*transform_yarp).segment<3>(3));
55 transform_.rotate(rotation);
56
57 linear_velocity_ = toEigen(*transform_yarp).segment<3>(7);
58 angular_velocity_ = toEigen(*transform_yarp).tail<3>();
59
60 return true;
61}