Browse Source

修改命令发送方式使用GRPC

zx 1 year ago
parent
commit
81272e614f

+ 33 - 13
CMakeLists.txt

@@ -11,18 +11,31 @@ project(navigation)
 #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
 #SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
-#---------------------------------------------------------------------------------------
-# find package and the dependecy
-#---------------------------------------------------------------------------------------
-#find_package(Boost 1.54 REQUIRED COMPONENTS
-#	system
-#	thread
-#	chrono
-#	)
+find_package(Protobuf CONFIG REQUIRED)
+message(STATUS "Using protobuf ${Protobuf_VERSION}")
+
+set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
+set(_REFLECTION gRPC::grpc++_reflection)
+if(CMAKE_CROSSCOMPILING)
+	find_program(_PROTOBUF_PROTOC protoc)
+else()
+	set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
+endif()
+
+# Find gRPC installation
+# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
+find_package(gRPC CONFIG REQUIRED)
+message(STATUS "Using gRPC ${gRPC_VERSION}")
+
+set(_GRPC_GRPCPP gRPC::grpc++)
+if(CMAKE_CROSSCOMPILING)
+	find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
+else()
+	set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
+endif()
 
 find_package (Eigen3 REQUIRED CONFIG QUIET)
-#find_package(PCL REQUIRED)
-FIND_PACKAGE(Protobuf REQUIRED)
+
 
 #---------------------------------------------------------------------------------------
 # Set default build to release
@@ -34,7 +47,7 @@ endif()
 #---------------------------------------------------------------------------------------
 # Compiler config
 #---------------------------------------------------------------------------------------
-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
@@ -44,6 +57,7 @@ include_directories(
 		/usr/include
 		/usr/local/include
 		${EIGEN3_INCLUDE_DIR}
+		${GRPC_INCLUDE_DIR}
 		)
 link_directories("/usr/local/lib")
 ## PCL library
