RobotsIO
Loading...
Searching...
No Matches
TransformYarpTransformClient.cpp
1/*
2 * Copyright (C) 2020 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/TransformYarpTransformClient.h>
9
10#include <yarp/eigen/Eigen.h>
11#include <yarp/os/Property.h>
12
13using namespace Eigen;
14using namespace RobotsIO::Utils;
15using namespace yarp::eigen;
16
17
18TransformYarpTransformClient::TransformYarpTransformClient(const std::string& port_prefix, const std::string& source_name, const std::string& target_name) :
19 source_name_(source_name),
20 target_name_(target_name)
21{
22 /* FrameTransformClient initialization. */
23 yarp::os::Property tf_properties;
24 tf_properties.put("device", "transformClient");
25 tf_properties.put("local", "/" + port_prefix + "/transform_client");
26 tf_properties.put("remote", "/transformServer");
27
28 bool ok = drv_transform_client_.open(tf_properties);
29 ok &= (drv_transform_client_.view(transform_client_) && (transform_client_ != nullptr));
30 if (!ok)
31 {
32 throw(std::runtime_error(log_name_ + "::ctor. Error: cannot initialize the FrameTransformClient."));
33 }
34}
35
36
37TransformYarpTransformClient:: ~TransformYarpTransformClient()
38{}
39
40
41Eigen::Transform<double, 3, Affine> TransformYarpTransformClient::transform()
42{
43 return transform_;
44}
45
46
47bool TransformYarpTransformClient::freeze(const bool blocking)
48{
49 yarp::sig::Matrix transform(4, 4);
50 if (!transform_client_->getTransform(target_name_, source_name_, transform))
51 return false;
52
53 transform_.matrix() = toEigen(transform);
54
55 return true;
56}