-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de63c83
commit 312ab08
Showing
26 changed files
with
1,383 additions
and
224 deletions.
There are no files selected for viewing
This file contains 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 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 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,76 @@ | ||
// Copyright (c) 2023 PickNik, Inc. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <array> | ||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
/** | ||
* Utility class to convert between commonly used data types. | ||
*/ | ||
namespace robotiq_driver::data_utils | ||
{ | ||
/** | ||
* Convert a sequence of uint8_t into a sequence of hex numbers. | ||
* @param bytes The sequence of bytes. | ||
* @return A string containing the sequence of hex numbers. | ||
*/ | ||
std::string to_hex(const std::vector<uint8_t>& bytes); | ||
|
||
/** | ||
* Convert a sequence of uint16_t into a sequence of hex numbers. | ||
* @param bytes The sequence of bytes. | ||
* @return A string containing the sequence of hex numbers. | ||
*/ | ||
std::string to_hex(const std::vector<uint16_t>& bytes); | ||
|
||
/** | ||
* Convert a byte to a binary representation for testing purposes. | ||
* @param byte The byte to decode. | ||
* @return The binary representation of the given byte. | ||
*/ | ||
std::string to_binary_string(const uint8_t byte); | ||
|
||
/** | ||
* Get the Most Significant Byte (MSB) of the given value. | ||
* @param value A 16-bits value. | ||
* @return The Most Significant Byte (MSB) of the given value. | ||
*/ | ||
uint8_t get_msb(uint16_t value); | ||
|
||
/** | ||
* Get the Least Significant Byte (LSB) of the given value. | ||
* @param value A 16-bits value. | ||
* @return The Least Significant Byte (LSB) of the given value. | ||
*/ | ||
uint8_t get_lsb(uint16_t value); | ||
|
||
} // namespace robotiq_driver::data_utils |
This file contains 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 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,73 @@ | ||
// Copyright (c) 2023 PickNik, Inc. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <robotiq_driver/serial.hpp> | ||
#include <memory> | ||
|
||
#include <serial/serial.h> | ||
|
||
namespace serial | ||
{ | ||
class Serial; | ||
} | ||
|
||
namespace robotiq_driver | ||
{ | ||
class DefaultSerial : public Serial | ||
{ | ||
public: | ||
/** | ||
* Creates a Serial object to send and receive bytes to and from the serial | ||
* port. | ||
*/ | ||
DefaultSerial(); | ||
|
||
void open() override; | ||
|
||
[[nodiscard]] bool is_open() const override; | ||
|
||
void close() override; | ||
|
||
[[nodiscard]] std::vector<uint8_t> read(size_t size = 1) override; | ||
void write(const std::vector<uint8_t>& data) override; | ||
|
||
void set_port(const std::string& port) override; | ||
[[nodiscard]] std::string get_port() const override; | ||
|
||
void set_timeout(std::chrono::milliseconds timeout_ms) override; | ||
[[nodiscard]] std::chrono::milliseconds get_timeout() const override; | ||
|
||
void set_baudrate(uint32_t baudrate) override; | ||
[[nodiscard]] uint32_t get_baudrate() const override; | ||
|
||
private: | ||
std::unique_ptr<serial::Serial> serial_ = nullptr; | ||
}; | ||
} // namespace robotiq_driver |
58 changes: 58 additions & 0 deletions
58
robotiq_driver/include/robotiq_driver/default_serial_factory.hpp
This file contains 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,58 @@ | ||
// Copyright (c) 2023 PickNik, Inc. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <robotiq_driver/serial_factory.hpp> | ||
#include <robotiq_driver/default_serial_factory.hpp> | ||
#include <hardware_interface/hardware_info.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace robotiq_driver | ||
{ | ||
/** | ||
* This class is used to create a default driver to interact with the hardware. | ||
*/ | ||
class DefaultSerialFactory : public SerialFactory | ||
{ | ||
public: | ||
DefaultSerialFactory() = default; | ||
|
||
/** | ||
* @brief Create a serial interface. | ||
* @param info The hardware information. | ||
* @return A sarial interface to communicate with the hardware. | ||
*/ | ||
std::unique_ptr<Serial> create(const hardware_interface::HardwareInfo& info) const; | ||
|
||
protected: | ||
// Seam for testing. | ||
virtual std::unique_ptr<Serial> create_serial() const; | ||
}; | ||
} // namespace robotiq_driver |
This file contains 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
Oops, something went wrong.