@@ -67,17 +81,23 @@ add_executable(${PROJECT_NAME}
 		MPC/monitor/emqx/mqttmsg.cpp
 		MPC/monitor/emqx/paho_client.cpp
 		MPC/monitor/emqx/message.pb.cc
+		MPC/monitor/emqx/message.grpc.pb.cc
 		MPC/monitor/terminator_emqx.cpp
 		tool/pathcreator.cpp
 		tool/singleton.cpp
 		tool/proto_tool.cpp
-        MPC/navigation_main.cpp MPC/navigation_main.h)
+        MPC/navigation_main.cpp
+		nav_server.cpp)
 
 #---------------------------------------------------------------------------------------
 # link libraries ${Boost_LIBRARY} -lpthread
 #---------------------------------------------------------------------------------------
 target_link_libraries(${PROJECT_NAME}
-		${PROTOBUF_LIBRARIES}
+		absl::flags
+		absl::flags_parse
+		${_REFLECTION}
+		${_GRPC_GRPCPP}
+		${_PROTOBUF_LIBPROTOBUF}
 		libglog.a libgflags.a
 		paho-mqtt3a
 		ipopt

+ 128 - 0
MPC/monitor/emqx/message.grpc.pb.cc

@@ -0,0 +1,128 @@
+// Generated by the gRPC C++ plugin.
+// If you make any local change, they will be lost.
+// source: message.proto
+
+#include "message.pb.h"
+#include "message.grpc.pb.h"
+
+#include <functional>
+#include <grpcpp/support/async_stream.h>
+#include <grpcpp/support/async_unary_call.h>
+#include <grpcpp/impl/channel_interface.h>
+#include <grpcpp/impl/client_unary_call.h>
+#include <grpcpp/support/client_callback.h>
+#include <grpcpp/support/message_allocator.h>
+#include <grpcpp/support/method_handler.h>
+#include <grpcpp/impl/rpc_service_method.h>
+#include <grpcpp/support/server_callback.h>
+#include <grpcpp/impl/server_callback_handlers.h>
+#include <grpcpp/server_context.h>
+#include <grpcpp/impl/service_type.h>
+#include <grpcpp/support/sync_stream.h>
+namespace NavMessage {
+
+static const char* NavExcutor_method_names[] = {
+  "/NavMessage.NavExcutor/Start",
+  "/NavMessage.NavExcutor/Cancel",
+};
+
+std::unique_ptr< NavExcutor::Stub> NavExcutor::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) {
+  (void)options;
+  std::unique_ptr< NavExcutor::Stub> stub(new NavExcutor::Stub(channel, options));
+  return stub;
+}
+
+NavExcutor::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options)
+  : channel_(channel), rpcmethod_Start_(NavExcutor_method_names[0], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel)
+  , rpcmethod_Cancel_(NavExcutor_method_names[1], options.suffix_for_stats(),::grpc::internal::RpcMethod::NORMAL_RPC, channel)
+  {}
+
+::grpc::Status NavExcutor::Stub::Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) {
+  return ::grpc::internal::BlockingUnaryCall< ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_Start_, context, request, response);
+}
+
+void NavExcutor::Stub::async::Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)> f) {
+  ::grpc::internal::CallbackUnaryCall< ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Start_, context, request, response, std::move(f));
+}
+
+void NavExcutor::Stub::async::Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) {
+  ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Start_, context, request, response, reactor);
+}
+
+::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* NavExcutor::Stub::PrepareAsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+  return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::NavMessage::NavResponse, ::NavMessage::NavCmd, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_Start_, context, request);
+}
+
+::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* NavExcutor::Stub::AsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+  auto* result =
+    this->PrepareAsyncStartRaw(context, request, cq);
+  result->StartCall();
+  return result;
+}
+
+::grpc::Status NavExcutor::Stub::Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) {
+  return ::grpc::internal::BlockingUnaryCall< ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_Cancel_, context, request, response);
+}
+
+void NavExcutor::Stub::async::Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)> f) {
+  ::grpc::internal::CallbackUnaryCall< ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Cancel_, context, request, response, std::move(f));
+}
+
+void NavExcutor::Stub::async::Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) {
+  ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Cancel_, context, request, response, reactor);
+}
+
+::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* NavExcutor::Stub::PrepareAsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+  return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::NavMessage::NavResponse, ::NavMessage::NavCmd, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_Cancel_, context, request);
+}
+
+::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* NavExcutor::Stub::AsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+  auto* result =
+    this->PrepareAsyncCancelRaw(context, request, cq);
+  result->StartCall();
+  return result;
+}
+
+NavExcutor::Service::Service() {
+  AddMethod(new ::grpc::internal::RpcServiceMethod(
+      NavExcutor_method_names[0],
+      ::grpc::internal::RpcMethod::NORMAL_RPC,
+      new ::grpc::internal::RpcMethodHandler< NavExcutor::Service, ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(
+          [](NavExcutor::Service* service,
+             ::grpc::ServerContext* ctx,
+             const ::NavMessage::NavCmd* req,
+             ::NavMessage::NavResponse* resp) {
+               return service->Start(ctx, req, resp);
+             }, this)));
+  AddMethod(new ::grpc::internal::RpcServiceMethod(
+      NavExcutor_method_names[1],
+      ::grpc::internal::RpcMethod::NORMAL_RPC,
+      new ::grpc::internal::RpcMethodHandler< NavExcutor::Service, ::NavMessage::NavCmd, ::NavMessage::NavResponse, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(
+          [](NavExcutor::Service* service,
+             ::grpc::ServerContext* ctx,
+             const ::NavMessage::NavCmd* req,
+             ::NavMessage::NavResponse* resp) {
+               return service->Cancel(ctx, req, resp);
+             }, this)));
+}
+
+NavExcutor::Service::~Service() {
+}
+
+::grpc::Status NavExcutor::Service::Start(::grpc::ServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response) {
+  (void) context;
+  (void) request;
+  (void) response;
+  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+}
+
+::grpc::Status NavExcutor::Service::Cancel(::grpc::ServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response) {
+  (void) context;
+  (void) request;
+  (void) response;
+  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+}
+
+
+}  // namespace NavMessage
+

+ 397 - 0
MPC/monitor/emqx/message.grpc.pb.h

