Skip to content
Snippets Groups Projects
Commit 265ddcde authored by C-Glick's avatar C-Glick
Browse files

Basic data plot, added crazyflie worker thread, added basic setpoint class

creazyflie worker thread will handle sending and receiving crazyflie specific data
parent 70fea32e
No related branches found
No related tags found
3 merge requests!76lots of gui updates,!75Lost of gui updates,!74lots of gui updates among others
......@@ -6,7 +6,7 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
TARGET = MicroCART
TEMPLATE = app
......@@ -20,7 +20,10 @@ SOURCES += main.cpp\
controlworker.cpp \
quaditem.cpp \
slotprocess.cpp \
qFlightInstruments.cpp
qFlightInstruments.cpp\
qcustomplot.cpp\
crazyflieworker.cpp\
setpoint.cpp
HEADERS += mainwindow.h \
trackerworker.h \
......@@ -28,7 +31,10 @@ HEADERS += mainwindow.h \
quaditem.h \
slotprocess.h \
graph_blocks.h \
qFlightInstruments.h
qFlightInstruments.h\
qcustomplot.h\
crazyflieworker.h\
setpoint.h
FORMS += mainwindow.ui
......
#include "crazyflieworker.h"
CrazyflieWorker::CrazyflieWorker(QObject *parent) : QObject(parent)
{
}
CrazyflieWorker::~CrazyflieWorker()
{
disconnectBackend();
}
/**
* @brief CrazyflieWorker::connectBackend
* Command the worker to connect to the backend
* will set the private class struct, conn, once done.
* The connected() signal is emitted once complete.
*/
void CrazyflieWorker::connectBackend()
{
if (conn == NULL) {
conn = ucart_backendConnect();
emit (connected());
} else {
qInfo() << "Attempted to connect trackerworker when already connected!";
}
}
/**
* @brief CrazyflieWorker::disconnectBackend
* Command the worker to disconnect from the backend,
* sets the conn struct to null and emits the
* disconnected() signal once complete
*/
void CrazyflieWorker::disconnectBackend()
{
if (conn) {
ucart_backendDisconnect(conn);
conn = NULL;
emit (disconnected());
}
}
void CrazyflieWorker::setCurrAttSetpoint(float roll, float pitch, float yaw, float throttle)
{
currAttitudeSetpoint.roll = roll;
currAttitudeSetpoint.pitch = pitch;
currAttitudeSetpoint.yaw = yaw;
currAttitudeSetpoint.throttle = throttle;
}
void CrazyflieWorker::setCurrAttRateSetpoint(float rollRate, float pitchRate, float yawRate, float throttleRate)
{
currAttitudeRateSetpoint.roll = rollRate;
currAttitudeRateSetpoint.pitch = pitchRate;
currAttitudeRateSetpoint.yaw = yawRate;
currAttitudeRateSetpoint.throttle = throttleRate;
}
void CrazyflieWorker::sendAttRateSetpoint()
{
struct frontend_override_data data;
data.enable = 2; //attitude rate
data.time = 0.2; //hold setpoint for 0.2 seconds TODO
data.throttle = currAttitudeRateSetpoint.throttle;
data.roll = currAttitudeRateSetpoint.roll;
data.pitch = currAttitudeRateSetpoint.pitch;
data.yaw = currAttitudeRateSetpoint.yaw;
//send setpoint
frontend_setoutputoverride(conn, &data);
}
void CrazyflieWorker::sendAttSetpoint()
{
struct frontend_override_data data;
data.enable = 1; //attitude
data.time = 0.2; //hold setpoint for 0.2 seconds TODO
data.throttle = currAttitudeSetpoint.throttle;
data.roll = currAttitudeSetpoint.roll;
data.pitch = currAttitudeSetpoint.pitch;
data.yaw = currAttitudeSetpoint.yaw;
//send setpoint
frontend_setoutputoverride(conn, &data);
}
void CrazyflieWorker::getParamValue(QString paramName){
struct frontend_param_data data = paramNameLookup(paramName);
if(frontend_getparam(conn, &data) == 0){
emit(gotParamValue(paramName, data.value));
}
}
struct frontend_param_data CrazyflieWorker::paramNameLookup(QString paramName){
//TODO
//if param is in cache, use that else lookup from file
struct frontend_param_data paramData;
return paramData;
}
#ifndef CRAZYFLIEWORKER_H
#define CRAZYFLIEWORKER_H
#include <QObject>
#include "frontend_common.h"
#include "frontend_param.h"
#include "frontend_override.h"
#include "setpoint.h"
#include <QDebug>
/**
* @brief The crazyflieworker class
* This class handles communication for the crazyflie,
* reading log values and setting parameter values
*/
class CrazyflieWorker : public QObject
{
Q_OBJECT
public:
explicit CrazyflieWorker(QObject *parent = nullptr);
~CrazyflieWorker();
void setCurrAttSetpoint(float roll, float pitch, float yaw, float throttle);
void setCurrAttRateSetpoint(float rollRate, float pitchRate, float yawRate, float throttleRate);
signals:
void gotParamValue(QString paramName, float value);
void connected();
void disconnected();
public slots:
void connectBackend();
void disconnectBackend();
void sendAttSetpoint();
void sendAttRateSetpoint();
void getParamValue(QString paramName);
private:
struct backend_conn * conn;
Setpoint currAttitudeSetpoint;
Setpoint currAttitudeRateSetpoint;
void sendAttitudeSetpoint();
void sendAttitudeRateSetpoint();
struct frontend_param_data paramNameLookup(QString paramName);
};
#endif // CRAZYFLIEWORKER_H
This diff is collapsed.
......@@ -45,6 +45,7 @@ private slots:
void newParamValue(QString node, QString param, float val);
void newNodeOutput(QString node, float output);
void newConstantBlocks(QStringList blocks);
void newControlGraph(QString graph);
void on_paramSelect_currentIndexChanged(const QString &arg1);
......@@ -81,6 +82,10 @@ private slots:
void on_zSetpoint_returnPressed();
void on_posattSrcVrpn_clicked();
void on_posattSrcQuad_clicked();
void on_yawSetpoint_returnPressed();
void backendStarted();
......@@ -91,6 +96,8 @@ private slots:
void workerConnected();
void workerDisconnected();
void on_dataPlot_customContextMenuRequested(const QPoint &pos);
private:
Ui::MainWindow *ui;
QStandardItemModel * setpointList;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "setpoint.h"
Setpoint::Setpoint()
{
}
#ifndef SETPOINT_H
#define SETPOINT_H
class Setpoint
{
public:
float roll = 0;
float pitch = 0;
float yaw = 0;
float throttle = 0;
Setpoint();
};
#endif // SETPOINT_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment