Browse Source

add apollodriver_hcp2

yuchuli 1 tháng trước cách đây
mục cha
commit
3dc122aceb

+ 12 - 0
src/apollo/apollolib/hcp2/Makefile

@@ -0,0 +1,12 @@
+all: hcp2.o
+
+	g++ -shared -o libhcp2.so hcp2.o  
+
+hcp2.o: hcp2.cpp
+
+	g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC  -o hcp2.o hcp2.cpp
+
+
+clean:
+
+	rm hcp2.o

+ 21 - 1
src/apollo/apollolib/hcp2/hcp2.cpp

@@ -153,11 +153,14 @@ int  set_port_attr (
      return (tcsetattr (fd, TCSANOW, &opt));
 }
 
-hcp2::hcp2(std::string strportname)
+hcp2::hcp2(std::string strportname,hcp2fun xFun)
 {
     mstrportname = strportname;
+    mhcp2fun = xFun;
     mbthreadrun = true;
     mpthread = new std::thread(&hcp2::threadrecv,this);
+
+
 }
 
 hcp2::~hcp2()
@@ -355,4 +358,21 @@ void hcp2::SerialGPSDecodeSen(std::string strsen)
        else insstate = 4;
        if(rtkstate == 0)insstate = 3;
    }
+
+   iv::rawgps xrawgps;
+   xrawgps.macc_x = acc_x; xrawgps.macc_y = acc_y; xrawgps.macc_z = acc_z;
+   xrawgps.mfRoll = fRoll; xrawgps.mfPitch = fPitch; xrawgps.mfheading = fheading;
+   xrawgps.mgyro_x = gyro_x; xrawgps.mgyro_y = gyro_y;  xrawgps.mgyro_z = gyro_z;
+   xrawgps.mfHgt = fHgt;  xrawgps.mfLat = fLat;  xrawgps.mfLon = fLon;
+   xrawgps.mgpstime = gpstime;  xrawgps.mgpsweek = gpsweek;
+   xrawgps.mnsv1 = nsv1;  xrawgps.mnsv2 = nsv2;
+   xrawgps.minsstate = insstate;  xrawgps.mrtkstate = rtkstate;
+   xrawgps.mvn = vn;  xrawgps.mve = ve;  xrawgps.mvu = vu;
+   xrawgps.mfVel = fVel;  xrawgps.mfCalAcc = mfCalc_acc;
+
+   mmutexgps.lock();
+   mrawgps = xrawgps;
+   mmutexgps.unlock();
+
+   mhcp2fun(xrawgps);
 }

+ 41 - 1
src/apollo/apollolib/hcp2/hcp2.h

@@ -7,11 +7,45 @@
 #include <cstring>
 #include <thread>
 #include <vector>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+namespace iv {
