DCCL v4
Loading...
Searching...
No Matches
test.cpp
1// Copyright 2015-2023:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6// Stephanie Petillo <stephanie@gobysoft.org>
7//
8//
9// This file is part of the Dynamic Compact Control Language Library
10// ("DCCL").
11//
12// DCCL is free software: you can redistribute it and/or modify
13// it under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// DCCL is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
24#include <iomanip>
25#include <iostream>
26
27#include "auv_status.pb.h"
28#include "test.pb.h"
29#include <boost/units/base_units/metric/bar.hpp>
30#include <boost/units/io.hpp>
31#include <boost/units/physical_dimensions/pressure.hpp>
32#include <boost/units/systems/si.hpp>
33#include <boost/units/systems/si/dimensionless.hpp>
34#include <boost/units/systems/si/prefixes.hpp>
35#include <boost/units/systems/si/velocity.hpp>
36#include <boost/units/systems/temperature/celsius.hpp>
37#include <boost/units/systems/temperature/fahrenheit.hpp>
38
39#include <boost/units/base_units/metric/nautical_mile.hpp>
40
41int main()
42{
43 CTDTestMessage test_msg;
44
45 using namespace boost::units;
46 using boost::units::metric::bar_base_unit;
47 using boost::units::si::deci;
48
49 typedef bar_base_unit::unit_type Bar;
50 static const Bar bar;
51
52 quantity<Bar> pressure(150.123456789 * si::deci * bar);
53
54 test_msg.set_pressure_with_units(pressure);
55
56 using Kelvin =
57 boost::units::unit<boost::units::temperature_dimension, boost::units::si::system>;
58 quantity<absolute<Kelvin>> temp(15 * absolute<celsius::temperature>());
59 std::cout << temp << std::endl;
60
61 double temp_d = (temp - quantity<absolute<Kelvin>>(0 * absolute<Kelvin>())) / Kelvin();
62 std::cout << temp_d << std::endl;
63
64 test_msg.set_temperature_with_units(15 * absolute<fahrenheit::temperature>());
65 test_msg.set_micro_temp_with_units(15 * Kelvin());
66 test_msg.set_salinity(35.2);
67 test_msg.set_sound_speed(1500);
68
69 quantity<si::velocity> c(1500 * si::meters_per_second);
70 test_msg.set_sound_speed_with_units(c);
71 test_msg.set_depth_with_units(100 * si::meters);
72 quantity<si::velocity> auv_spd(2.5 * si::meters_per_second);
73 test_msg.set_auv_speed_with_units(auv_spd);
74 std::cout << "auv_spd: " << auv_spd << std::endl;
75
76 test_msg.set_salinity_with_units(38.9 * si::dimensionless());
77
78 std::cout << test_msg.DebugString() << std::endl; //outputs protobuf debug string
79 std::cout << "Temperature: " << test_msg.temperature_with_units() << std::endl;
80 std::cout << "Micro temperature: " << test_msg.micro_temp_with_units() << std::endl;
81 std::cout << std::setprecision(10) << "Pressure: " << test_msg.pressure_with_units()
82 << std::endl;
83 std::cout << "Pressure (as bars): " << quantity<Bar>(test_msg.pressure_with_units())
84 << std::endl;
85 std::cout << "Sound speed: " << test_msg.sound_speed_with_units() << std::endl;
86 std::cout << "AUV speed: " << test_msg.auv_speed_with_units() << std::endl;
87 std::cout << "Salinity: " << test_msg.salinity_with_units() << std::endl;
88
89 AUVStatus status;
90 status.set_x_with_units(1000 * si::meters);
91 status.set_y_with_units(500 * si::meters);
92 status.set_heading_with_units(3.1415926535 / 2 * si::radians);
93
94 using NauticalMile = metric::nautical_mile_base_unit::unit_type;
95 quantity<NauticalMile> x_nm(status.x_with_units());
96 quantity<NauticalMile> y_nm(status.y_with_units());
97
98 std::cout << status.DebugString() << std::endl;
99 std::cout << x_nm << std::endl;
100 std::cout << y_nm << std::endl;
101 std::cout << status.heading_with_units() << std::endl;
102
103 Parent p;
104 p.set_mass_with_units(2 * si::kilograms);
105 p.set_si_mass_with_units(10 * si::kilograms);
106 p.mutable_child()->set_length_with_units(5 * si::meters);
107
108 assert(p.mass() == 2000); // grams
109 assert(p.si_mass() == 10); // kilograms
110 assert(p.child().length() == 500); // centimeters
111
112 std::cout << "all tests passed" << std::endl;
113}