RobotsIO
Loading...
Searching...
No Matches
iCubCameraRelative.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/Camera/iCubCameraRelative.h>
9
10using namespace RobotsIO::Camera;
11
12
13iCubCameraRelative::iCubCameraRelative
14(
15 const std::string& robot_name,
16 const std::string& port_prefix,
17 const bool& use_calibration,
18 const std::string& calibration_path
19) :
20 iCubCamera(robot_name, "right", port_prefix + "_relative_right", use_calibration, calibration_path)
21{
22 /* Initialize left camera. */
23 left_camera_= std::unique_ptr<iCubCamera>
24 (
25 new iCubCamera(robot_name, "left", port_prefix + "_relative_left")
26 );
27}
28
29
30iCubCameraRelative::iCubCameraRelative
31(
32 const std::string& data_path_left,
33 const std::string& data_path_right,
34 const std::size_t& width,
35 const std::size_t& height,
36 const double& fx_l,
37 const double& cx_l,
38 const double& fy_l,
39 const double& cy_l,
40 const double& fx_r,
41 const double& cx_r,
42 const double& fy_r,
43 const double& cy_r,
44 const bool& load_encoders_data,
45 const bool& use_calibration,
46 const std::string& calibration_path
47) :
48 iCubCamera(data_path_right, "right", width, height, fx_r, cx_r, fy_r, cy_r, load_encoders_data, use_calibration, calibration_path)
49{
50 /* Initialize left camera. */
51 left_camera_= std::unique_ptr<iCubCamera>
52 (
53 new iCubCamera(data_path_left, "left", width, height, fx_l, cx_l, fy_l, cy_l, load_encoders_data)
54 );
55}
56
57
58iCubCameraRelative::~iCubCameraRelative()
59{}
60
61
62bool iCubCameraRelative::status() const
63{
64 return iCubCamera::status() && get_relative_camera().status();
65}
66
67
69{
70 bool ok = iCubCamera::step_frame();
71 ok &= left_camera_->step_frame();
72
73 return ok;
74}
75
76
77bool iCubCameraRelative::set_frame_index(const std::int32_t& index)
78{
79 bool ok = iCubCamera::set_frame_index(index);
80
81 ok &= left_camera_->set_frame_index(index);
82
83 return ok;
84}
85
86
87RobotsIO::Camera::iCubCamera& iCubCameraRelative::get_relative_camera()
88{
89 return *left_camera_;
90}
91
92
93const RobotsIO::Camera::iCubCamera& iCubCameraRelative::get_relative_camera() const
94{
95 return *left_camera_;
96}
97
98
99std::pair<bool, Eigen::Transform<double, 3, Eigen::Affine>> iCubCameraRelative::pose(const bool& blocking)
100{
101 bool valid_left = false;
102 Eigen::Transform<double, 3, Eigen::Affine> pose_left;
103 std::tie(valid_left, pose_left) = get_relative_camera().pose(false);
104 if (!valid_left)
105 return std::make_pair(false, Eigen::Transform<double, 3, Eigen::Affine>());
106
107 bool valid_right = false;
108 Eigen::Transform<double, 3, Eigen::Affine> pose_right;
109 std::tie(valid_right, pose_right) = iCubCamera::pose(false);
110 if (!valid_right)
111 return std::make_pair(false, Eigen::Transform<double, 3, Eigen::Affine>());
112
113 /* Evaluate the relative pose from left camera to right camera . */
114 Eigen::Transform<double, 3, Eigen::Affine> pose_relative;
115 pose_relative = pose_left.inverse() * pose_right;
116
117 return std::make_pair(true, pose_relative);
118}
std::pair< bool, Eigen::Transform< double, 3, Eigen::Affine > > pose(const bool &blocking) override