-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michel Hidalgo <[email protected]>
- Loading branch information
1 parent
e34b68d
commit 9dad912
Showing
24 changed files
with
1,178 additions
and
59 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
41 changes: 41 additions & 0 deletions
41
spot_driver/include/spot_driver/api/default_lease_client.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,41 @@ | ||
// Copyright (c) 2025 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <bosdyn/client/lease/lease.h> | ||
#include <bosdyn/client/lease/lease_client.h> | ||
#include <bosdyn/client/lease/lease_keepalive.h> | ||
#include <bosdyn/client/lease/lease_wallet.h> | ||
#include <bosdyn/client/sdk/client_sdk.h> | ||
#include <spot_driver/api/lease_client_interface.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace spot_ros2 { | ||
/** | ||
* @brief Implements LeaseClientInterface to use the Spot C++ Lease Client. | ||
*/ | ||
class DefaultLeaseClient : public LeaseClientInterface { | ||
public: | ||
explicit DefaultLeaseClient(::bosdyn::client::LeaseClient* lease_client); | ||
|
||
[[nodiscard]] tl::expected<::bosdyn::client::Lease, std::string> acquireLease( | ||
const std::string& resource_name, LeaseUseCallback retention_failure_callback) override; | ||
|
||
[[nodiscard]] tl::expected<::bosdyn::client::Lease, std::string> takeLease( | ||
const std::string& resource_name, LeaseUseCallback retention_failure_callback) override; | ||
|
||
[[nodiscard]] tl::expected<bool, std::string> returnLease(const ::bosdyn::client::Lease& lease) override; | ||
|
||
[[nodiscard]] std::shared_ptr<::bosdyn::client::LeaseWallet> getLeaseWallet() const override; | ||
|
||
[[nodiscard]] const ::bosdyn::client::ResourceHierarchy& getResourceHierarchy() const override; | ||
|
||
private: | ||
::bosdyn::client::LeaseClient* lease_client_; | ||
std::unordered_map<std::string, std::unique_ptr<::bosdyn::client::LeaseKeepAlive>> keepalives_; | ||
std::mutex keepalives_mutex_; | ||
}; | ||
} // namespace spot_ros2 |
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
41 changes: 41 additions & 0 deletions
41
spot_driver/include/spot_driver/api/lease_client_interface.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,41 @@ | ||
// Copyright (c) 2025 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <tl_expected/expected.hpp> | ||
|
||
#include <bosdyn/api/lease.pb.h> | ||
#include <bosdyn/client/lease/lease.h> | ||
#include <bosdyn/client/lease/lease_wallet.h> | ||
|
||
namespace spot_ros2 { | ||
class LeaseClientInterface { | ||
public: | ||
using LeaseUseCallback = std::function<void(const bosdyn::api::LeaseUseResult&)>; | ||
|
||
// LeaseClientInterface is move-only | ||
LeaseClientInterface() = default; | ||
LeaseClientInterface(LeaseClientInterface&& other) = default; | ||
LeaseClientInterface(const LeaseClientInterface&) = delete; | ||
LeaseClientInterface& operator=(LeaseClientInterface&& other) = default; | ||
LeaseClientInterface& operator=(const LeaseClientInterface&) = delete; | ||
|
||
virtual ~LeaseClientInterface() = default; | ||
|
||
virtual tl::expected<::bosdyn::client::Lease, std::string> acquireLease( | ||
const std::string& resource_name, LeaseUseCallback retention_failure_callback) = 0; | ||
|
||
virtual tl::expected<::bosdyn::client::Lease, std::string> takeLease( | ||
const std::string& resource_name, LeaseUseCallback retention_failure_callback) = 0; | ||
|
||
virtual tl::expected<bool, std::string> returnLease(const ::bosdyn::client::Lease& lease) = 0; | ||
|
||
virtual std::shared_ptr<::bosdyn::client::LeaseWallet> getLeaseWallet() const = 0; | ||
|
||
virtual const ::bosdyn::client::ResourceHierarchy& getResourceHierarchy() const = 0; | ||
}; | ||
} // namespace spot_ros2 |
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
45 changes: 45 additions & 0 deletions
45
spot_driver/include/spot_driver/lease/lease_manager_node.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,45 @@ | ||
// Copyright (c) 2025 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <spot_driver/lease/lease_manager.hpp> | ||
|
||
#include <spot_driver/api/spot_api.hpp> | ||
#include <spot_driver/interfaces/logger_interface_base.hpp> | ||
#include <spot_driver/interfaces/parameter_interface_base.hpp> | ||
|
||
#include <rclcpp/node.hpp> | ||
#include <rclcpp/node_interfaces/node_base_interface.hpp> | ||
#include <rclcpp/node_options.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace spot_ros2::lease { | ||
class LeaseManagerNode { | ||
public: | ||
explicit LeaseManagerNode(std::shared_ptr<rclcpp::Node> node, std::unique_ptr<SpotApi> spot_api, | ||
std::shared_ptr<ParameterInterfaceBase> parameter_interface, | ||
std::shared_ptr<LoggerInterfaceBase> logger_interface); | ||
|
||
explicit LeaseManagerNode(const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions{}); | ||
|
||
/** | ||
* @brief Returns the NodeBaseInterface of this class's node. | ||
* @details This function exists to allow spinning the class's node as if it were derived from rclcpp::Node. | ||
* This allows loading this class as a component node in a composable node container without requiring that it inherit | ||
* from rclcpp::Node. | ||
* | ||
* @return A shared_ptr to the NodeBaseInterface of the node stored as a private member of this class. | ||
*/ | ||
std::shared_ptr<rclcpp::node_interfaces::NodeBaseInterface> get_node_base_interface(); | ||
|
||
private: | ||
std::shared_ptr<rclcpp::Node> node_; | ||
std::unique_ptr<SpotApi> spot_api_; | ||
std::unique_ptr<LeaseManager> internal_; | ||
|
||
void initialize(std::shared_ptr<rclcpp::Node> node, std::unique_ptr<SpotApi> spot_api, | ||
std::shared_ptr<ParameterInterfaceBase> parameter_interface, | ||
const std::shared_ptr<LoggerInterfaceBase> logger_interface); | ||
}; | ||
} // namespace spot_ros2::kinematic |
38 changes: 38 additions & 0 deletions
38
spot_driver/include/spot_driver/lease/lease_middleware_handle.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,38 @@ | ||
// Copyright (c) 2025 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <spot_driver/lease/lease_manager.hpp> | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <rclcpp/node.hpp> | ||
#include <rclcpp/service.hpp> | ||
|
||
namespace spot_ros2::lease { | ||
|
||
class LeaseMiddlewareHandle : public LeaseManager::MiddlewareHandle { | ||
public: | ||
explicit LeaseMiddlewareHandle(std::shared_ptr<rclcpp::Node> node); | ||
|
||
void createAcquireLeaseService( | ||
const std::string& service_name, | ||
std::function<void(const std::shared_ptr<AcquireLease::Request>, | ||
std::shared_ptr<AcquireLease::Response>)> callback) override; | ||
|
||
void createReturnLeaseService( | ||
const std::string& service_name, | ||
std::function<void(const std::shared_ptr<ReturnLease::Request>, | ||
std::shared_ptr<ReturnLease::Response>)> callback) override; | ||
|
||
std::shared_ptr<LeaseManager::MiddlewareHandle::Bond> createBond( | ||
const std::string& node_name, std::function<void()> break_callback) override; | ||
|
||
private: | ||
std::shared_ptr<rclcpp::Node> node_; | ||
std::shared_ptr<rclcpp::Service<AcquireLease>> acquire_lease_service_; | ||
std::shared_ptr<rclcpp::Service<ReturnLease>> return_lease_service_; | ||
}; | ||
} // namespace spot_ros2::lease |
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.