RobotsIO
Loading...
Searching...
No Matches
test_DatasetSpatialVelocity/main.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 <cstdlib>
9#include <iostream>
10
11#include <RobotsIO/Utils/DatasetSpatialVelocity.h>
12
13using namespace Eigen;
14using namespace RobotsIO::Utils;
15
16
17bool parse_size_t (char** argv, const std::size_t& index, const std::string& name, std::size_t& retrieved);
18
19
20int main(int argc, char** argv)
21{
22 const std::string log_name = "test_DatasetSpatialVelocity";
23
24 if (argc != 4)
25 {
26 std::cerr << "Synopsis: " + log_name + " <dataset_path> <skip_rows> <skip_cols>" << std::endl << std::endl;
27
28 return EXIT_FAILURE;
29 }
30
31 const std::string dataset_path{argv[1]};
32
33 std::size_t skip_rows;
34 if (!parse_size_t(argv, 2, "skip_rows", skip_rows))
35 return EXIT_FAILURE;
36
37 std::size_t skip_cols;
38 if (!parse_size_t(argv, 3, "skip_cols", skip_cols))
39 return EXIT_FAILURE;
40
41 DatasetSpatialVelocity dataset(dataset_path, skip_rows, skip_cols, 6);
42
43 std::size_t i = 0;
44 while (dataset.freeze())
45 {
46 auto linear_velocity = dataset.linear_velocity_origin();
47 auto angular_velocity = dataset.angular_velocity();
48 std::cout << i++ << ": "
49 << linear_velocity.transpose() << " "
50 << angular_velocity.transpose() << " "
51 << "(degenerate: " << (dataset.is_screw_degenerate() ? "true" : "false") << ") "
52 << std::endl;
53 }
54
55 return EXIT_SUCCESS;
56}
57
58
59bool parse_size_t (char** argv, const std::size_t& index, const std::string& name, std::size_t& retrieved)
60{
61 try
62 {
63 if (std::stoi(argv[index]) < 0)
64 throw(std::invalid_argument(""));
65 retrieved = std::stoul(argv[index]);
66 }
67 catch (std::invalid_argument)
68 {
69 std::cerr << "Invalid value " << argv[index] << " for parameter <" << name << ">." << std::endl;
70 return false;
71 }
72
73 return true;
74}