|
| 1 | +// -- BEGIN LICENSE BLOCK ---------------------------------------------- |
| 2 | +// Copyright 2026 Universal Robots A/S |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are met: |
| 6 | +// |
| 7 | +// * Redistributions of source code must retain the above copyright |
| 8 | +// notice, this list of conditions and the following disclaimer. |
| 9 | +// |
| 10 | +// * Redistributions in binary form must reproduce the above copyright |
| 11 | +// notice, this list of conditions and the following disclaimer in the |
| 12 | +// documentation and/or other materials provided with the distribution. |
| 13 | +// |
| 14 | +// * Neither the name of the {copyright_holder} nor the names of its |
| 15 | +// contributors may be used to endorse or promote products derived from |
| 16 | +// this software without specific prior written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +// POSSIBILITY OF SUCH DAMAGE. |
| 29 | +// -- END LICENSE BLOCK ------------------------------------------------ |
| 30 | + |
| 31 | +#include <ur_client_library/types.h> |
| 32 | + |
| 33 | +#include <algorithm> |
| 34 | + |
| 35 | +namespace urcl |
| 36 | +{ |
| 37 | +Q::Q(const double q1, const double q2, const double q3, const double q4, const double q5, const double q6) |
| 38 | +{ |
| 39 | + values_ = { q1, q2, q3, q4, q5, q6 }; |
| 40 | +} |
| 41 | + |
| 42 | +Q::Q(const vector6d_t& values) |
| 43 | +{ |
| 44 | + values_.resize(6); |
| 45 | + std::copy(values.begin(), values.end(), values_.begin()); |
| 46 | +} |
| 47 | + |
| 48 | +const std::vector<double>& Q::getValues() const |
| 49 | +{ |
| 50 | + return values_; |
| 51 | +} |
| 52 | + |
| 53 | +void Q::setValues(const vector6d_t& values) |
| 54 | +{ |
| 55 | + values_.resize(6); |
| 56 | + std::copy(values.begin(), values.end(), values_.begin()); |
| 57 | +} |
| 58 | + |
| 59 | +void Q::setValues(const std::vector<double>& values) |
| 60 | +{ |
| 61 | + values_ = values; |
| 62 | +} |
| 63 | + |
| 64 | +bool operator==(const Q& lhs, const Q& rhs) |
| 65 | +{ |
| 66 | + return lhs.getValues().size() == rhs.getValues().size() && |
| 67 | + std::equal(lhs.getValues().begin(), lhs.getValues().end(), rhs.getValues().begin()); |
| 68 | +} |
| 69 | + |
| 70 | +Pose::Pose() : x(0.0), y(0.0), z(0.0), rx(0.0), ry(0.0), rz(0.0), q_near_(std::nullopt) |
| 71 | +{ |
| 72 | +} |
| 73 | + |
| 74 | +Pose::Pose(const double x, const double y, const double z, const double rx, const double ry, const double rz) |
| 75 | + : x(x), y(y), z(z), rx(rx), ry(ry), rz(rz), q_near_(std::nullopt) |
| 76 | +{ |
| 77 | +} |
| 78 | + |
| 79 | +Pose::Pose(const double x, const double y, const double z, const double rx, const double ry, const double rz, |
| 80 | + const Q& q_near) |
| 81 | + : x(x), y(y), z(z), rx(rx), ry(ry), rz(rz), q_near_(q_near) |
| 82 | +{ |
| 83 | +} |
| 84 | + |
| 85 | +bool Pose::operator==(const Pose& other) const |
| 86 | +{ |
| 87 | + if (x != other.x || y != other.y || z != other.z || rx != other.rx || ry != other.ry || rz != other.rz) |
| 88 | + { |
| 89 | + return false; |
| 90 | + } |
| 91 | + if (q_near_.has_value() != other.q_near_.has_value()) |
| 92 | + { |
| 93 | + return false; |
| 94 | + } |
| 95 | + if (!q_near_.has_value()) |
| 96 | + { |
| 97 | + return true; |
| 98 | + } |
| 99 | + return *q_near_ == *other.q_near_; |
| 100 | +} |
| 101 | + |
| 102 | +const std::optional<Q>& Pose::getQNear() const |
| 103 | +{ |
| 104 | + return q_near_; |
| 105 | +} |
| 106 | + |
| 107 | +void Pose::setQNear(const Q& q_near) |
| 108 | +{ |
| 109 | + q_near_ = q_near; |
| 110 | +} |
| 111 | + |
| 112 | +bool operator==(const Q& lhs, const vector6d_t& rhs) |
| 113 | +{ |
| 114 | + return lhs.getValues().size() == rhs.size() && |
| 115 | + std::equal(lhs.getValues().begin(), lhs.getValues().end(), rhs.begin()); |
| 116 | +} |
| 117 | + |
| 118 | +} // namespace urcl |
0 commit comments