@@ -0,0 +1,397 @@
+// Generated by the gRPC C++ plugin.
+// If you make any local change, they will be lost.
+// source: message.proto
+#ifndef GRPC_message_2eproto__INCLUDED
+#define GRPC_message_2eproto__INCLUDED
+
+#include "message.pb.h"
+
+#include <functional>
+#include <grpcpp/generic/async_generic_service.h>
+#include <grpcpp/support/async_stream.h>
+#include <grpcpp/support/async_unary_call.h>
+#include <grpcpp/support/client_callback.h>
+#include <grpcpp/client_context.h>
+#include <grpcpp/completion_queue.h>
+#include <grpcpp/support/message_allocator.h>
+#include <grpcpp/support/method_handler.h>
+#include <grpcpp/impl/proto_utils.h>
+#include <grpcpp/impl/rpc_method.h>
+#include <grpcpp/support/server_callback.h>
+#include <grpcpp/impl/server_callback_handlers.h>
+#include <grpcpp/server_context.h>
+#include <grpcpp/impl/service_type.h>
+#include <grpcpp/support/status.h>
+#include <grpcpp/support/stub_options.h>
+#include <grpcpp/support/sync_stream.h>
+
+namespace NavMessage {
+
+class NavExcutor final {
+ public:
+  static constexpr char const* service_full_name() {
+    return "NavMessage.NavExcutor";
+  }
+  class StubInterface {
+   public:
+    virtual ~StubInterface() {}
+    virtual ::grpc::Status Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) = 0;
+    std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>> AsyncStart(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>>(AsyncStartRaw(context, request, cq));
+    }
+    std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>> PrepareAsyncStart(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>>(PrepareAsyncStartRaw(context, request, cq));
+    }
+    virtual ::grpc::Status Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) = 0;
+    std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>> AsyncCancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>>(AsyncCancelRaw(context, request, cq));
+    }
+    std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>> PrepareAsyncCancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>>(PrepareAsyncCancelRaw(context, request, cq));
+    }
+    class async_interface {
+     public:
+      virtual ~async_interface() {}
+      virtual void Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)>) = 0;
+      virtual void Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) = 0;
+      virtual void Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)>) = 0;
+      virtual void Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) = 0;
+    };
+    typedef class async_interface experimental_async_interface;
+    virtual class async_interface* async() { return nullptr; }
+    class async_interface* experimental_async() { return async(); }
+   private:
+    virtual ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>* AsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) = 0;
+    virtual ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>* PrepareAsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) = 0;
+    virtual ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>* AsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) = 0;
+    virtual ::grpc::ClientAsyncResponseReaderInterface< ::NavMessage::NavResponse>* PrepareAsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) = 0;
+  };
+  class Stub final : public StubInterface {
+   public:
+    Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
+    ::grpc::Status Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) override;
+    std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>> AsyncStart(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>>(AsyncStartRaw(context, request, cq));
+    }
+    std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>> PrepareAsyncStart(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>>(PrepareAsyncStartRaw(context, request, cq));
+    }
+    ::grpc::Status Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::NavMessage::NavResponse* response) override;
+    std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>> AsyncCancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>>(AsyncCancelRaw(context, request, cq));
+    }
+    std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>> PrepareAsyncCancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) {
+      return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>>(PrepareAsyncCancelRaw(context, request, cq));
+    }
+    class async final :
+      public StubInterface::async_interface {
+     public:
+      void Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)>) override;
+      void Start(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) override;
+      void Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, std::function<void(::grpc::Status)>) override;
+      void Cancel(::grpc::ClientContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response, ::grpc::ClientUnaryReactor* reactor) override;
+     private:
+      friend class Stub;
+      explicit async(Stub* stub): stub_(stub) { }
+      Stub* stub() { return stub_; }
+      Stub* stub_;
+    };
+    class async* async() override { return &async_stub_; }
+
+   private:
+    std::shared_ptr< ::grpc::ChannelInterface> channel_;
+    class async async_stub_{this};
+    ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* AsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) override;
+    ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* PrepareAsyncStartRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) override;
+    ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* AsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) override;
+    ::grpc::ClientAsyncResponseReader< ::NavMessage::NavResponse>* PrepareAsyncCancelRaw(::grpc::ClientContext* context, const ::NavMessage::NavCmd& request, ::grpc::CompletionQueue* cq) override;
+    const ::grpc::internal::RpcMethod rpcmethod_Start_;
+    const ::grpc::internal::RpcMethod rpcmethod_Cancel_;
+  };
+  static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
+
+  class Service : public ::grpc::Service {
+   public:
+    Service();
+    virtual ~Service();
+    virtual ::grpc::Status Start(::grpc::ServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response);
+    virtual ::grpc::Status Cancel(::grpc::ServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response);
+  };
+  template <class BaseClass>
+  class WithAsyncMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithAsyncMethod_Start() {
+      ::grpc::Service::MarkMethodAsync(0);
+    }
+    ~WithAsyncMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    void RequestStart(::grpc::ServerContext* context, ::NavMessage::NavCmd* request, ::grpc::ServerAsyncResponseWriter< ::NavMessage::NavResponse>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+      ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag);
+    }
+  };
+  template <class BaseClass>
+  class WithAsyncMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithAsyncMethod_Cancel() {
+      ::grpc::Service::MarkMethodAsync(1);
+    }
+    ~WithAsyncMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    void RequestCancel(::grpc::ServerContext* context, ::NavMessage::NavCmd* request, ::grpc::ServerAsyncResponseWriter< ::NavMessage::NavResponse>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+      ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag);
+    }
+  };
+  typedef WithAsyncMethod_Start<WithAsyncMethod_Cancel<Service > > AsyncService;
+  template <class BaseClass>
+  class WithCallbackMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithCallbackMethod_Start() {
+      ::grpc::Service::MarkMethodCallback(0,
+          new ::grpc::internal::CallbackUnaryHandler< ::NavMessage::NavCmd, ::NavMessage::NavResponse>(
+            [this](
+                   ::grpc::CallbackServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response) { return this->Start(context, request, response); }));}
+    void SetMessageAllocatorFor_Start(
+        ::grpc::MessageAllocator< ::NavMessage::NavCmd, ::NavMessage::NavResponse>* allocator) {
+      ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(0);
+      static_cast<::grpc::internal::CallbackUnaryHandler< ::NavMessage::NavCmd, ::NavMessage::NavResponse>*>(handler)
+              ->SetMessageAllocator(allocator);
+    }
+    ~WithCallbackMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    virtual ::grpc::ServerUnaryReactor* Start(
+      ::grpc::CallbackServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/)  { return nullptr; }
+  };
+  template <class BaseClass>
+  class WithCallbackMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithCallbackMethod_Cancel() {
+      ::grpc::Service::MarkMethodCallback(1,
+          new ::grpc::internal::CallbackUnaryHandler< ::NavMessage::NavCmd, ::NavMessage::NavResponse>(
+            [this](
+                   ::grpc::CallbackServerContext* context, const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response) { return this->Cancel(context, request, response); }));}
+    void SetMessageAllocatorFor_Cancel(
+        ::grpc::MessageAllocator< ::NavMessage::NavCmd, ::NavMessage::NavResponse>* allocator) {
+      ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(1);
+      static_cast<::grpc::internal::CallbackUnaryHandler< ::NavMessage::NavCmd, ::NavMessage::NavResponse>*>(handler)
+              ->SetMessageAllocator(allocator);
+    }
+    ~WithCallbackMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    virtual ::grpc::ServerUnaryReactor* Cancel(
+      ::grpc::CallbackServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/)  { return nullptr; }
+  };
+  typedef WithCallbackMethod_Start<WithCallbackMethod_Cancel<Service > > CallbackService;
+  typedef CallbackService ExperimentalCallbackService;
+  template <class BaseClass>
+  class WithGenericMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithGenericMethod_Start() {
+      ::grpc::Service::MarkMethodGeneric(0);
+    }
+    ~WithGenericMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+  };
+  template <class BaseClass>
+  class WithGenericMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithGenericMethod_Cancel() {
+      ::grpc::Service::MarkMethodGeneric(1);
+    }
+    ~WithGenericMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+  };
+  template <class BaseClass>
+  class WithRawMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithRawMethod_Start() {
+      ::grpc::Service::MarkMethodRaw(0);
+    }
+    ~WithRawMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    void RequestStart(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+      ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag);
+    }
+  };
+  template <class BaseClass>
+  class WithRawMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithRawMethod_Cancel() {
+      ::grpc::Service::MarkMethodRaw(1);
+    }
+    ~WithRawMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    void RequestCancel(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+      ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag);
+    }
+  };
+  template <class BaseClass>
+  class WithRawCallbackMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithRawCallbackMethod_Start() {
+      ::grpc::Service::MarkMethodRawCallback(0,
+          new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>(
+            [this](
+                   ::grpc::CallbackServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->Start(context, request, response); }));
+    }
+    ~WithRawCallbackMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    virtual ::grpc::ServerUnaryReactor* Start(
+      ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/)  { return nullptr; }
+  };
+  template <class BaseClass>
+  class WithRawCallbackMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithRawCallbackMethod_Cancel() {
+      ::grpc::Service::MarkMethodRawCallback(1,
+          new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>(
+            [this](
+                   ::grpc::CallbackServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->Cancel(context, request, response); }));
+    }
+    ~WithRawCallbackMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable synchronous version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    virtual ::grpc::ServerUnaryReactor* Cancel(
+      ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/)  { return nullptr; }
+  };
+  template <class BaseClass>
+  class WithStreamedUnaryMethod_Start : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithStreamedUnaryMethod_Start() {
+      ::grpc::Service::MarkMethodStreamed(0,
+        new ::grpc::internal::StreamedUnaryHandler<
+          ::NavMessage::NavCmd, ::NavMessage::NavResponse>(
+            [this](::grpc::ServerContext* context,
+                   ::grpc::ServerUnaryStreamer<
+                     ::NavMessage::NavCmd, ::NavMessage::NavResponse>* streamer) {
+                       return this->StreamedStart(context,
+                         streamer);
+                  }));
+    }
+    ~WithStreamedUnaryMethod_Start() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable regular version of this method
+    ::grpc::Status Start(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    // replace default version of method with streamed unary
+    virtual ::grpc::Status StreamedStart(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::NavMessage::NavCmd,::NavMessage::NavResponse>* server_unary_streamer) = 0;
+  };
+  template <class BaseClass>
+  class WithStreamedUnaryMethod_Cancel : public BaseClass {
+   private:
+    void BaseClassMustBeDerivedFromService(const Service* /*service*/) {}
+   public:
+    WithStreamedUnaryMethod_Cancel() {
+      ::grpc::Service::MarkMethodStreamed(1,
+        new ::grpc::internal::StreamedUnaryHandler<
+          ::NavMessage::NavCmd, ::NavMessage::NavResponse>(
+            [this](::grpc::ServerContext* context,
+                   ::grpc::ServerUnaryStreamer<
+                     ::NavMessage::NavCmd, ::NavMessage::NavResponse>* streamer) {
+                       return this->StreamedCancel(context,
+                         streamer);
+                  }));
+    }
+    ~WithStreamedUnaryMethod_Cancel() override {
+      BaseClassMustBeDerivedFromService(this);
+    }
+    // disable regular version of this method
+    ::grpc::Status Cancel(::grpc::ServerContext* /*context*/, const ::NavMessage::NavCmd* /*request*/, ::NavMessage::NavResponse* /*response*/) override {
+      abort();
+      return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+    }
+    // replace default version of method with streamed unary
+    virtual ::grpc::Status StreamedCancel(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::NavMessage::NavCmd,::NavMessage::NavResponse>* server_unary_streamer) = 0;
+  };
+  typedef WithStreamedUnaryMethod_Start<WithStreamedUnaryMethod_Cancel<Service > > StreamedUnaryService;
+  typedef Service SplitStreamedService;
+  typedef WithStreamedUnaryMethod_Start<WithStreamedUnaryMethod_Cancel<Service > > StreamedService;
+};
+
+}  // namespace NavMessage
+
+
+#endif  // GRPC_message_2eproto__INCLUDED

