-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extension of Spot_Driver_CPP refactor (#196)
- Loading branch information
1 parent
630e12e
commit c3f6c5c
Showing
33 changed files
with
918 additions
and
778 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
31 changes: 31 additions & 0 deletions
31
spot_driver_cpp/include/spot_driver_cpp/api/default_image_client_api.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,31 @@ | ||
// Copyright (c) 2023 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <bosdyn/client/image/image_client.h> | ||
#include <bosdyn/client/sdk/client_sdk.h> | ||
#include <spot_driver_cpp/api/image_client_api.hpp> | ||
#include <spot_driver_cpp/api/time_sync_api.hpp> | ||
#include <spot_driver_cpp/images/spot_image_sources.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace spot_ros2 { | ||
/** | ||
* @brief Implements ImageClientApi to use the Spot C++ Image Client. | ||
*/ | ||
class DefaultImageClientApi : public ImageClientApi { | ||
public: | ||
DefaultImageClientApi(::bosdyn::client::ImageClient* image_client, std::shared_ptr<TimeSyncApi> time_sync_api, | ||
const std::string& robot_name); | ||
~DefaultImageClientApi() = default; | ||
|
||
tl::expected<GetImagesResult, std::string> getImages(::bosdyn::api::GetImageRequest request) override; | ||
|
||
private: | ||
::bosdyn::client::ImageClient* image_client_; | ||
std::shared_ptr<TimeSyncApi> time_sync_api_; | ||
std::string robot_name_; | ||
}; | ||
} // namespace spot_ros2 |
21 changes: 0 additions & 21 deletions
21
spot_driver_cpp/include/spot_driver_cpp/api/default_robot_api.hpp
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
spot_driver_cpp/include/spot_driver_cpp/api/default_spot_api.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,32 @@ | ||
// Copyright (c) 2023 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <spot_driver_cpp/api/spot_api.hpp> | ||
|
||
#include <bosdyn/client/robot/robot.h> | ||
#include <bosdyn/client/sdk/client_sdk.h> | ||
#include <spot_driver_cpp/api/time_sync_api.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace spot_ros2 { | ||
|
||
class DefaultSpotApi : public SpotApi { | ||
public: | ||
explicit DefaultSpotApi(const std::string& sdk_client_name); | ||
|
||
tl::expected<void, std::string> createRobot(const std::string& ip_address, const std::string& robot_name) override; | ||
tl::expected<void, std::string> authenticate(const std::string& username, const std::string& password) override; | ||
tl::expected<bool, std::string> hasArm() const override; | ||
std::shared_ptr<ImageClientApi> image_client_api() const override; | ||
|
||
private: | ||
std::unique_ptr<::bosdyn::client::ClientSdk> client_sdk_; | ||
std::unique_ptr<::bosdyn::client::Robot> robot_; | ||
std::shared_ptr<ImageClientApi> image_client_api_; | ||
std::shared_ptr<TimeSyncApi> time_sync_api_; | ||
std::string robot_name_; | ||
}; | ||
} // 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
// Copyright (c) 2023 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <spot_driver_cpp/api/image_client_api.hpp> | ||
#include <tl_expected/expected.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace spot_ros2 { | ||
|
||
class SpotApi { | ||
public: | ||
virtual ~SpotApi() = default; | ||
|
||
virtual tl::expected<void, std::string> createRobot(const std::string& ip_address, const std::string& robot_name) = 0; | ||
virtual tl::expected<void, std::string> authenticate(const std::string& username, const std::string& password) = 0; | ||
virtual tl::expected<bool, std::string> hasArm() const = 0; | ||
virtual std::shared_ptr<ImageClientApi> image_client_api() const = 0; | ||
}; | ||
} // namespace spot_ros2 |
60 changes: 60 additions & 0 deletions
60
spot_driver_cpp/include/spot_driver_cpp/api/time_sync_api.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,60 @@ | ||
// Copyright (c) 2023 Boston Dynamics AI Institute LLC. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <google/protobuf/duration.pb.h> | ||
#include <google/protobuf/timestamp.pb.h> | ||
#include <builtin_interfaces/msg/time.hpp> | ||
#include <tl_expected/expected.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace spot_ros2 { | ||
|
||
inline builtin_interfaces::msg::Time applyClockSkew(const google::protobuf::Timestamp& timestamp, | ||
const google::protobuf::Duration& clock_skew) { | ||
int64_t seconds_unskewed = timestamp.seconds() - clock_skew.seconds(); | ||
int32_t nanos_unskewed = timestamp.nanos() - clock_skew.nanos(); | ||
|
||
// Carry over a second if needed | ||
// Note: Since ROS Time messages store the nanoseconds component as an unsigned integer, we need to do this before | ||
// converting to ROS Time. | ||
if (nanos_unskewed < 0) { | ||
nanos_unskewed += 1e9; | ||
seconds_unskewed -= 1; | ||
} else if (nanos_unskewed >= 1e9) { | ||
nanos_unskewed -= 1e9; | ||
seconds_unskewed += 1; | ||
} | ||
|
||
// If the timestamp contains a negative time, create an all-zero ROS Time. | ||
if (seconds_unskewed < 0) { | ||
return builtin_interfaces::build<builtin_interfaces::msg::Time>().sec(0).nanosec(0); | ||
} else { | ||
return builtin_interfaces::build<builtin_interfaces::msg::Time>().sec(seconds_unskewed).nanosec(nanos_unskewed); | ||
} | ||
} | ||
|
||
class TimeSyncApi { | ||
public: | ||
virtual tl::expected<builtin_interfaces::msg::Time, std::string> convertRobotTimeToLocalTime( | ||
const google::protobuf::Timestamp& robot_timestamp) = 0; | ||
|
||
/** | ||
* @brief Get the current clock skew from the Spot SDK's time sync endpoint. | ||
* @details The clock skew is the difference between Spot's internal system clock and the host PC's system clock. | ||
* For example, a clock skew of 1.0 seconds means that a timestamp from Spot's clock that is 10.0 seconds after epoch | ||
* would correspond to a timestmap from the system clock that is 9.0 seconds after epoch. | ||
* The Spot SDK documentation provides a more detailed explanation of how Spot's time sync works here: | ||
* https://dev.bostondynamics.com/docs/concepts/base_services#time-sync | ||
* | ||
* @return If the clock skew was successfully calculated, return a Duration containing the difference between Spot's | ||
* internal clock and the host's system clock. | ||
* @return If the Spot SDK's time sync thread was not initialized, return an error message. | ||
* @return If the Spot SDK's time sync endpoint fails to handle the clock skew request, return an error message. | ||
*/ | ||
virtual tl::expected<google::protobuf::Duration, std::string> getClockSkew() = 0; | ||
}; | ||
} // namespace spot_ros2 |
Oops, something went wrong.