diff --git a/qt-gui.workspace.user b/qt-gui.workspace.user index f79686e..7691cc4 100644 --- a/qt-gui.workspace.user +++ b/qt-gui.workspace.user @@ -1,10 +1,10 @@ - + EnvironmentId - {87d6e2af-d768-4e25-a852-033ba8fb5a4a} + {1cdd7bd7-53f1-43dd-8e81-2dd8afa72b84} ProjectExplorer.Project.ActiveTarget @@ -19,7 +19,7 @@ Cpp - CppGlobal + ROSProject.CppCodeStyle @@ -54,33 +54,21 @@ ProjectExplorer.Project.PluginSettings - - - + ProjectExplorer.Project.Target.0 Desktop Desktop - {f4cc9e8d-34cc-4663-9466-ea6b16c693b9} + {53a1a275-3cec-4649-8add-1b460e25bc60} 0 0 0 - - true - CatkinMake Step - - ROSProjectManager.ROSCatkinMakeStep - - - - 0 - - 1 + 0 Build ProjectExplorer.BuildSteps.Build @@ -93,28 +81,11 @@ 2 false - - CMAKE_PREFIX_PATH=/home/ros/owr-qtgui/devel:/home/ros/owr_software/rover/devel:/home/ros/ros_deps/devel:/opt/ros/kinetic - LD_LIBRARY_PATH=/home/ros/owr-qtgui/devel/lib:/home/ros/owr_software/rover/devel/lib:/home/ros/ros_deps/devel/lib:/opt/ros/kinetic/lib:/opt/ros/kinetic/lib/x86_64-linux-gnu:/opt/qt57/lib/x86_64-linux-gnu:/opt/qt57/lib - PATH=/opt/ros/kinetic/bin:/opt/qt57/bin:/home/ros/bin:/home/ros/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - PKG_CONFIG_PATH=/home/ros/owr-qtgui/devel/lib/pkgconfig:/home/ros/owr_software/rover/devel/lib/pkgconfig:/home/ros/ros_deps/devel/lib/pkgconfig:/opt/ros/kinetic/lib/pkgconfig:/opt/ros/kinetic/lib/x86_64-linux-gnu/pkgconfig:/opt/qt57/lib/pkgconfig - PWD=/home/ros/owr-qtgui - PYTHONPATH=/home/ros/owr-qtgui/devel/lib/python2.7/dist-packages:/home/ros/owr_software/rover/devel/lib/python2.7/dist-packages:/home/ros/ros_deps/devel/lib/python2.7/dist-packages:/opt/ros/kinetic/lib/python2.7/dist-packages - ROSLISP_PACKAGE_DIRECTORIES=/home/ros/owr-qtgui/devel/share/common-lisp:/home/ros/owr_software/rover/devel/share/common-lisp:/home/ros/ros_deps/devel/share/common-lisp - ROS_DISTRO=kinetic - ROS_ETC_DIR=/opt/ros/kinetic/etc/ros - ROS_MASTER_URI=http://localhost:11311 - ROS_PACKAGE_PATH=/home/ros/owr-qtgui/src:/home/ros/owr_software/rover/src:/home/ros/ros_deps/src:/opt/ros/kinetic/share - ROS_ROOT=/opt/ros/kinetic/share/ros - ROS_VERSION=1 - SHLVL=3 - TERM=xterm - _=/usr/bin/env - + Debug Debug ROSProjectManager.ROSBuildConfiguration - 0 + 61797536 0 @@ -137,7 +108,7 @@ Release Release ROSProjectManager.ROSBuildConfiguration - 48753808 + 61797536 1 @@ -160,7 +131,7 @@ Release with Debug Information Release with Debug Information ROSProjectManager.ROSBuildConfiguration - 48753808 + 61797536 2 @@ -183,7 +154,7 @@ Minimum Size Release Minimum Size Release ROSProjectManager.ROSBuildConfiguration - 48753808 + 61797536 3 4 diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 526dc55..2235ca9 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -10,10 +10,10 @@ project(gui) ############################################################################## # qt_build provides the qt cmake glue, roscpp the comms for a default talker -find_package(catkin REQUIRED COMPONENTS qt_build roscpp sensor_msgs image_transport ros_video_components owr_messages) +find_package(catkin REQUIRED COMPONENTS qt_build roscpp sensor_msgs image_transport ros_video_components owr_messages usb_reset) set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${CATKIN_GLOBAL_LIB_DESTINATION}" ) set(QML_IMPORT_PATH2 "${QML_IMPORT_PATH};${CATKIN_GLOBAL_LIB_DESTINATION}" ) -include_directories(${catkin_INCLUDE_DIRS}) +include_directories(${catkin_INCLUDE_DIRS}; usb_reset) # Use this to define what the package will export (e.g. libs, headers). # Since the default here is to produce only a binary, we don't worry about # exporting anything. diff --git a/src/gui/package.xml b/src/gui/package.xml index 1510a7e..7912c96 100644 --- a/src/gui/package.xml +++ b/src/gui/package.xml @@ -47,6 +47,8 @@ sensor_msgs libqt4-dev ros_video_components + usb_reset + usb_reset ros_video_components qt_build image_transport diff --git a/src/gui/resources/main_window.qml b/src/gui/resources/main_window.qml index da3be17..9bde009 100644 --- a/src/gui/resources/main_window.qml +++ b/src/gui/resources/main_window.qml @@ -1,6 +1,7 @@ import QtQuick 2.5 import QtQuick.Window 2.2 import bluesat.owr 1.0 +import QtQuick.Controls 1.4 @@ -73,6 +74,7 @@ Window { Item { id: signal_strength_container + width: 173 z: 4 anchors.right: parent.right anchors.rightMargin: 0 @@ -233,4 +235,50 @@ Window { height: 80 } + + + + Item { + id: usb_reset_container + z: 5 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.top: parent.top + anchors.topMargin: 80 + anchors.left: parent.right + anchors.leftMargin: -700 + anchors.bottom: parent.top + anchors.bottomMargin: -300 + ROSUsbReset { + signal recieved(int upd) + // @disable-check M16 + objectName: "usb_reset" + id: usb_reset + // @disable-check M16` + anchors.bottom: parent.bottom + // @disable-check M16 + anchors.bottomMargin: 0 + // @disable-check M16 + anchors.top: parent.top + // @disable-check M16 + anchors.left: parent.left + // @disable-check M16 + anchors.right: parent.right + // @disable-check M16 + topic: qsTr("/rover/usb") + ListView { + model: usbDevices + id: list + width: 500 + height: 1000 + spacing: 10 + delegate: Button {text: "Reset" + onClicked: { + usb_reset.publish(index) + } + } + } + } + + } } diff --git a/src/gui/src/main_application.cpp b/src/gui/src/main_application.cpp index 578644c..7f9783d 100644 --- a/src/gui/src/main_application.cpp +++ b/src/gui/src/main_application.cpp @@ -8,6 +8,7 @@ #include "ros_video_components/ros_joystick_listener.hpp" #include "ros_video_components/ros_drive_mode.hpp" #include "gui/main_application.hpp" +#include "usb_reset/usb_reset.hpp" Main_Application::Main_Application() {} @@ -19,6 +20,7 @@ void Main_Application::run() { qmlRegisterType("bluesat.owr", 1, 0, "ROSTimer"); qmlRegisterType("bluesat.owr", 1, 0, "ROSJoystickListener"); qmlRegisterType("bluesat.owr", 1, 0, "ROSDriveMode"); + qmlRegisterType("bluesat.owr", 1, 0, "ROSUsbReset"); // this loads the qml file we are about to create this->load(QUrl(QStringLiteral("qrc:/main_window.qml"))); @@ -48,6 +50,10 @@ void Main_Application::run() { Ros_Drive_Mode * drive_mode = this->rootObjects()[0]->findChild(QString("drive_mode")); drive_mode->setup(&nh); + //this->rootContext passes the root context of main_window.qml + ROS_Usb_Reset * usb_reset = this->rootObjects()[0]->findChild(QString("usb_reset")); + usb_reset->setup(&nh, this->rootContext()); + // setup the timer ROSTimer * stopwatch = this->rootObjects()[0]->findChild(QString("timerDisplay")); // the following code section is for debugging diff --git a/src/owr_messages/CMakeLists.txt b/src/owr_messages/CMakeLists.txt index 890c1cf..6f979f1 100644 --- a/src/owr_messages/CMakeLists.txt +++ b/src/owr_messages/CMakeLists.txt @@ -51,7 +51,19 @@ find_package(catkin REQUIRED COMPONENTS add_message_files( FILES activeCameras.msg + camera_angle.msg + motor.msg + status.msg stream.msg + position.msg + voltage.msg + ultrasonic.msg + heading.msg + pwm.msg + board.msg + adc.msg + stop.msg + devices.msg ) ## Generate services in the 'srv' folder diff --git a/src/owr_messages/msg/adc.msg b/src/owr_messages/msg/adc.msg new file mode 100644 index 0000000..f89a760 --- /dev/null +++ b/src/owr_messages/msg/adc.msg @@ -0,0 +1,3 @@ +Header header +float32[] pot +string[] potFrame diff --git a/src/owr_messages/msg/board.msg b/src/owr_messages/msg/board.msg new file mode 100644 index 0000000..add85e6 --- /dev/null +++ b/src/owr_messages/msg/board.msg @@ -0,0 +1,2 @@ +pwm[] joints +Header header \ No newline at end of file diff --git a/src/owr_messages/msg/camera_angle.msg b/src/owr_messages/msg/camera_angle.msg new file mode 100644 index 0000000..d18e1e9 --- /dev/null +++ b/src/owr_messages/msg/camera_angle.msg @@ -0,0 +1,3 @@ +geometry_msgs/Vector3 angle +int32 feed_number + diff --git a/src/owr_messages/msg/devices.msg b/src/owr_messages/msg/devices.msg new file mode 100644 index 0000000..c4195ec --- /dev/null +++ b/src/owr_messages/msg/devices.msg @@ -0,0 +1 @@ +string[] devices \ No newline at end of file diff --git a/src/owr_messages/msg/heading.msg b/src/owr_messages/msg/heading.msg new file mode 100644 index 0000000..45c0beb --- /dev/null +++ b/src/owr_messages/msg/heading.msg @@ -0,0 +1 @@ +float64 heading diff --git a/src/owr_messages/msg/camera_angle~ b/src/owr_messages/msg/motor.msg similarity index 73% rename from src/owr_messages/msg/camera_angle~ rename to src/owr_messages/msg/motor.msg index 1600bca..0501815 100644 --- a/src/owr_messages/msg/camera_angle~ +++ b/src/owr_messages/msg/motor.msg @@ -1,3 +1,3 @@ -Vector3 angle -Int32 feed_number +float64 angle +int32 motor_number diff --git a/src/owr_messages/msg/position.msg b/src/owr_messages/msg/position.msg new file mode 100644 index 0000000..90dafb8 --- /dev/null +++ b/src/owr_messages/msg/position.msg @@ -0,0 +1,35 @@ +# Message that reports the position, and orientation of the robot +# Location specified using the WGS 84 reference ellipsoid + +#Based on the NavSatFix message here: http://docs.ros.org/api/sensor_msgs/html/msg/NavSatFix.html + + +# Latitude [degrees]. Positive is north of equator; negative is south. +float64 latitude + +# Longitude [degrees]. Positive is east of prime meridian; negative is west. +float64 longitude + + +# Altitude [m]. Positive is above the WGS 84 ellipsoid +# (quiet NaN if no altitude is available). +float64 altitude + +#The orientation of the front of the rover +#relative to grid North on the WGS 84 datum +#where 0 deg is Grid North +float64 orientation + +#The pitch of the robot (facing forward), in degrees. +#0 being level to the horizon, and positive being facing above the horizon (nose up) +#rotation is around the centre of the robot +float64 pitch + +#The roll of the robot (forward facing) +#0 deg is level with the horizon, Positive is left up +float64 roll + +#The heading relative to the grid north. (WGS 84) +float64 heading + + diff --git a/src/owr_messages/msg/pwm.msg b/src/owr_messages/msg/pwm.msg new file mode 100644 index 0000000..4864efa --- /dev/null +++ b/src/owr_messages/msg/pwm.msg @@ -0,0 +1,6 @@ +string joint +int32 pwm +float64 targetVel +float64 currentVel +float64 currentPos +float64 targetPos \ No newline at end of file diff --git a/src/owr_messages/msg/status.msg b/src/owr_messages/msg/status.msg new file mode 100644 index 0000000..5091dfa --- /dev/null +++ b/src/owr_messages/msg/status.msg @@ -0,0 +1,2 @@ +float32 battery +float32 signal diff --git a/src/owr_messages/msg/stop.msg b/src/owr_messages/msg/stop.msg new file mode 100644 index 0000000..b956b40 --- /dev/null +++ b/src/owr_messages/msg/stop.msg @@ -0,0 +1,2 @@ +bool stopP +bool stopN \ No newline at end of file diff --git a/src/owr_messages/msg/ultrasonic.msg b/src/owr_messages/msg/ultrasonic.msg new file mode 100644 index 0000000..ba2ec77 --- /dev/null +++ b/src/owr_messages/msg/ultrasonic.msg @@ -0,0 +1 @@ +int64[] pulseTime #pulse in microseconds (uS) diff --git a/src/owr_messages/msg/voltage.msg b/src/owr_messages/msg/voltage.msg new file mode 100644 index 0000000..226a8d8 --- /dev/null +++ b/src/owr_messages/msg/voltage.msg @@ -0,0 +1 @@ +float32 voltage diff --git a/src/ros_video_components/package.xml b/src/ros_video_components/package.xml index 0525090..d1fcc57 100644 --- a/src/ros_video_components/package.xml +++ b/src/ros_video_components/package.xml @@ -40,21 +40,21 @@ - catkin - qt_build - roscpp - image_transport - sensor_msgs - libqt4-dev - owr_messages - qt_build - image_transport - sensor_msgs - roscpp - libqt4-dev - owr_messages +catkin +qt_build +roscpp +image_transport +sensor_msgs +libqt4-dev +owr_messages +qt_build +image_transport +sensor_msgs +roscpp +libqt4-dev +owr_messages diff --git a/src/usb_reset/CMakeLists.txt b/src/usb_reset/CMakeLists.txt new file mode 100644 index 0000000..7757a55 --- /dev/null +++ b/src/usb_reset/CMakeLists.txt @@ -0,0 +1,222 @@ +cmake_minimum_required(VERSION 2.8.3) +project(usb_reset) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + owr_messages + roscpp + std_msgs + qt_build +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +include_directories(include ${catkin_INCLUDE_DIRS}) +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( + INCLUDE_DIRS include + LIBRARIES UsbReset + CATKIN_DEPENDS owr_messages roscpp std_msgs qt_build +# DEPENDS system_lib +) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# std_msgs +# ) + +############################################################################## +# Qt Environment +############################################################################## + +# this comes from qt_build's qt-ros.cmake which is automatically +# included via the dependency ca ll in package.xml +find_package(Qt5 COMPONENTS Core Qml Widgets Quick REQUIRED) + +############################################################################## +# Sections +############################################################################## + +file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc) +file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/usb_reset/*.hpp) + +QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES}) +QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC}) + +############################################################################## +# Sources +############################################################################## + +file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +#include_directories( +# ${catkin_INCLUDE_DIRS} +# include usb_reset +#) + +## Declare a C++ library +# add_library(usb_reset +# src/${usb_reset}/usb_reset.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(usb_reset ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +# add_executable(usb_reset_node src/usb_reset_node.cpp) + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(usb_reset_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(usb_reset_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS usb_reset usb_reset_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_usb_reset.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +############################################################################## +# Binaries +############################################################################## +add_library(UsbReset ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP}) +qt5_use_modules(UsbReset Quick Core Widgets) +target_link_libraries(UsbReset ${QT_LIBRARIES} ${catkin_LIBRARIES}) +target_include_directories(UsbReset PUBLIC include) diff --git a/src/usb_reset/include/usb_reset/usb_reset.hpp b/src/usb_reset/include/usb_reset/usb_reset.hpp new file mode 100644 index 0000000..a427108 --- /dev/null +++ b/src/usb_reset/include/usb_reset/usb_reset.hpp @@ -0,0 +1,75 @@ +/* + * Date Started: 11/08/18 + * Original Author: Lasindu Shanil de Silva + * Editors: + * Purpose: Widget to create buttons to reset usb devices + * This code is released under the MIT License. Copyright BLUEsat UNSW, 2019 + */ +#ifndef ROS_USB_RESET_H +#define ROS_USB_RESET_H + +//ROS +#include +#include "std_msgs/String.h" +#include +#include +#include "owr_messages/devices.h" + +//QT +//#include +//#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class ROS_Usb_Reset : public QQuickPaintedItem { + //make this a Qt Widget + Q_OBJECT + // defines a qml value for the topic + Q_PROPERTY(QString topic READ get_topic WRITE set_topic NOTIFY topic_changed) + + + public: + // Constructor, takes parent widget, which defaults to null + ROS_Usb_Reset(QQuickItem * parent = 0); + + void paint(QPainter *painter); + void setup(ros::NodeHandle * nh, QQmlContext *ctxt); + Q_INVOKABLE void publish(int num); + Q_INVOKABLE int num_devices(); + + protected: + + //getters and setters + void set_topic(const QString &new_value); + QString get_topic() const; + + signals: + void topic_changed(); + + private: + void receive_msg(const owr_messages::devices::ConstPtr & msg); + + // ROS + ros::NodeHandle * nh; + ros::Subscriber usb_sub; + ros::Publisher usb_pub; + QString topic_value; + bool ros_ready; + QQmlContext *curr_ctxt; + + // Used for storing attached devices + std::string devices[100]; + // Holds number of attached devices + int num; +}; + +#endif // ROS_USB_RESET_H diff --git a/src/usb_reset/package.xml b/src/usb_reset/package.xml new file mode 100644 index 0000000..f4a8da8 --- /dev/null +++ b/src/usb_reset/package.xml @@ -0,0 +1,61 @@ + + + usb_reset + 0.0.0 + The usb_reset package + + + + + ros + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + owr_messages + roscpp + std_msgs + qt_build + libqt4-dev + + libqt4-dev + qt_build + owr_messages + roscpp + std_msgs + + + + + + + + diff --git a/src/usb_reset/qmldir b/src/usb_reset/qmldir new file mode 100644 index 0000000..6d86360 --- /dev/null +++ b/src/usb_reset/qmldir @@ -0,0 +1,3 @@ +module bluesat.owr +plugin RosVideoComponents +designersupported diff --git a/src/usb_reset/src/usb_reset.cpp b/src/usb_reset/src/usb_reset.cpp new file mode 100644 index 0000000..910153d --- /dev/null +++ b/src/usb_reset/src/usb_reset.cpp @@ -0,0 +1,89 @@ +#include "usb_reset/usb_reset.hpp" + +int num = 0; + +ROS_Usb_Reset::ROS_Usb_Reset(QQuickItem * parent) : + QQuickPaintedItem(parent), + topic_value(), + ros_ready(false), + num(0), + devices() { + +} + +void ROS_Usb_Reset::setup(ros::NodeHandle * nh, QQmlContext *ctxt) { + usb_sub = nh->subscribe( + "rover/usb", + 1, + &ROS_Usb_Reset::receive_msg, + this + ); + usb_pub = nh->advertise( + "rover/usb/reset", + 1, + false + ); + + ros_ready = true; + curr_ctxt = ctxt; + ROS_INFO("Setup of usb component complete"); +} + +void ROS_Usb_Reset::receive_msg(const owr_messages::devices::ConstPtr & msg) { + int i = 0; + for(; i < msg->devices.size(); i++) { + devices[i] = msg->devices[i]; + } + num = i; + update(); +} + +void ROS_Usb_Reset::paint(QPainter * painter) {QLinearGradient linearGradient(0, 0, 100, 100); + linearGradient.setColorAt(0.2, Qt::yellow); + painter->setBrush(linearGradient); + painter->setPen(Qt::green); + int i = 0; + //create the neccessary number of buttons + curr_ctxt->setContextProperty("usbDevices", (num - 1)); + for (; i < num - 1; i++) { + //write the name of the usb device + painter->drawText(75,(i*35) + 15, QString::fromStdString(devices[i])); + } + +} + +void ROS_Usb_Reset::set_topic(const QString & new_value) { + ROS_INFO("new value %s", new_value.toStdString().c_str()); + if(topic_value != new_value) { + topic_value = new_value; + if(!topic_value.isEmpty()) { + if(ros_ready) { + ROS_INFO("new value %s", new_value.toStdString().c_str()); + usb_sub.shutdown(); + usb_sub = nh->subscribe( + topic_value.toStdString(), + 1, + &ROS_Usb_Reset::receive_msg, + this + ); + } + } else { + usb_sub.shutdown(); + } + emit topic_changed(); + } +} + +QString ROS_Usb_Reset::get_topic() const { + return topic_value; +} + +void ROS_Usb_Reset::publish(int num) { + std_msgs::Int16 a; + a.data = num; + usb_pub.publish(a); +} + +int ROS_Usb_Reset::num_devices() { + return num; +}