From 68803740dc2ccb45a75134406b7848b8586a45c6 Mon Sep 17 00:00:00 2001 From: yikestone Date: Sat, 7 Dec 2019 16:35:16 +0530 Subject: [PATCH] synchronized and blinking recording --- .gitignore | 2 +- gazebo_sim/package.xml | 7 +++ qt_pi/CMakeLists.txt | 60 ++++++++++----------- qt_pi/include/ble_connect/ble_connect.h | 2 +- qt_pi/include/mapview/mapview.h | 15 ++++-- qt_pi/include/speller/speller.h | 28 +++++++--- qt_pi/package.xml | 1 - qt_pi/src/main.cpp | 9 ++-- qt_pi/src/mapview.cpp | 40 ++++---------- qt_pi/src/speller.cpp | 72 ++++++++++++++++++++++++- 10 files changed, 157 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index c057cef..eb0f44a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/scripts/qt_pi/*.pyc +*.pyc .ccls-cache compile_commands.json diff --git a/gazebo_sim/package.xml b/gazebo_sim/package.xml index aa85652..7486499 100644 --- a/gazebo_sim/package.xml +++ b/gazebo_sim/package.xml @@ -5,6 +5,13 @@ Rishabh Kundu MIT catkin + gmapping + amcl + move_base + depthimage_to_laserscan + map_server + static_transform_publisher + teleop_twist_keyboard diff --git a/qt_pi/CMakeLists.txt b/qt_pi/CMakeLists.txt index b5d24c9..89b083e 100644 --- a/qt_pi/CMakeLists.txt +++ b/qt_pi/CMakeLists.txt @@ -1,62 +1,62 @@ cmake_minimum_required(VERSION 2.8.3) project(qt_pi) -set(CMAKE_CXX_FLAGS "-fpermissive -std=c++0x") - +set(CMAKE_CXX_FLAGS "-std=c++0x") +#-fpermissive +#ros setup find_package(catkin REQUIRED COMPONENTS qt_build roscpp roslib ) -find_package(Qt5 REQUIRED COMPONENTS Core Gui OpenGL) - - -#set(FORMS ui/speller.ui) -set(MOC include/mapview/mapview.h) -set(HPP include/speller/speller.h include/mapview/vertex.h) -set(SRCS src/speller.cpp src/mapview.cpp ) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -#qt5_wrap_ui(FORMS_HPP ${FORMS}) -qt5_wrap_cpp(MOC_HPP ${MOC}) -qt5_add_resources(RCC resources/resources.qrc) - catkin_python_setup() catkin_package(DEPENDS) +#Qt setup and MOC generation +find_package(Qt5 REQUIRED COMPONENTS Core Gui OpenGL) +set(MOC include/speller/speller.h include/mapview/mapview.h) +set(HPP include/mapview/vertex.h) +set(SRCS src/speller.cpp src/mapview.cpp ) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +qt5_wrap_cpp(MOC_HPP ${MOC}) +qt5_add_resources(RCC resources/resources.qrc) + + + + + +#Mcrypt library includes find_package(PkgConfig REQUIRED) - -find_path(Mcrypt_INCLUDE_DIR mcrypt.h PATHS - /usr/include -) - +find_path(Mcrypt_INCLUDE_DIR mcrypt.h PATHS /usr/include) set(Mcrypt_LIB_PATHS /usr/lib) find_library(Mcrypt_LIBS NAMES mcrypt rtfilter PATHS ${Mcrypt_LIB_PATHS}) +include_directories(${Mcrypt_INCLUDE_DIRS}) +link_directories(${Mcrypt_LIBS}) -include_directories(include -${catkin_INCLUDE_DIRS} -) - +#Gattlib includes pkg_search_module(GATTLIB REQUIRED gattlib) pkg_search_module(GLIB REQUIRED glib-2.0) include_directories(${GLIB_INCLUDE_DIRS}) -include_directories(${Mcrypt_INCLUDE_DIRS}) -link_directories(${Mcrypt_LIBS}) +include_directories(include + ${catkin_INCLUDE_DIRS} +) + +#ble_connect library generation add_library(ble_connect include/ble_connect/ble_connect.h src/ble_connect.c) - target_link_libraries(ble_connect ${GATTLIB_LIBRARIES} ${GATTLIB_LDFLAGS} ${GLIB_LDFLAGS} pthread ${Mcrypt_LIBS}) +#ble_connect_test executable generation add_executable(ble_connect_test tests/ble_test.cpp) target_link_libraries(ble_connect_test ble_connect) - +#speller library generation add_library(speller ${SRCS} ${FORMS_HPP} ${MOC_HPP} ${RCC} ${HPP}) -target_link_libraries(speller Qt5::Widgets Qt5::Core Qt5::OpenGL Qt5::Gui ${catkin_LIBRARIES}) +target_link_libraries(speller Qt5::Widgets Qt5::Core Qt5::OpenGL Qt5::Gui ${catkin_LIBRARIES} ble_connect) +#main executable generation add_executable(speller_ui src/main.cpp) target_link_libraries(speller_ui speller) diff --git a/qt_pi/include/ble_connect/ble_connect.h b/qt_pi/include/ble_connect/ble_connect.h index 511a78f..c5cccbc 100644 --- a/qt_pi/include/ble_connect/ble_connect.h +++ b/qt_pi/include/ble_connect/ble_connect.h @@ -14,7 +14,7 @@ enum Channels { AF3 = 0, T7 = 1, Pz = 2, T8 = 3, AF4 = 4 }; struct insight_data { double uV[5]; struct timespec ts; -} insight_data; +}; #ifdef __cplusplus extern "C" { #endif diff --git a/qt_pi/include/mapview/mapview.h b/qt_pi/include/mapview/mapview.h index e338ee5..87821d7 100644 --- a/qt_pi/include/mapview/mapview.h +++ b/qt_pi/include/mapview/mapview.h @@ -21,29 +21,38 @@ class MapView : public QOpenGLWindow, protected QOpenGLFunctions_3_1 { public: explicit MapView(QWidget *parent = 0); ~MapView(); + void start_blinking(); void stop_blinking(); - volatile int sleep_control = 1; + void toggle_blinking(); protected: GLsizei count; GLint startingElements[4] = {0, 4, 8, 12}; GLsizei counts[4] = {4, 4, 4, 4}; + void initializeGL() override; void paintGL() override; void resizeGL(int, int) override; void teardownGL(); void printContextInformation(); + signals: void update_GUI(); + void keyPress(QKeyEvent *key); private: QOpenGLBuffer m_vertex; QOpenGLVertexArrayObject m_object; QOpenGLShaderProgram *m_program; - void run(); + + volatile int sleep_control = 1; + volatile int blinking; + std::thread *t; - int blinking; + + void run(); + void keyPressEvent(QKeyEvent *key) override; // QTimer *t1; // QTimer *t2; // QTimer *t3; diff --git a/qt_pi/include/speller/speller.h b/qt_pi/include/speller/speller.h index cdc5928..5d90381 100644 --- a/qt_pi/include/speller/speller.h +++ b/qt_pi/include/speller/speller.h @@ -1,18 +1,34 @@ #ifndef SPELLER #define SPELLER -#include +#include "ble_connect/ble_connect.h" +#include "mapview/mapview.h" +#include +#include +#include +#include +#include +#include +#include #include -class Speller { - +class Speller : public QThread { + Q_OBJECT public: - explicit Speller(ros::NodeHandle _nh); + explicit Speller(int argc, char **argv); ~Speller(); - + const std::map frequency = { + {4.286f, 14}, {5.0f, 12}, {6.0f, 10}, {7.5f, 8}}; MapView *window; private: - ros::NodeHandle nh; + int argc; + char **argv; + void run() override; +private slots: + void keyEvent(QKeyEvent *key); + +private: + volatile int spelling; }; #endif diff --git a/qt_pi/package.xml b/qt_pi/package.xml index 17b5179..be01063 100644 --- a/qt_pi/package.xml +++ b/qt_pi/package.xml @@ -10,7 +10,6 @@ roslib rospy - std_msgs geometry_msgs nav_msgs tf diff --git a/qt_pi/src/main.cpp b/qt_pi/src/main.cpp index 56466f9..69e200a 100644 --- a/qt_pi/src/main.cpp +++ b/qt_pi/src/main.cpp @@ -3,9 +3,9 @@ #include int main(int argc, char *argv[]) { + QGuiApplication app(argc, argv); - ros::init(argc, argv, "speller"); - ros::NodeHandle nh; + QSurfaceFormat format; format.setSwapInterval(1); format.setRenderableType(QSurfaceFormat::OpenGL); @@ -13,11 +13,10 @@ int main(int argc, char *argv[]) { format.setVersion(3, 3); // Set the window up - Speller spell(nh); - + Speller spell(argc, argv); spell.window->setFormat(format); - // spell.window->resize(QSize(800, 600)); spell.window->show(); + // spell.start(); return app.exec(); } diff --git a/qt_pi/src/mapview.cpp b/qt_pi/src/mapview.cpp index e35a6f8..1937304 100644 --- a/qt_pi/src/mapview.cpp +++ b/qt_pi/src/mapview.cpp @@ -2,6 +2,7 @@ MapView::MapView(QWidget *parent) { connect(this, SIGNAL(update_GUI()), this, SLOT(update())); + blinking = 0; count = 4; } @@ -22,6 +23,13 @@ void MapView::stop_blinking() { free(t); } +void MapView::toggle_blinking() { + if (blinking) + stop_blinking(); + else + start_blinking(); +} + void MapView::start_blinking() { if (blinking) return; @@ -64,17 +72,6 @@ void MapView::run() { std::chrono::high_resolution_clock::now() - time) .count()); } - - // while (blinking) { - // emit(update_GUI()); - // printf("WOah\n"); - // - // count = 4; - // sleep(1); - // emit(update_GUI()); - // count = 0; - // sleep(1); - // } } static const Vertex sg_vertexes[] = { @@ -98,25 +95,6 @@ static const Vertex sg_vertexes[] = { Vertex(QVector3D(0.45f, -0.45f, 1.0f), QVector3D(0.75f, 0.75f, 0.75f)), Vertex(QVector3D(0.55f, -0.45f, 1.0f), QVector3D(0.75f, 0.75f, 0.75f)), - // Vertex(QVector3D(-0.75f, 0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.25f, 0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.25f, 0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.75f, 0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // - // Vertex(QVector3D(-0.75f, -0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.25f, -0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.25f, -0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(-0.75f, -0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // - // Vertex(QVector3D(0.75f, 0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.25f, 0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.25f, 0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.75f, 0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // - // Vertex(QVector3D(0.75f, -0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.25f, -0.75f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.25f, -0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)), - // Vertex(QVector3D(0.75f, -0.25f, 1.0f), QVector3D(0.0f, 0.0f, 0.0f)) }; void MapView::initializeGL() { @@ -208,3 +186,5 @@ void MapView::teardownGL() { m_vertex.destroy(); delete m_program; } + +void MapView::keyPressEvent(QKeyEvent *key) { emit(keyPress(key)); } diff --git a/qt_pi/src/speller.cpp b/qt_pi/src/speller.cpp index f1e5be9..40843a3 100644 --- a/qt_pi/src/speller.cpp +++ b/qt_pi/src/speller.cpp @@ -1,5 +1,73 @@ #include "speller/speller.h" -Speller::Speller(ros::NodeHandle _nh) : nh(_nh) { window = new MapView(); } +Speller::Speller(int ar, char **av) { + argc = ar; + argv = av; + spelling = 0; + window = new MapView(); + connect(window, SIGNAL(keyPress(QKeyEvent *)), this, + SLOT(keyEvent(QKeyEvent *))); -Speller::~Speller() {} + const char *a = "EF:BD:39:4E:08:49"; + const char *b = "81072f41-9f3d-11e3-a9dc-0002a5d5c51b"; + insight_init(a, b); +} + +Speller::~Speller() { + insight_stop_notif(); + insight_destroy(); + this->terminate(); +} + +void Speller::run() { + + const std::string node_name = "speller"; + + ros::init(argc, argv, node_name); + ros::NodeHandle nh; + ros::Publisher pub = + nh.advertise("/move_base_simple/goal", 1); + geometry_msgs::PoseStamped msg; + geometry_msgs::Pose pose; + geometry_msgs::Point point; + geometry_msgs::Quaternion quat; + pose.position = point; + pose.orientation = quat; + msg.pose = pose; + point.x = 0; + point.y = 0; + point.z = 0; + quat.w = 1; + quat.x = 0; + quat.y = 0; + quat.z = 0; + + while (ros::ok()) { + while (spelling) { + int len = 1000; + struct insight_data *buf = + (struct insight_data *)malloc(sizeof(struct insight_data) * len); + + window->start_blinking(); + insight_write_to_buffer(len, buf); + + while (insight_buffer_status() == 1) + sleep(0); + + window->stop_blinking(); + + // TODO-Send data for classification + // int a; if((a = classify(len, buf))) window->zoom(a); + } + } +} + +void Speller::keyEvent(QKeyEvent *e) { + if (e->key() == Qt::Key_Space) { + if (!spelling) + insight_start_notif(); + else + insight_stop_notif(); + spelling = !spelling; + } +}