File diff suppressed because it is too large
+ 2681 - 1990
MPC/monitor/emqx/message.pb.cc


File diff suppressed because it is too large
+ 1897 - 1447
MPC/monitor/emqx/message.pb.h


+ 1 - 1
MPC/monitor/emqx/mqttmsg.cpp

@@ -270,7 +270,7 @@ bool MqttMsg::toProtoMessage(google::protobuf::Message& message) const
   if(data_== nullptr)
     return false;
 
-  util::Status ret;
+  absl::Status ret;
   char* buf=(char*)malloc(length_+1);
   memset(buf,0,length_+1);
   memcpy(buf,data(),length_);

+ 1 - 0
MPC/monitor/terminator_emqx.h

@@ -6,6 +6,7 @@
 #define NAVIGATION_TERMINATOR_EMQX_H
 #include <mutex>
 #include "emqx/paho_client.h"
+#include "emqx/message.grpc.pb.h"
 
 typedef void (*Callback)(const MqttMsg& msg,void* context);
 

+ 28 - 84
MPC/navigation.cpp

@@ -15,12 +15,7 @@ Navigation::~Navigation()
     delete brotherEmqx_;
   if(monitor_)
     delete monitor_;
-  if(thread_!= nullptr)
-  {
-    if(thread_->joinable())
-      thread_->join();
-    delete thread_;
-  }
+
   if(pubthread_!= nullptr)
   {
     if(pubthread_->joinable())
@@ -105,8 +100,6 @@ bool Navigation::Init(const NavParameter::Navigation_parameter& parameter)
       return false;
     }
 
