Skip to content

Commit

Permalink
feat: add dynamixel_rdk_manager node
Browse files Browse the repository at this point in the history
- dynamixel status GUI support
- dynamixel position, velocity, acceleration publish (dynamixel_control_msgs) available
  • Loading branch information
mjlee111 committed Nov 19, 2024
1 parent 11a6b05 commit 9232d6e
Show file tree
Hide file tree
Showing 10 changed files with 932 additions and 0 deletions.
49 changes: 49 additions & 0 deletions dynamixel_rdk_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.5)
project(dynamixel_rdk_manager)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# find dependencies
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()
find_package(rclcpp REQUIRED)
find_package(Boost 1.71.0 REQUIRED COMPONENTS thread)
find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)
find_package(dynamixel_rdk_msgs REQUIRED)

file(GLOB PRO_SOURCE_DIR RELATIVE ${CMAKE_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)
file(GLOB PRO_UI_DIR RELATIVE ${CMAKE_SOURCE_DIR} FOLLOW_SYMLINKS ui/*.ui)
file(GLOB PRO_INCLUDE_DIR RELATIVE ${CMAKE_SOURCE_DIR} FOLLOW_SYMLINKS include/${PROJECT_NAME}/*.h include/${PROJECT_NAME}/*.hpp)
file(GLOB PRO_RESOURCE_DIR RELATIVE ${CMAKE_SOURCE_DIR} FOLLOW_SYMLINKS resource/*.qrc)

qt5_wrap_ui(QT_UI_HPP ${PRO_UI_DIR})
qt5_wrap_cpp(QT_MOC_HPP ${PRO_INCLUDE_DIR})
qt5_add_resources(QT_RESOUCE_HPP ${PRO_RESOURCE_DIR})

include_directories(
include/
${CMAKE_CURRENT_BINARY_DIR}
)
add_executable(${PROJECT_NAME}
${PRO_SOURCE_DIR}
${PRO_INCLUDE_DIR}
${PRO_UI_DIR}
${QT_MOC_HPP}
${QT_RESOUCE_HPP}
${QT_UI_HPP}
)
ament_target_dependencies(${PROJECT_NAME} rclcpp Boost dynamixel_rdk_msgs)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Core Qt5::Gui)
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2024 Myeong Jin Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef dynamixel_rdk_manager_MAIN_WINDOW_H
#define dynamixel_rdk_manager_MAIN_WINDOW_H

/*****************************************************************************
** Includes
*****************************************************************************/

#include "QIcon"
#include "qnode.hpp"
#include "ui_mainwindow.h"

#include <rclcpp/rclcpp.hpp>

#include <QAbstractTableModel>
#include <QLayoutItem>
#include <QMainWindow>
#include <QTableWidget>
#include <QVariant>
#include <string>
#include <thread>
#include <vector>

/*****************************************************************************
** Interface [MainWindow]
*****************************************************************************/
/**
* @brief Qt central, all operations relating to the view part here.
*/
class MainWindow : public QMainWindow
{
Q_OBJECT

public: // Public Functions
MainWindow(QWidget * parent = nullptr);
~MainWindow();

void setup_table();

public: // Public Variables
QNode * qnode;

public Q_SLOTS:
void update_data();
void update_id_list();

void on_idList_currentIndexChanged(int index);
void on_goal_pos_slider_valueChanged(int value);
void on_goal_vel_slider_valueChanged(int value);
void on_goal_acc_slider_valueChanged(int value);
void on_pub_btn_clicked();

private:
Ui::MainWindow * ui;
void closeEvent(QCloseEvent * event);
QTableWidget * table_widget_;
};

#endif // dynamixel_rdk_manager_MAIN_WINDOW_H
83 changes: 83 additions & 0 deletions dynamixel_rdk_manager/include/dynamixel_rdk_manager/qnode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2024 Myeong Jin Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef dynamixel_rdk_manager_QNODE_HPP_
#define dynamixel_rdk_manager_QNODE_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/
#ifndef Q_MOC_RUN
#include <rclcpp/rclcpp.hpp>
#endif
#include <dynamixel_rdk_msgs/msg/dynamixel_bulk_read_msgs.hpp>
#include <dynamixel_rdk_msgs/msg/dynamixel_control_msgs.hpp>

#include <QThread>
#include <vector>

/*****************************************************************************
** Class
*****************************************************************************/
class QNode : public QThread
{
Q_OBJECT
public: // Public Functions
QNode();
~QNode();

void control_publish();

protected: // Protected Functions
void run();

private: // Private Functions
void status_callback(const dynamixel_rdk_msgs::msg::DynamixelBulkReadMsgs & msg);

private: // Private Variables
std::shared_ptr<rclcpp::Node> node;
rclcpp::Subscription<dynamixel_rdk_msgs::msg::DynamixelBulkReadMsgs>::SharedPtr bulk_read_sub_;
rclcpp::Publisher<dynamixel_rdk_msgs::msg::DynamixelControlMsgs>::SharedPtr control_pub_;

public: // Public Variables
// Status
std::vector<uint8_t> dynamixel_ids_;
std::vector<bool> torque_enabled_;
std::vector<std::string> dynamixel_types_;
std::vector<uint8_t> error_status_;
std::vector<double> present_positions_;
std::vector<double> present_velocities_;
std::vector<double> present_accelerations_;
std::vector<double> present_currents_;
std::vector<double> present_voltages_;
std::vector<double> present_temperatures_;
std::vector<std::pair<double, double>> min_max_positions_;

// Control
std::vector<double> goal_positions_;
std::vector<double> goal_velocities_;
std::vector<double> goal_accelerations_;

int dynamixel_size_ = 0;
bool is_size_initialized_ = false;

Q_SIGNALS: // Q_SIGNALS
void rosShutDown();
void update_data();
void update_id_list();
};

#endif /* dynamixel_rdk_manager_QNODE_HPP_ */
20 changes: 20 additions & 0 deletions dynamixel_rdk_manager/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<name>dynamixel_rdk_manager</name>
<version>0.1.0</version>
<description>

simple dynamixel RDK manager GUI

</description>
<maintainer email="menggu1234@naver.com">Myeong Jin Lee</maintainer>
<author>Myeong Jin Lee</author>
<license>Apache License 2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Binary file added dynamixel_rdk_manager/resources/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions dynamixel_rdk_manager/resources/resource.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>images/logo.png</file>
</qresource>
</RCC>
28 changes: 28 additions & 0 deletions dynamixel_rdk_manager/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024 Myeong Jin Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "../include/dynamixel_rdk_manager/main_window.hpp"

#include <QApplication>
#include <iostream>

int main(int argc, char * argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Loading

0 comments on commit 9232d6e

Please sign in to comment.