RobotsIO
Loading...
Searching...
No Matches
SpatialVelocityYarpPort.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/SpatialVelocityYarpPort.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
19SpatialVelocityYarpPort::SpatialVelocityYarpPort(const std::string& port_name) :
20 YarpVectorOfProbe<double>(port_name)
21{}
22
23
24SpatialVelocityYarpPort:: ~SpatialVelocityYarpPort()
25{}
26
27
28bool SpatialVelocityYarpPort::freeze(const bool blocking)
29{
30 /* Data reception .*/
31 yarp::sig::Vector* velocity_yarp = receive_data(blocking);
32 if (velocity_yarp == nullptr)
33 return false;
34
35 /* Elapsed time. */
36 elapsed_time_ = 0.0;
37 auto now = std::chrono::steady_clock::now();
38 if (last_time_initialized_)
39 elapsed_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time_).count() / 1000.0;
40 last_time_ = now;
41 last_time_initialized_ = true;
42
43 twist_ = toEigen(*velocity_yarp);
44
45 return true;
46}
47
48double SpatialVelocityYarpPort::elapsed_time()
49{
50 return elapsed_time_;
51}
52
53
54VectorXd SpatialVelocityYarpPort::twist()
55{
56 return twist_;
57}