-    terminator_->AddCallback(terminal_p.subnavcmdtopic(),Navigation::NavCmdCallback,this);
-
   }
 
   if(parameter.has_brother_emqx()) {
@@ -276,38 +269,10 @@ void Navigation::ResetPose(const Pose2d& pose)
   timedPose_.reset(pose,1.0);
 }
 
-bool Navigation::Start(const NavMessage::NavCmd& cmd)
-{
-  if(newUnfinished_cations_.empty()==false)  //正在运行中,上一次指令未完成
-  {
-    if(pause_)
-    {
-      pause_=false;
-      return true;
-    }
-    printf(" navigation is running pls cancel before\n");
-    return false;
-  }
-  if(thread_!= nullptr)
-  {
-    if(thread_->joinable())
-      thread_->join();
-    delete thread_;
-  }
-
-    //add 先检查当前点与起点的距离
-    global_navCmd_=cmd;
-
-    for (int i = 0; i < cmd.newactions_size(); ++i)
-      newUnfinished_cations_.push(cmd.newactions(i));
-    thread_=new std::thread(&Navigation::navigatting,this);
-    return true;
-
-}
-void Navigation::Cancel()
+void Navigation::Cancel(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response)
 {
   cancel_=true;
-
+  response.set_ret(0);
 }
 
 bool Navigation::Stop() {
@@ -364,18 +329,12 @@ bool Navigation::SlowlyStop() {
   return false;
 }
 
-void Navigation::Pause()
-{
-  if(Stop())
-    pause_=true;
-}
 
 Navigation::Navigation()
 {
   isInSpace_=false; //是否在车位或者正在进入车位
   RWheel_position_=eUnknow;
   move_mode_=Monitor_emqx::eSingle;
-  thread_= nullptr;
   monitor_= nullptr;
   terminator_= nullptr;
 
@@ -402,43 +361,6 @@ void Navigation::BrotherAgvStatuCallback(const MqttMsg& msg,void* context)
   }
 }
 