+struct rawgps
+{
+    double mfheading;
+    double mfLat;
+    double mfLon;
+    double mfVel;
+    double mfPitch;
+    double mfRoll;
+    double mfHgt;
+    double mgyro_x;
+    double mgyro_y;
+    double mgyro_z;
+    double macc_x;
+    double macc_y;
+    double macc_z;
+    int mnsv1;
+    int mnsv2;
+    int mgpsweek;
+    int mgpstime;
+    int minsstate;
+    int mrtkstate;
+    double mvn;
+    double mve;
+    double mvu;
+    double mfCalAcc;
+};
+}
+
+typedef std::function<void(iv::rawgps xrawgps)> hcp2fun;
 
 class  hcp2
 {
 public:
-    hcp2(std::string strportname);
+    hcp2(std::string strportname,hcp2fun xFun);
     ~hcp2();
 
 private:
@@ -25,6 +59,12 @@ private:
     double mfCalc_acc = 0;
     double mfOldVel = 0;
 
+    iv::rawgps mrawgps;
+    std::mutex mmutexgps;
+
+    hcp2fun mhcp2fun;
+
+
 private:
     void threadrecv();
 

+ 2 - 0
src/apollo/apollolib/hcp2/hcp2.pro

@@ -27,3 +27,5 @@ unix {
     target.path = /usr/lib
 }
 !isEmpty(target.path): INSTALLS += target
+
+CONFIG += plugin

+ 73 - 0
src/apollo/code/apollodriver_hcp2/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 62 - 0
src/apollo/code/apollodriver_hcp2/apollodriver_hcp2.pro

@@ -0,0 +1,62 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH += /opt/apollo/neo/include
+INCLUDEPATH += /apollo_workspace/bazel-bin/external/apollo_src
+
+LIBS += -L/opt/apollo/neo/lib/cyber -lcyber -lcyber_binary -lcyber_state
+
+LIBS += /opt/apollo/neo/lib/cyber/component/*.so
+LIBS += /opt/apollo/neo/lib/cyber/context/*.so
+LIBS += /opt/apollo/neo/lib/cyber/io/*.so
+LIBS += /opt/apollo/neo/lib/cyber/logger/*.so
+LIBS += /opt/apollo/neo/lib/cyber/parameter/*.so
+LIBS += /opt/apollo/neo/lib/cyber/plugin_manager/*.so
+LIBS += /opt/apollo/neo/lib/cyber/node/*.so
+LIBS += /opt/apollo/neo/lib/cyber/blocker/*.so
+LIBS += /opt/apollo/neo/lib/cyber/class_loader/*.so
+LIBS += /opt/apollo/neo/lib/cyber/profiler/*.so
+LIBS += /opt/apollo/neo/lib/cyber/scheduler/*.so
+LIBS += /opt/apollo/neo/lib/cyber/service/*.so
+LIBS += /opt/apollo/neo/lib/cyber/statistics/*.so
+LIBS += /opt/apollo/neo/lib/cyber/task/*.so
+LIBS += /opt/apollo/neo/lib/cyber/common/*.so
+LIBS += /opt/apollo/neo/lib/cyber/service_discovery/*.so
+LIBS += /opt/apollo/neo/lib/cyber/transport/*.so
+LIBS += /opt/apollo/neo/lib/cyber/message/*.so
+LIBS += /opt/apollo/neo/lib/cyber/proto/*.so
+LIBS += /opt/apollo/neo/lib/cyber/croutine/*.so
+LIBS += /opt/apollo/neo/lib/cyber/event/*.so
+LIBS += /opt/apollo/neo/lib/cyber/time/*.so
+
+LIBS += -L/opt/apollo/neo/lib/3rd-fastdds-wrap -lfastrtps
+
+LIBS += -L/lib/aarch64-linux-gnu -lgflags -lglog
+
+LIBS += -L/usr/local/lib/ -lbvar
+
+LIBS += -L/opt/apollo/neo/lib/3rd-protobuf -lprotobuf
+
+LIBS += -L$$PWD -lhcp2
+

+ 75 - 0
src/apollo/code/apollodriver_hcp2/hcp2.h

@@ -0,0 +1,75 @@
+#ifndef HCP2_H
+#define HCP2_H
+
+
+#include <iostream>
+#include <string>
+#include <cstring>
+#include <thread>
+#include <vector>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+namespace iv {
+struct rawgps
+{
+    double mfheading;
+    double mfLat;
+    double mfLon;
+    double mfVel;
+    double mfPitch;
+    double mfRoll;
+    double mfHgt;
+    double mgyro_x;
+    double mgyro_y;
+    double mgyro_z;
+    double macc_x;
+    double macc_y;
+    double macc_z;
+    int mnsv1;
+    int mnsv2;
+    int mgpsweek;
+    int mgpstime;
+    int minsstate;
+    int mrtkstate;
+    double mvn;
+    double mve;
+    double mvu;
+    double mfCalAcc;
+};
+}
+
+typedef std::function<void(iv::rawgps xrawgps)> hcp2fun;
+
+class  hcp2
+{
+public:
+    hcp2(std::string strportname,hcp2fun xFun);
+    ~hcp2();
+
+private:
+    bool mbthreadrun = true;
+    std::thread * mpthread;
+    std::string mstrportname;
+
+    std::string mstrgpsdata;
+
+    int64_t mOldTime = 0;
+    double mfCalc_acc = 0;
+    double mfOldVel = 0;
+
+    iv::rawgps mrawgps;
+    std::mutex mmutexgps;
+
+    hcp2fun mhcp2fun;
+
+
+private:
+    void threadrecv();
+
+    void SerialGPSDecode();
+    void SerialGPSDecodeSen(std::string strsen);
+};
+
+#endif // HCP2_H

+ 26 - 0
src/apollo/code/apollodriver_hcp2/main.cpp

@@ -0,0 +1,26 @@
+#include <QCoreApplication>
+
+#include "cyber/cyber.h"
+#include "cyber/time/rate.h"
+#include "cyber/time/time.h"
+#include "hcp2.h"
+
+void hcp2callback(iv::rawgps xrawgps)
+{
+
+}
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    apollo::cyber::Init("apllodriver_hcp2");
+    std::unique_ptr<apollo::cyber::Node> pilot_node  = apollo::cyber::CreateNode("apllodriver_hcp2");
+
+    std::string strgpsport =  "/dev/ttyUSB0";
+    hcp2fun funcall = std::bind(&hcp2callback,std::placeholders::_1);
+    hcp2 xhcp2(strgpsport,funcall);
+
+    return a.exec();
+}