Commit 5ea962ec authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

Add RobotarmExample

parent b37f1d11
CMakeLists.txt.user
RobotArm.qmlproject.qtds
translations.db*
cmake_minimum_required(VERSION 3.18)
project(RobotArm LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt6 COMPONENTS Gui Qml Quick)
qt_add_executable(RobotArmApp src/main.cpp)
qt_add_resources(RobotArmApp "configuration"
PREFIX "/"
FILES
qtquickcontrols2.conf
)
target_link_libraries(RobotArmApp PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Qml
)
include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)
import QmlProject
Project {
mainFile: "content/App.qml"
/* Include .qml, .js, and image files from current directory and subdirectories */
QmlFiles {
directory: "content"
}
QmlFiles {
directory: "imports"
}
QmlFiles {
directory: "backend_mock"
}
JavaScriptFiles {
directory: "content"
}
JavaScriptFiles {
directory: "imports"
}
ImageFiles {
directory: "content"
}
Files {
filter: "*.conf"
files: ["qtquickcontrols2.conf"]
}
Files {
filter: "qmldir"
directory: "."
}
Files {
filter: "*.ttf;*.otf"
}
Files {
filter: "*.wav;*.mp3"
}
Files {
filter: "*.mp4"
}
Files {
filter: "*.glsl;*.glslv;*.glslf;*.vsh;*.fsh;*.vert;*.frag"
}
Files {
filter: "*.mesh"
directory: "asset_imports"
}
Environment {
QT_QUICK_CONTROLS_CONF: "qtquickcontrols2.conf"
QT_AUTO_SCREEN_SCALE_FACTOR: "1"
QT_LOGGING_RULES: "qt.qml.connections=false"
QT_ENABLE_HIGHDPI_SCALING: "0"
/* Useful for debugging
QSG_VISUALIZE=batches
QSG_VISUALIZE=clip
QSG_VISUALIZE=changes
QSG_VISUALIZE=overdraw
*/
}
qt6Project: true
/* List of plugin directories passed to QML runtime */
importPaths: [ "imports", "asset_imports", "backend_mock" ]
/* Required for deployment */
targetDirectory: "/opt/RobotArm"
qdsVersion: "3.0"
/* If any modules the project imports require widgets (e.g. QtCharts), widgetApp must be true */
widgetApp: true
multilanguageSupport: true
supportedLanguages: ["en"]
primaryLanguage: "en"
}
### This file is automatically generated by Qt Design Studio.
### Do not change
add_subdirectory(Quick3DAssets)
### This file is automatically generated by Qt Design Studio.
### Do not change
find_package(Qt6 REQUIRED COMPONENTS Gui)
qt_add_qml_module(backend
URI Backend
VERSION 1.0
SOURCES
animatedparam.cpp
animatedparam.h
backend.cpp
backend.h
)
target_link_libraries(backend PRIVATE Qt6::Gui)
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Design Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "animatedparam.h"
#include <QVariantAnimation>
AnimatedParam::AnimatedParam(QObject *parent)
:
QVariantAnimation(parent)
{
setDuration(1500);
setEasingCurve(QEasingCurve::InOutCubic);
connect(this, &QVariantAnimation::valueChanged, this, &AnimatedParam::valueChanged);
connect(this, &QAbstractAnimation::stateChanged, this, [this](QAbstractAnimation::State newState, QAbstractAnimation::State oldState){
m_isRunning = (newState == QAbstractAnimation::Running);
});
}
int AnimatedParam::value() const
{
return currentValue().toInt();
}
void AnimatedParam::setValue(int newValue)
{
stop();
setStartValue(value());
setEndValue(newValue);
start();
}
bool AnimatedParam::isRunning() const
{
return m_isRunning;
}
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Design Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#include <QVariantAnimation>
#include <QProperty>
class AnimatedParam : public QVariantAnimation
{
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
public:
AnimatedParam(QObject *parent = nullptr);
int value() const;
void setValue(int newValue);
bool isRunning() const;
signals:
void valueChanged();
private:
QProperty<bool> m_isRunning;
};
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Design Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "backend.h"
#include <QTransform>
Backend::Backend(QObject *parent) :
QObject(parent)
{
connect(&m_rotation1Angle, &AnimatedParam::valueChanged, this, &Backend::rotation1AngleChanged);
connect(&m_rotation2Angle, &AnimatedParam::valueChanged, this, &Backend::rotation2AngleChanged);
connect(&m_rotation3Angle, &AnimatedParam::valueChanged, this, &Backend::rotation3AngleChanged);
connect(&m_rotation4Angle, &AnimatedParam::valueChanged, this, &Backend::rotation4AngleChanged);
connect(&m_clawsAngle, &AnimatedParam::valueChanged, this, &Backend::clawsAngleChanged);
m_status.setBinding([this](){
return m_isCollision.value() ? QString("Collision!") :
m_rotation1Angle.isRunning()
|| m_rotation2Angle.isRunning()
|| m_rotation3Angle.isRunning()
|| m_rotation4Angle.isRunning()
? QString("Busy") : QString("Ready");
});
connect(&m_rotation1Angle, &AnimatedParam::valueChanged, this, &Backend::detectCollision);
connect(&m_rotation2Angle, &AnimatedParam::valueChanged, this, &Backend::detectCollision);
connect(&m_rotation3Angle, &AnimatedParam::valueChanged, this, &Backend::detectCollision);
connect(&m_rotation4Angle, &AnimatedParam::valueChanged, this, &Backend::detectCollision);
}
int Backend::rotation1Angle() const
{
return m_rotation1Angle.value();
}
void Backend::setRotation1Angle(const int angle)
{
m_rotation1Angle.setValue(angle);
}
int Backend::rotation2Angle() const
{
return m_rotation2Angle.value();
}
void Backend::setRotation2Angle(const int angle)
{
m_rotation2Angle.setValue(angle);
}
int Backend::rotation3Angle() const
{
return m_rotation3Angle.value();
}
void Backend::setRotation3Angle(const int angle)
{
m_rotation3Angle.setValue(angle);
}
int Backend::rotation4Angle() const
{
return m_rotation4Angle.value();
}
void Backend::setRotation4Angle(const int angle)
{
m_rotation4Angle.setValue(angle);
}
int Backend::clawsAngle() const
{
return m_clawsAngle.value();
}
void Backend::setClawsAngle(const int angle)
{
m_clawsAngle.setValue(angle);
}
QString Backend::status() const
{
return m_status;
}
QBindable<QString> Backend::bindableStatus() const
{
return &m_status;
}
void Backend::detectCollision()
{
// simple aproximate collision detection, uses hardcoded model dimensions
QRectF m_bbox1(QPointF(-0.7, 0.),
QPointF(0.7, 3.));
QTransform t;
t.rotate(-8.7);
t.translate(0, 2.59);
t.rotate(20.);
t.rotate(-rotation3Angle());
QRectF m_bbox2 = t.mapRect(QRectF(QPointF(-0.35, 0.),
QPointF(0.35, 2.33)));
t.translate(0, 2.33);
t.rotate(-15);
t.rotate(-rotation2Angle());
QRectF m_bbox3 = t.mapRect(QRectF(-0.27, 0.,
0.27, 2.12));
t.translate(0, 2.12);
t.rotate(-rotation1Angle());
QRectF m_bbox4 = t.mapRect(QRectF(-0.42, 0.,
0.42, 1.8));
m_isCollision.setValue(m_bbox1.intersects(m_bbox3)
|| m_bbox1.intersects(m_bbox4)
|| m_bbox2.intersects(m_bbox4));
}
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Design Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#include <QObject>
#include <qqmlregistration.h>
#include "animatedparam.h"
class Backend : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(int rotation1Angle READ rotation1Angle WRITE setRotation1Angle NOTIFY rotation1AngleChanged)
Q_PROPERTY(int rotation2Angle READ rotation2Angle WRITE setRotation2Angle NOTIFY rotation2AngleChanged)
Q_PROPERTY(int rotation3Angle READ rotation3Angle WRITE setRotation3Angle NOTIFY rotation3AngleChanged)
Q_PROPERTY(int rotation4Angle READ rotation4Angle WRITE setRotation4Angle NOTIFY rotation4AngleChanged)
Q_PROPERTY(int clawsAngle READ clawsAngle WRITE setClawsAngle NOTIFY clawsAngleChanged)
Q_PROPERTY(QString status READ status BINDABLE bindableStatus)
public:
explicit Backend(QObject *parent = nullptr);
int rotation1Angle() const;
void setRotation1Angle(const int angle);
int rotation2Angle() const;
void setRotation2Angle(const int angle);
int rotation3Angle() const;
void setRotation3Angle(const int angle);
int rotation4Angle() const;
void setRotation4Angle(const int angle);
int clawsAngle() const;
void setClawsAngle(const int angle);
QString status() const;
QBindable<QString> bindableStatus() const;
signals:
void rotation1AngleChanged();
void rotation2AngleChanged();
void rotation3AngleChanged();
void rotation4AngleChanged();
void clawsAngleChanged();
private:
AnimatedParam m_rotation1Angle;
AnimatedParam m_rotation2Angle;
AnimatedParam m_rotation3Angle;
AnimatedParam m_rotation4Angle;
AnimatedParam m_clawsAngle;
QProperty<QString> m_status;
QProperty<bool> m_isCollision;
void detectCollision();
};
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Design Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are