|
| 1 | +// -- BEGIN LICENSE BLOCK ---------------------------------------------- |
| 2 | +// Copyright 2025 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/primary/robot_state/robot_mode_data.h" |
| 32 | +#include "ur_client_library/primary/abstract_primary_consumer.h" |
| 33 | + |
| 34 | +#include <iomanip> |
| 35 | + |
| 36 | +namespace urcl |
| 37 | +{ |
| 38 | +namespace primary_interface |
| 39 | +{ |
| 40 | +RobotModeData::RobotModeData(const RobotModeData& pkg) : RobotState(RobotStateType::ROBOT_MODE_DATA) |
| 41 | +{ |
| 42 | + timestamp_ = pkg.timestamp_; |
| 43 | + is_real_robot_connected_ = pkg.is_real_robot_connected_; |
| 44 | + is_real_robot_enabled_ = pkg.is_real_robot_enabled_; |
| 45 | + is_robot_power_on_ = pkg.is_robot_power_on_; |
| 46 | + is_emergency_stopped_ = pkg.is_emergency_stopped_; |
| 47 | + is_protective_stopped_ = pkg.is_protective_stopped_; |
| 48 | + is_program_running_ = pkg.is_program_running_; |
| 49 | + is_program_paused_ = pkg.is_program_paused_; |
| 50 | + robot_mode_ = pkg.robot_mode_; |
| 51 | + control_mode_ = pkg.control_mode_; |
| 52 | + target_speed_fraction_ = pkg.target_speed_fraction_; |
| 53 | + speed_scaling_ = pkg.speed_scaling_; |
| 54 | + target_speed_fraction_limit_ = pkg.target_speed_fraction_limit_; |
| 55 | + reserved_ = pkg.reserved_; |
| 56 | +} |
| 57 | + |
| 58 | +bool RobotModeData::parseWith(comm::BinParser& bp) |
| 59 | +{ |
| 60 | + bp.parse(timestamp_); |
| 61 | + bp.parse(is_real_robot_connected_); |
| 62 | + bp.parse(is_real_robot_enabled_); |
| 63 | + bp.parse(is_robot_power_on_); |
| 64 | + bp.parse(is_emergency_stopped_); |
| 65 | + bp.parse(is_protective_stopped_); |
| 66 | + bp.parse(is_program_running_); |
| 67 | + bp.parse(is_program_paused_); |
| 68 | + bp.parse(robot_mode_); |
| 69 | + bp.parse(control_mode_); |
| 70 | + bp.parse(target_speed_fraction_); |
| 71 | + bp.parse(speed_scaling_); |
| 72 | + bp.parse(target_speed_fraction_limit_); |
| 73 | + bp.parseRemainder(reserved_); |
| 74 | + |
| 75 | + return true; |
| 76 | +} |
| 77 | + |
| 78 | +bool RobotModeData::consumeWith(AbstractPrimaryConsumer& consumer) |
| 79 | +{ |
| 80 | + return consumer.consume(*this); |
| 81 | +} |
| 82 | + |
| 83 | +std::string RobotModeData::toString() const |
| 84 | +{ |
| 85 | + std::stringstream os; |
| 86 | + os << "Timestamp: " << timestamp_ << std::endl; |
| 87 | + os << "Is real robot connected: " << is_real_robot_connected_ << std::endl; |
| 88 | + os << "Is real robot enabled: " << is_real_robot_enabled_ << std::endl; |
| 89 | + os << "Is robot power on: " << is_robot_power_on_ << std::endl; |
| 90 | + os << "Is emergency stopped: " << is_emergency_stopped_ << std::endl; |
| 91 | + os << "Is protective stopped: " << is_protective_stopped_ << std::endl; |
| 92 | + os << "Is program running: " << is_program_running_ << std::endl; |
| 93 | + os << "Is program paused: " << is_program_paused_ << std::endl; |
| 94 | + os << "Robot mode: " << unsigned(robot_mode_) << std::endl; |
| 95 | + os << "Control mode: " << unsigned(control_mode_) << std::endl; |
| 96 | + os << "Target speed fraction: " << target_speed_fraction_ << std::endl; |
| 97 | + os << "Speed scaling: " << speed_scaling_ << std::endl; |
| 98 | + os << "Target speed fraction limit: " << target_speed_fraction_limit_ << std::endl; |
| 99 | + os << "Reserved: ( " << reserved_.length() << ")"; |
| 100 | + for (const char& c : reserved_) |
| 101 | + { |
| 102 | + os << std::hex << static_cast<int>(c) << ", "; |
| 103 | + } |
| 104 | + os << std::endl; |
| 105 | + |
| 106 | + return os.str(); |
| 107 | +} |
| 108 | + |
| 109 | +} // namespace primary_interface |
| 110 | +} // namespace urcl |
0 commit comments