-void Navigation::HandleNavCmd(const NavMessage::NavCmd& cmd)
-{
-  if(cmd.action()==3)
-  {
-    printf(" Nav cancel\n");
-    Cancel();
-    return ;
-  }
-  if(cmd.action()==2) {
-    printf(" Nav continue\n");
-    pause_=false;
-    return ;
-  }
-  if(cmd.action()==1) {
-    printf(" Nav pause\n");
-    Pause();
-    return ;
-  }
-  if(cmd.action()==0||cmd.action()==6)
-  {
-    Start(cmd);
-  }
-  else
-    printf(" Invalid action ,action:%d\n",cmd.action());
-}
-
-void Navigation::NavCmdCallback(const MqttMsg& msg,void* context)
-{
-  NavMessage::NavCmd cmd;
-  if(msg.toProtoMessage(cmd)==false) {
-    printf(" msg transform to NavCmd failed ..!!\n");
-    return;
-  }
-  Navigation* navigator=(Navigation*)context;
-  navigator->HandleNavCmd(cmd);
-}
-
 
 bool Navigation::RotateReferToTarget(const Pose2d& target,stLimit limit_rotate,bool anyDirect) {
 
@@ -1049,11 +971,26 @@ bool Navigation::PossibleToTarget(NavMessage::PathNode targetNode,bool directY)
   return false;
 }
 
