-
Notifications
You must be signed in to change notification settings - Fork 27
RSDK-3589 add wrapper for navigation service #323
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 23 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
bbf46f2
first pass navigation hpp
abe-winter a270b0d
missing include
abe-winter e338601
green
abe-winter e8e2aab
checkpoint
abe-winter 4783dd6
proto constructors, unique_ptr
abe-winter 0cb6b02
nav client compiles
abe-winter 2deaf73
nav service compiles, register it
abe-winter 6c8545d
clang format
abe-winter 3b83c1b
extra nav mentions where needed in cmake
abe-winter f353325
sigh clang-tidy
abe-winter 1f51fa8
vec <-> repeated pointer converters in utils
abe-winter 3960542
use builtin types instead of protos
abe-winter b7c8cb5
clang format grr
abe-winter 3f7c6c7
add inlines without
abe-winter d36b9ea
instead of constructor + operator, weird not-quite-sfinae approach to…
abe-winter 2f470be
lint
abe-winter d334572
clear destination in ptr <-> vec conversions
abe-winter d640587
actually remove proto headers from nav wrapper
abe-winter b674f55
nolints
abe-winter 49b210b
clang format
abe-winter d5e7d3a
get rid of annoying template approach
abe-winter aa5e1f0
fix comments
abe-winter 359d53b
move proto_utils to private
abe-winter 3def54d
nested namespaces only in cpp17
abe-winter 226d860
remove name param, other sdks don't use it in nav wrappers
abe-winter 83444b3
properties struct instead of returning raw maptype in case we add mor…
abe-winter 305e2a8
mock and test stubs
abe-winter 0128a00
roundtrip test passing
abe-winter 679432c
operator==, fix type on NavServer::DoCommand
abe-winter 6631bc0
test all methods
abe-winter d4cf2e7
docstrings
abe-winter c6d5da9
Merge branch 'main' into aw-nav-service
abe-winter 7fa6630
missing const
abe-winter 4e9f32c
x_from_proto -> from_proto
abe-winter 6c26a8c
change mapOver signature
abe-winter 1ae0b1f
return vector instead of unique_ptr
abe-winter 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /// @file common/proto_utils.hpp | ||
| /// | ||
| /// @brief Utils that require generated proto includes. These should be #included | ||
| /// in cpp implementation files, but not in wrapper headers consumed by third party code. | ||
| #pragma once | ||
|
|
||
| #include <viam/api/common/v1/common.pb.h> | ||
|
|
||
| namespace viam::sdk::impl { | ||
|
|
||
| /// @brief Copies elements from a protobuf repeated pointer array into a std::vector. Src type | ||
| /// must have a `to_proto` method. | ||
| template <typename Src, typename Dst> | ||
| void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) { | ||
| dest.Clear(); | ||
| dest.Reserve(vec.size()); | ||
| for (auto& x : vec) { | ||
| *dest.Add() = x.to_proto(); | ||
| } | ||
| } | ||
|
|
||
| /// @brief Non-member to_proto() version. (necessary for moving generated types out of wrapper | ||
| /// headers). Takes explicit `to_proto`. | ||
| template <typename Src, typename Dst> | ||
| void vecToRepeatedPtr(const std::vector<Src>& vec, | ||
| google::protobuf::RepeatedPtrField<Dst>& dest, | ||
| Dst to_proto(const Src&)) { | ||
| dest.Clear(); | ||
| dest.Reserve(vec.size()); | ||
| for (auto& x : vec) { | ||
| *dest.Add() = to_proto(x); | ||
| } | ||
| } | ||
|
|
||
| /// @brief Copies elements from a std::vector into a protobuf repeated pointer array. Dst type | ||
| /// must have a `from_proto` static method. | ||
| template <typename Src, typename Dst> | ||
| void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) { | ||
| vec.clear(); | ||
| vec.reserve(src.size()); | ||
| for (auto& x : src) { | ||
| vec.push_back(Dst::from_proto(x)); | ||
| } | ||
| } | ||
|
|
||
| /// @brief Non-member from_proto() version. (necessary for moving generated types out of wrapper | ||
| /// headers). Takes explicit `from_proto`. | ||
| template <typename Src, typename Dst> | ||
| void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, | ||
| std::vector<Dst>& vec, | ||
| Dst from_proto(const Src&)) { | ||
| vec.clear(); | ||
| vec.reserve(src.size()); | ||
| for (auto& x : src) { | ||
| vec.push_back(from_proto(x)); | ||
| } | ||
| } | ||
|
|
||
| } // namespace viam::sdk::impl | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #include <viam/sdk/services/navigation.hpp> | ||
|
|
||
| #include <viam/api/service/navigation/v1/navigation.pb.h> | ||
| #include <viam/sdk/common/private/proto_utils.hpp> | ||
| #include <viam/sdk/common/utils.hpp> | ||
|
|
||
| namespace viam { | ||
| namespace sdk { | ||
|
|
||
| Navigation::Navigation(std::string name) : Service(std::move(name)){}; | ||
|
|
||
| API Navigation::api() const { | ||
| return API::get<Navigation>(); | ||
| } | ||
|
|
||
| API API::traits<Navigation>::api() { | ||
| return {kRDK, kService, "navigation"}; | ||
| } | ||
|
|
||
| } // namespace sdk | ||
| } // namespace viam |
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,102 @@ | ||
| /// @file services/navigation.hpp | ||
| /// | ||
| /// @brief Defines a `Navigation` service. | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include <viam/sdk/common/pose.hpp> | ||
| #include <viam/sdk/common/utils.hpp> | ||
| #include <viam/sdk/services/service.hpp> | ||
| #include <viam/sdk/spatialmath/geometry.hpp> | ||
|
|
||
| namespace viam { | ||
| namespace sdk { | ||
|
|
||
| class Navigation : public Service { | ||
| public: | ||
| enum class Mode : uint8_t { | ||
| k_unspecified, | ||
| k_manual, | ||
| k_waypoint, | ||
| k_explore, | ||
| }; | ||
|
|
||
| enum class MapType : uint8_t { | ||
| k_unspecified, | ||
| k_none, | ||
| k_gps, | ||
| }; | ||
|
|
||
| struct LocationResponse { | ||
| geo_point location; | ||
| double compass_heading; | ||
| }; | ||
|
|
||
| struct Waypoint { | ||
| std::string id; | ||
| geo_point location; | ||
| }; | ||
|
|
||
| struct Path { | ||
| std::string destination_waypoint_id; | ||
| std::vector<geo_point> geopoints; | ||
| }; | ||
|
|
||
| API api() const override; | ||
|
|
||
| virtual Mode get_mode(const std::string name, const ProtoStruct& extra) = 0; | ||
abe-winter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| virtual void set_mode(const std::string name, const Mode mode, const ProtoStruct& extra) = 0; | ||
| virtual LocationResponse get_location(const std::string name, const ProtoStruct& extra) = 0; | ||
| virtual std::unique_ptr<std::vector<Waypoint>> get_waypoints(const std::string name, | ||
| const ProtoStruct& extra) = 0; | ||
| virtual void add_waypoint(const std::string name, | ||
| const geo_point& location, | ||
| const ProtoStruct& extra) = 0; | ||
| virtual void remove_waypoint(const std::string name, | ||
| const std::string id, | ||
| const ProtoStruct& extra) = 0; | ||
| virtual std::unique_ptr<std::vector<geo_geometry>> get_obstacles(const std::string name, | ||
| const ProtoStruct& extra) = 0; | ||
| virtual std::unique_ptr<std::vector<Path>> get_paths(const std::string name, | ||
| const ProtoStruct& extra) = 0; | ||
| virtual MapType get_properties(const std::string) = 0; | ||
| virtual ProtoStruct do_command(const ProtoStruct& command) = 0; | ||
|
|
||
| // overloads without `extra` param. | ||
| inline Mode get_mode(const std::string name) { | ||
| return get_mode(name, {}); | ||
| } | ||
| inline void set_mode(const std::string name, const Mode mode) { | ||
| set_mode(name, mode, {}); | ||
| } | ||
| inline LocationResponse get_location(const std::string name) { | ||
| return get_location(name, {}); | ||
| } | ||
| inline std::unique_ptr<std::vector<Waypoint>> get_waypoints(const std::string name) { | ||
| return get_waypoints(name, {}); | ||
| } | ||
| inline void add_waypoint(const std::string name, const geo_point& location) { | ||
| add_waypoint(name, location, {}); | ||
| } | ||
| inline void remove_waypoint(const std::string name, const std::string id) { | ||
| remove_waypoint(name, id, {}); | ||
| } | ||
| inline std::unique_ptr<std::vector<geo_geometry>> get_obstacles(const std::string name) { | ||
| return get_obstacles(name, {}); | ||
| } | ||
| inline std::unique_ptr<std::vector<Path>> get_paths(const std::string name) { | ||
| return get_paths(name, {}); | ||
| } | ||
|
|
||
| protected: | ||
| explicit Navigation(std::string name); | ||
| }; | ||
|
|
||
| template <> | ||
| struct API::traits<Navigation> { | ||
| static API api(); | ||
| }; | ||
|
|
||
| } // namespace sdk | ||
| } // namespace viam | ||
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.