-
Notifications
You must be signed in to change notification settings - Fork 142
Add parsing masterboard data #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
include/ur_client_library/primary/robot_state/masterboard_data.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // -- BEGIN LICENSE BLOCK ---------------------------------------------- | ||
| // Copyright 2026 Universal Robots A/S | ||
| // | ||
| // Redistribution and use in source and binary forms, with or without | ||
| // modification, are permitted provided that the following conditions are met: | ||
| // | ||
| // * Redistributions of source code must retain the above copyright | ||
| // notice, this list of conditions and the following disclaimer. | ||
| // | ||
| // * Redistributions in binary form must reproduce the above copyright | ||
| // notice, this list of conditions and the following disclaimer in the | ||
| // documentation and/or other materials provided with the distribution. | ||
| // | ||
| // * Neither the name of the {copyright_holder} nor the names of its | ||
| // contributors may be used to endorse or promote products derived from | ||
| // this software without specific prior written permission. | ||
| // | ||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| // POSSIBILITY OF SUCH DAMAGE. | ||
| // -- END LICENSE BLOCK ------------------------------------------------ | ||
|
|
||
| #ifndef UR_CLIENT_LIBRARY_MASTERBOARD_DATA_H_INCLUDED | ||
| #define UR_CLIENT_LIBRARY_MASTERBOARD_DATA_H_INCLUDED | ||
|
|
||
| #include <bitset> | ||
|
|
||
| #include "ur_client_library/types.h" | ||
| #include "ur_client_library/primary/robot_state.h" | ||
| #include "ur_client_library/ur/datatypes.h" | ||
|
|
||
| namespace urcl | ||
| { | ||
| namespace primary_interface | ||
| { | ||
| /*! | ||
| * \brief The MasterboardData class handles the masterboard data sub-package sent as part of the | ||
| * Robot State message on the primary UR interface. | ||
| * | ||
| * This package contains information about the control box IOs, analog inputs/outputs, voltages, | ||
| * currents, temperatures, the safety mode, as well as information about the optional IMMI | ||
| * interface. See the Universal Robots primary/secondary guide for details: | ||
| * https://docs.universal-robots.com/tutorials/communication-protocol-tutorials/primary-secondary-guide.html | ||
| */ | ||
| class MasterboardData : public RobotState | ||
| { | ||
| public: | ||
| MasterboardData() = delete; | ||
|
|
||
| /*! | ||
| * \brief Creates a new MasterboardData object. | ||
| * | ||
| * \param type The type of RobotState message received | ||
| */ | ||
| MasterboardData(const RobotStateType type) : RobotState(type) | ||
| { | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Creates a copy of a MasterboardData object. | ||
| * | ||
| * \param pkg The MasterboardData object to be copied | ||
| */ | ||
| MasterboardData(const MasterboardData& pkg); | ||
|
|
||
| virtual ~MasterboardData() = default; | ||
|
|
||
| /*! | ||
| * \brief Sets the attributes of the package by parsing a serialized representation of the | ||
| * package. | ||
| * | ||
| * \param bp A parser containing a serialized version of the package | ||
| * | ||
| * \returns True, if the package was parsed successfully, false otherwise | ||
| */ | ||
| virtual bool parseWith(comm::BinParser& bp); | ||
|
|
||
| /*! | ||
| * \brief Consume this specific package with a specific consumer. | ||
| * | ||
| * \param consumer Placeholder for the consumer calling this | ||
| * | ||
| * \returns true on success | ||
| */ | ||
| virtual bool consumeWith(AbstractPrimaryConsumer& consumer); | ||
|
|
||
| /*! | ||
| * \brief Produces a human readable representation of the package object. | ||
| * | ||
| * \returns A string representing the object | ||
| */ | ||
| virtual std::string toString() const; | ||
|
|
||
| std::bitset<32> digital_input_bits_; | ||
| std::bitset<32> digital_output_bits_; | ||
| uint8_t analog_input_range_0_; | ||
| uint8_t analog_input_range_1_; | ||
| double analog_input_0_; | ||
| double analog_input_1_; | ||
| char analog_output_domain_0_; | ||
| char analog_output_domain_1_; | ||
| double analog_output_0_; | ||
| double analog_output_1_; | ||
| float master_board_temperature_; | ||
| float robot_voltage_48v_; | ||
| float robot_current_; | ||
| float master_io_current_; | ||
| SafetyMode safety_mode_; | ||
| bool in_reduced_mode_; | ||
| bool immi_interface_installed_{ false }; | ||
|
|
||
| // The following four fields are only valid if immi_interface_installed_ is true. | ||
| std::bitset<32> immi_input_bits_; | ||
| std::bitset<32> immi_output_bits_; | ||
| float immi_voltage_24v_{ 0.0f }; | ||
| float immi_current_{ 0.0f }; | ||
|
|
||
| uint32_t reserved_1_{ 0 }; | ||
| uint8_t operational_mode_selector_input_{ 0 }; | ||
| bool three_position_enabling_device_input_{ false }; | ||
| uint8_t reserved_2_{ 0 }; | ||
| }; | ||
|
|
||
| } // namespace primary_interface | ||
| } // namespace urcl | ||
|
|
||
| #endif // ifndef UR_CLIENT_LIBRARY_MASTERBOARD_DATA_H_INCLUDED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // -- BEGIN LICENSE BLOCK ---------------------------------------------- | ||
| // Copyright 2025 Universal Robots A/S | ||
| // | ||
| // Redistribution and use in source and binary forms, with or without | ||
| // modification, are permitted provided that the following conditions are met: | ||
| // | ||
| // * Redistributions of source code must retain the above copyright | ||
| // notice, this list of conditions and the following disclaimer. | ||
| // | ||
| // * Redistributions in binary form must reproduce the above copyright | ||
| // notice, this list of conditions and the following disclaimer in the | ||
| // documentation and/or other materials provided with the distribution. | ||
| // | ||
| // * Neither the name of the {copyright_holder} nor the names of its | ||
| // contributors may be used to endorse or promote products derived from | ||
| // this software without specific prior written permission. | ||
| // | ||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| // POSSIBILITY OF SUCH DAMAGE. | ||
| // -- END LICENSE BLOCK ------------------------------------------------ | ||
|
|
||
| #include "ur_client_library/primary/robot_state/masterboard_data.h" | ||
| #include "ur_client_library/primary/abstract_primary_consumer.h" | ||
|
|
||
| #include <iomanip> | ||
| #include <sstream> | ||
|
|
||
| namespace urcl | ||
| { | ||
| namespace primary_interface | ||
| { | ||
| MasterboardData::MasterboardData(const MasterboardData& pkg) : RobotState(RobotStateType::MASTERBOARD_DATA) | ||
| { | ||
| digital_input_bits_ = pkg.digital_input_bits_; | ||
| digital_output_bits_ = pkg.digital_output_bits_; | ||
| analog_input_range_0_ = pkg.analog_input_range_0_; | ||
| analog_input_range_1_ = pkg.analog_input_range_1_; | ||
| analog_input_0_ = pkg.analog_input_0_; | ||
| analog_input_1_ = pkg.analog_input_1_; | ||
| analog_output_domain_0_ = pkg.analog_output_domain_0_; | ||
| analog_output_domain_1_ = pkg.analog_output_domain_1_; | ||
| analog_output_0_ = pkg.analog_output_0_; | ||
| analog_output_1_ = pkg.analog_output_1_; | ||
| master_board_temperature_ = pkg.master_board_temperature_; | ||
| robot_voltage_48v_ = pkg.robot_voltage_48v_; | ||
| robot_current_ = pkg.robot_current_; | ||
| master_io_current_ = pkg.master_io_current_; | ||
| safety_mode_ = pkg.safety_mode_; | ||
| in_reduced_mode_ = pkg.in_reduced_mode_; | ||
| immi_interface_installed_ = pkg.immi_interface_installed_; | ||
| immi_input_bits_ = pkg.immi_input_bits_; | ||
| immi_output_bits_ = pkg.immi_output_bits_; | ||
| immi_voltage_24v_ = pkg.immi_voltage_24v_; | ||
| immi_current_ = pkg.immi_current_; | ||
| reserved_1_ = pkg.reserved_1_; | ||
| operational_mode_selector_input_ = pkg.operational_mode_selector_input_; | ||
| three_position_enabling_device_input_ = pkg.three_position_enabling_device_input_; | ||
| reserved_2_ = pkg.reserved_2_; | ||
| } | ||
|
|
||
| bool MasterboardData::parseWith(comm::BinParser& bp) | ||
| { | ||
| bp.parse<uint32_t>(digital_input_bits_); | ||
| bp.parse<uint32_t>(digital_output_bits_); | ||
| bp.parse(analog_input_range_0_); | ||
| bp.parse(analog_input_range_1_); | ||
| bp.parse(analog_input_0_); | ||
| bp.parse(analog_input_1_); | ||
| bp.parse(analog_output_domain_0_); | ||
| bp.parse(analog_output_domain_1_); | ||
| bp.parse(analog_output_0_); | ||
| bp.parse(analog_output_1_); | ||
| bp.parse(master_board_temperature_); | ||
| bp.parse(robot_voltage_48v_); | ||
| bp.parse(robot_current_); | ||
| bp.parse(master_io_current_); | ||
| bp.parse(safety_mode_); | ||
| bp.parse(in_reduced_mode_); | ||
| bp.parse(immi_interface_installed_); | ||
|
|
||
| if (immi_interface_installed_) | ||
| { | ||
| bp.parse<uint32_t>(immi_input_bits_); | ||
| bp.parse<uint32_t>(immi_output_bits_); | ||
| bp.parse(immi_voltage_24v_); | ||
| bp.parse(immi_current_); | ||
| } | ||
|
|
||
| bp.parse(reserved_1_); | ||
| bp.parse(operational_mode_selector_input_); | ||
| bp.parse(three_position_enabling_device_input_); | ||
| bp.parse(reserved_2_); | ||
|
urfeex marked this conversation as resolved.
|
||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool MasterboardData::consumeWith(AbstractPrimaryConsumer& consumer) | ||
| { | ||
| return consumer.consume(*this); | ||
| } | ||
|
|
||
| std::string MasterboardData::toString() const | ||
| { | ||
| std::stringstream os; | ||
| os << std::boolalpha; | ||
| os << "MasterboardData:" << std::endl; | ||
| os << "Digital input bits: 0b" << digital_input_bits_ << std::endl; | ||
| os << "Digital output bits: 0b" << digital_output_bits_ << std::endl; | ||
| os << "Analog input range 0: " << unsigned(analog_input_range_0_) << std::endl; | ||
| os << "Analog input range 1: " << unsigned(analog_input_range_1_) << std::endl; | ||
| os << "Analog input 0: " << analog_input_0_ << std::endl; | ||
| os << "Analog input 1: " << analog_input_1_ << std::endl; | ||
| os << "Analog output domain 0: " << static_cast<int>(analog_output_domain_0_) << std::endl; | ||
| os << "Analog output domain 1: " << static_cast<int>(analog_output_domain_1_) << std::endl; | ||
| os << "Analog output 0: " << analog_output_0_ << std::endl; | ||
| os << "Analog output 1: " << analog_output_1_ << std::endl; | ||
| os << "Masterboard temperature: " << master_board_temperature_ << std::endl; | ||
| os << "Robot voltage 48V: " << robot_voltage_48v_ << std::endl; | ||
| os << "Robot current: " << robot_current_ << std::endl; | ||
| os << "Master I/O current: " << master_io_current_ << std::endl; | ||
| os << "Safety mode: " << safetyModeString(safety_mode_) << std::endl; | ||
| os << "In reduced mode: " << in_reduced_mode_ << std::endl; | ||
| os << "IMMI interface installed: " << immi_interface_installed_ << std::endl; | ||
| if (immi_interface_installed_) | ||
| { | ||
| os << "IMMI input bits: 0b" << immi_input_bits_ << std::endl; | ||
| os << "IMMI output bits: 0b" << immi_output_bits_ << std::endl; | ||
| os << "IMMI voltage 24V: " << immi_voltage_24v_ << std::endl; | ||
| os << "IMMI current: " << immi_current_ << std::endl; | ||
| } | ||
| os << "Operational mode selector input: " << unsigned(operational_mode_selector_input_) << std::endl; | ||
| os << "Three position enabling device input: " << three_position_enabling_device_input_ << std::endl; | ||
|
|
||
| return os.str(); | ||
| } | ||
|
|
||
| } // namespace primary_interface | ||
| } // namespace urcl | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.