-void Navigation::navigatting() {
+void Navigation::Start(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response) {
   if (inited_ == false) {
+    response.set_ret(-1);
+    response.set_info("navigation has not inited");
     printf(" navigation has not inited\n");
-    return;
+    return ;
   }
+  if(newUnfinished_cations_.empty()==false)  //正在运行中,上一次指令未完成
+  {
+    response.set_ret(-2);
+    response.set_info("navigation is running pls cancel before");
+    printf(" navigation is running pls cancel before\n");
+    return ;
+  }
+  //add 先检查当前点与起点的距离
+  global_navCmd_=cmd;
+
+  for (int i = 0; i < cmd.newactions_size(); ++i)
+    newUnfinished_cations_.push(cmd.newactions(i));
+
   pause_ = false;
   cancel_ = false;
   running_ = true;
@@ -1106,13 +1043,20 @@ void Navigation::navigatting() {
   actionType_ = eReady;
   Stop();
   if (cancel_ == true) {
+    response.set_ret(-3);
+    response.set_info("navigation canceled");
     printf(" navigation canceled\n");
     while (newUnfinished_cations_.empty() == false)
       newUnfinished_cations_.pop();
   } else {
-    if (newUnfinished_cations_.empty())
+    if (newUnfinished_cations_.empty()) {
+      response.set_ret(0);
+      response.set_info("navigation completed!!!");
       printf("navigation completed!!!\n");
+    }
     else {
+      response.set_ret(-4);
+      response.set_info("navigation Failed!!!!");
       printf(" navigation Failed\n");
       while (newUnfinished_cations_.empty() == false)
         newUnfinished_cations_.pop();

+ 2 - 8
MPC/navigation.h

@@ -70,9 +70,8 @@ public:
     TimedLockData<double>& RealTimeA(){
       return timedA_;
     }
-    virtual bool Start(const NavMessage::NavCmd& cmd);
-    void Cancel();
-    void Pause();
+    virtual void Start(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response);
+    void Cancel(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response);
     bool Stop();
     bool SlowlyStop();
     virtual void SwitchMode(Monitor_emqx::ActionMode mode,float wheelBase);
@@ -82,11 +81,9 @@ public:
     virtual void HandleAgvStatu(const MqttMsg& msg);
     virtual void SendMoveCmd(Monitor_emqx::ActionMode mode,Monitor_emqx::ActionType type,
                              double v,double angular);
-    virtual void HandleNavCmd(const NavMessage::NavCmd& cmd);
 
     static void RobotPoseCallback(const MqttMsg& msg,void* context);
     static void RobotSpeedCallback(const MqttMsg& msg,void* context);
-    static void NavCmdCallback(const MqttMsg& msg,void* context);
     static void BrotherAgvStatuCallback(const MqttMsg& msg,void* context);
 
 
@@ -125,8 +122,6 @@ public:
     virtual bool clamp_open();
     bool mpc_once(Trajectory traj,stLimit limit_v,std::vector<double>& out,bool directY=false);
 
-    void navigatting();
-
     virtual bool CreateRobotStatuMsg(NavMessage::RobotStatu& robotStatu);
     /*
      * 计算以当前点到目标点的曲率
@@ -161,7 +156,6 @@ public:
 
     NavMessage::NavCmd global_navCmd_; //导航任务,包含一系列动作
     std::queue<NavMessage::NewAction> newUnfinished_cations_; //未完成的动作
-    std::thread* thread_= nullptr;
     bool running_=false;
     bool pause_=false;
     bool cancel_=false;

+ 3 - 31
MPC/navigation_main.cpp

@@ -47,37 +47,8 @@ void NavigationMain::publish_statu(NavMessage::NavStatu& statu)
   Navigation::publish_statu(statu);
 }
 
-void NavigationMain::HandleNavCmd(const NavMessage::NavCmd& cmd)
-{
-  if(cmd.action()==4)
-  {
-    if(cmd.newactions_size()==0)
-    {
-      printf(" Error main \n");
-      return;
-    }
-    NavMessage::NewAction action=cmd.newactions(0);
-    if(action.wheelbase()<2.4 || action.wheelbase()>3.5)
-    {
-      printf("Failed to Switch MoveMode --> main,wheelbase invalid :%f\n",action.wheelbase());
-      return;
-    }
-    SwitchMode(Monitor_emqx::eMain,action.wheelbase());
-    return ;
-  }
-  if(cmd.action()==5)
-  {
-    printf(" Switch MoveMode --> single\n");
-    SwitchMode(Monitor_emqx::eSingle,0);
-    return ;
-  }
-  else
-  {
-    Navigation::HandleNavCmd(cmd);
-  }
-}
 
-bool NavigationMain::Start(const NavMessage::NavCmd& cmd)
+void NavigationMain::Start(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response)
 {
   /*if(move_mode_!=Monitor_emqx::eMain)
   {
@@ -85,7 +56,7 @@ bool NavigationMain::Start(const NavMessage::NavCmd& cmd)
     return false;
   }*/
 
-  return Navigation::Start(cmd);
+  Navigation::Start(cmd,response);
 
 }
 
@@ -180,6 +151,7 @@ bool NavigationMain::RotateBeforeEnterSpace(NavMessage::PathNode space,double wh
     printf(" rotate failed : timedBrotherNavStatu_ or pose timeout\n");
     return false;
   }
+
   NavMessage::NavStatu brother = timedBrotherNavStatu_.Get();
 
   stLimit limit_rotate = {2 * M_PI / 180.0, 15 * M_PI / 180.0};

+ 1 - 2
MPC/navigation_main.h

@@ -13,7 +13,7 @@ public:
     ~NavigationMain();
 
     virtual void ResetPose(const Pose2d& pose);
-    virtual bool Start(const NavMessage::NavCmd& cmd);
+    virtual void Start(const NavMessage::NavCmd& cmd,NavMessage::NavResponse& response);
     virtual void publish_statu(NavMessage::NavStatu& statu);
 
 
@@ -52,7 +52,6 @@ protected:
     virtual bool RotateBeforeEnterSpace(NavMessage::PathNode space,double wheelbase,NavMessage::PathNode& target);
     virtual void SendMoveCmd(Monitor_emqx::ActionMode mode,Monitor_emqx::ActionType type,
                              double v,double angular);
-    virtual void HandleNavCmd(const NavMessage::NavCmd& cmd);
     virtual bool clamp_close();
     virtual bool clamp_open();
     virtual bool CreateRobotStatuMsg(NavMessage::RobotStatu& robotStatu);

File diff suppressed because it is too large
+ 1829 - 1590
MPC/parameter.pb.cc


File diff suppressed because it is too large
+ 1486 - 1494
MPC/parameter.pb.h


+ 2 - 2
config/webots/navigation.prototxt

@@ -1,6 +1,7 @@
 
 
 main_agv:false
+rpc_ipport:"127.0.0.1:9091"
 Agv_emqx
 {
 	NodeId:"agv-Child"
@@ -18,7 +19,6 @@ Terminal_emqx
         port:1883
         pubStatuTopic:"agv_child/agv_statu"
         pubNavStatuTopic:"agv_child/nav_statu"
-        subNavCmdTopic:"agv_child/nav_cmd"
 }
 
 #连接主PLC的emqx
@@ -53,7 +53,7 @@ InOutVLimit
 NodeVelocityLimit
 {
     min:0.03
-    max:1.5
+    max:3
 }
 NodeAngularLimit
 {

+ 2 - 2
config/webots/navigation_main.prototxt

@@ -1,5 +1,6 @@
 
 main_agv:true
+rpc_ipport:"127.0.0.1:9090"
 Agv_emqx
 {
 	NodeId:"agv-main"
@@ -17,7 +18,6 @@ Terminal_emqx
 	port:1883
 	pubStatuTopic:"agv_main/agv_statu"
 	pubNavStatuTopic:"agv_main/nav_statu"
-	subNavCmdTopic:"agv_main/nav_cmd"
 }
 
 #连接后车的emqx
@@ -52,7 +52,7 @@ InOutVLimit
 NodeVelocityLimit
 {
     min:0.03
-    max:1.5
+    max:3
 }
 NodeAngularLimit
 {

+ 11 - 6
controller.cpp

@@ -7,6 +7,8 @@
 #include <glog/logging.h>
 #include "tool/pathcreator.h"
 #include "tool/proto_tool.h"
+#include "nav_server.h"
+#include <grpcpp/grpcpp.h>
 
 int main(int argc,char* argv[])
 {
@@ -36,14 +38,17 @@ int main(int argc,char* argv[])
     printf(" navigation init failed");
     return -1;
   }
+  //启动rpc server
+  grpc::ServerBuilder builder;
+  NavServer service(g_navigator);
+  builder.AddListeningPort(parameter.rpc_ipport(), grpc::InsecureServerCredentials());
+  builder.RegisterService(&service);
 
+  std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
+  std::cout << "Server Listening on port: "  << std::endl;
+
+  server->Wait();
 
-  printf(" input q to quite\n");
-  while(getchar()!='q')
-  {
-    printf(" input q to quite\n");
-    usleep(1000*500);
-  }
   delete g_navigator;
   return 0;
 }

+ 10 - 0
message.proto

@@ -69,6 +69,16 @@ message NavCmd
   repeated NewAction newActions=5;
 }
 
+message NavResponse{
+  int32 ret=1;
+  string info=2;
+}
+
+service NavExcutor{
+  rpc Start(NavCmd) returns(NavResponse){}
+  rpc Cancel(NavCmd) returns(NavResponse){}
+}
+
 message NavStatu
 {
   int32 statu = 1; //0:ready  1:原地旋转,2:Horizon,3:vrtical,4:MPC,5:夹持开,6:夹持关

+ 25 - 0
nav_server.cpp

@@ -0,0 +1,25 @@
+//
+// Created by zx on 23-7-15.
+//
+
+#include "nav_server.h"
+
+
+::grpc::Status NavServer::Start(::grpc::ServerContext* context,
+                             const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response){
+  std::cout << "server received StartCmd: " << request->key() << std::endl;
+  if(navigator_!= nullptr){
+    navigator_->Start(*request,*response);
+  }
+  return ::grpc::Status::OK;
+}
+::grpc::Status NavServer::Cancel(::grpc::ServerContext* context,
+                              const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response){
+  std::cout << "server received Cancel Cmd: " << request->key() << std::endl;
+  if(navigator_!= nullptr){
+    navigator_->Cancel(*request,*response);
+  }
+  return ::grpc::Status::OK;
+}
+
+

+ 26 - 0
nav_server.h

@@ -0,0 +1,26 @@
+//
+// Created by zx on 23-7-15.
+//
+
+#ifndef NAVIGATION_NAV_SERVER_H
+#define NAVIGATION_NAV_SERVER_H
+#include "MPC/navigation_main.h"
+class NavServer :public NavMessage::NavExcutor::Service{
+public:
+    NavServer(Navigation* navigator){
+      navigator_=navigator;
+    }
+    virtual ~NavServer(){}
+private:
+    virtual ::grpc::Status Start(::grpc::ServerContext* context,
+                                 const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response);
+    virtual ::grpc::Status Cancel(::grpc::ServerContext* context,
+                                  const ::NavMessage::NavCmd* request, ::NavMessage::NavResponse* response);
+
+protected:
+    Navigation* navigator_= nullptr;
+
+
+};
+
+#endif //NAVIGATION_NAV_SERVER_H

+ 2 - 1
parameter.proto

@@ -16,7 +16,6 @@ message Emqx_parameter
     int32 port=3;
     string pubStatuTopic=4;
     string pubNavStatuTopic=5;
-    string subNavCmdTopic=6;
 }
 message BrotherEmqx
 {
@@ -26,6 +25,7 @@ message BrotherEmqx
   string subBrotherStatuTopic=4;
 }
 
+
 message MPC_parameter
 {
   float shortest_radius=1;
@@ -56,5 +56,6 @@ message Navigation_parameter
   SpeedLimit InOutVLimit=7; //进出库速度
   SpeedLimit NodeVelocityLimit=8; //马路点MPC速度限制
   SpeedLimit NodeAngularLimit=9;  //马路点原地旋转速度限制
+  string rpc_ipport=10;
 }
 

+ 3 - 1
proto.sh

@@ -1,5 +1,7 @@
 
-protoc -I=./ message.proto --cpp_out=./MPC/monitor/emqx
+protoc --cpp_out=./MPC/monitor/emqx --grpc_out=./MPC/monitor/emqx --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` -I=./ message.proto
+
 protoc -I=./ parameter.proto --cpp_out=./MPC
 
 
+