Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add joint position controller GUI, also enable tests for GUI plugins #534

Merged
merged 7 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/gui/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ endfunction()
#
# [QT_HEADERS]: Qt headers that need to be moc'ed
#
# [TEST_SOURCES]: Source files for unit tests.
#
# [PUBLIC_LINK_LIBS]: Specify a list of libraries to be publicly linked.
#
# [PRIVATE_LINK_LIBS]: Specify a list of libraries to be privately linked.
#
function(gz_add_gui_plugin plugin_name)
set(options)
set(oneValueArgs)
set(multiValueArgs SOURCES QT_HEADERS PUBLIC_LINK_LIBS PRIVATE_LINK_LIBS)
set(multiValueArgs
SOURCES
QT_HEADERS
TEST_SOURCES
PUBLIC_LINK_LIBS
PRIVATE_LINK_LIBS
)

cmake_parse_arguments(gz_add_gui_plugin "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

Expand All @@ -75,6 +83,22 @@ function(gz_add_gui_plugin plugin_name)
PRIVATE_LINK_LIBS ${gz_add_gui_plugin_PRIVATE_LINK_LIBS} ignition-plugin${IGN_PLUGIN_VER}::register
)

if(gz_add_gui_plugin_TEST_SOURCES)
ign_build_tests(TYPE UNIT
SOURCES
${gz_add_gui_plugin_TEST_SOURCES}
LIB_DEPS
ignition-gazebo${PROJECT_VERSION_MAJOR}-gui
${plugin_name}
INCLUDE_DIRS
# Used to make internal source file headers visible to the unit tests
${CMAKE_CURRENT_SOURCE_DIR}
# Used to make test-directory headers visible to the unit tests
${PROJECT_SOURCE_DIR}
# Used to make test_config.h visible to the unit tests
${PROJECT_BINARY_DIR})
endif()

install (TARGETS ${plugin_name} DESTINATION ${IGNITION_GAZEBO_GUI_PLUGIN_INSTALL_DIR})
endfunction()

Expand All @@ -85,6 +109,7 @@ add_subdirectory(align_tool)
add_subdirectory(component_inspector)
add_subdirectory(entity_tree)
add_subdirectory(grid_config)
add_subdirectory(joint_position_controller)
add_subdirectory(playback_scrubber)
add_subdirectory(resource_spawner)
add_subdirectory(scene3d)
Expand Down
8 changes: 8 additions & 0 deletions src/gui/plugins/joint_position_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gz_add_gui_plugin(JointPositionController
SOURCES
JointPositionController.cc
QT_HEADERS
JointPositionController.hh
TEST_SOURCES
JointPositionController_TEST.cc
)
112 changes: 112 additions & 0 deletions src/gui/plugins/joint_position_controller/Joint.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* 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.
*
*/
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "qrc:/JointPositionController"
import "qrc:/qml"

Rectangle {
id: joint
height: slider.height
width: jointPositionController.width
color: index % 2 == 0 ? lightGrey : darkGrey

// Position value
property double value: 0.0

// Horizontal margins
property int margin: 15

Connections {
target: joint
onValueChanged: {
jointPositionController.onCommand(model.name, joint.value);
spin.value = joint.value;
slider.value = joint.value;
}
}

RowLayout {
anchors.fill: parent
spacing: 0

Item {
height: parent.height
width: margin
}

Text {
text: model.name
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: 100
elide: Text.ElideRight
ToolTip {
visible: ma.containsMouse
delay: Qt.styleHints.mousePressAndHoldInterval
text: model.name
y: -30
enter: null
exit: null
}
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.RightButton
}
}

IgnSpinBox {
id: spin
value: model.value
minimumValue: model.min
maximumValue: model.max
decimals: 2
onEditingFinished: {
joint.value = spin.value
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onEditingFinished: {
joint.value = spin.value
}
stepSize: 0.1
onValueChanged: {
joint.value = spin.value
}

Currently, the stepSize is 1 but I think 0.1 would be a better increment. Also, I think using onValueChanged instead of onEditingFinished is more user friendly, the user doesn't have to hit enter every time they want to update a joint when using the spinbox

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are very good suggestions. I started with both of them, but I had to revert to using onEditingFinished when I worked on the reset button.

While working on reset, I noticed that the values on the GUI were not being updated to reflect the actual state of the robot. When I fixed that, I realized I couldn't use onValueChanged, because that signal doesn't differentiate the value being changed by the user, or from the ECM. So what was happening was that the intermediate state of a joint moving would be sent as a new command, and the joint would tend to return to its original position in a negative feedback loop. It's hard to explain with words, see what happened with onValueChanged:

jointfeedback

This is all on 08904d0, let me know what you think.

}

Text {
text: model.min.toFixed(2)
Layout.alignment: Qt.AlignVCenter
}

Slider {
id: slider
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
from: model.min
to: model.max
value: model.value
onMoved: {
joint.value = slider.value
}
}

Text {
text: model.max.toFixed(2)
Layout.alignment: Qt.AlignVCenter
}

Item {
height: parent.height
width: margin
}
}
}
Loading