Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61542130
mainwindow.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 7, 08:06
Size
2 KB
Mime Type
text/x-c
Expires
Thu, May 9, 08:06 (2 d)
Engine
blob
Format
Raw Data
Handle
17525836
Attached To
R2671 HHRI-software
mainwindow.cpp
View Options
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>
#include <QInputDialog>
#include <QList>
#include "hriboard.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//
ui->setupUi(this);
// Connect the GUI signals to the slots.
connect(ui->torqueSpin, SIGNAL(editingFinished()),
this, SLOT(setMotorTorque()));
// Ask for the COM port.
QString comPortName;
QStringList ports = HriBoard::getComPorts();
if(ports.size() == 0)
{
QMessageBox::critical(this, qApp->applicationName(), "No COM port.");
exit(0);
}
else if(ports.size() == 1)
comPortName = ports.first();
else
{
bool ok;
QString portChoice = QInputDialog::getItem(this, "HRI2_PC_Controller",
"Serial port:", ports, 0,
false, &ok);
int portIndex = ports.indexOf(portChoice);
if(portIndex == -1 || !ok)
exit(0);
comPortName = ports[portIndex];
}
// Establish the link with the HRI board.
hriBoard.openLink(comPortName);
connect(&hriBoard, SIGNAL(syncVarsListReceived(QList<SyncVar>)),
this, SLOT(onVarsListReceived(QList<SyncVar>)));
connect(&hriBoard, SIGNAL(syncVarsUpdated()), this, SLOT(onVarsUpdated()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onVarsListReceived(const QList<SyncVar> &syncVars)
{
// Display the list of all the SyncVars.
qDebug() << "SyncVars list:";
for(const SyncVar &sv : syncVars)
qDebug() << sv.getName();
// Get the variables from the list.
hriBoard.associate(hallVoltage, "hall_voltage [V]");
hriBoard.associate(motorTorque, "motor_torque [N.m]");
if(!hallVoltage.isValid() || !motorTorque.isValid())
{
qDebug() << "The expected SyncVars were not found in the list." << endl;
return;
}
// Start the streaming.
hriBoard.setStreamedVars({&hallVoltage, &motorTorque});
}
void MainWindow::onVarsUpdated()
{
// Update the UI widgets.
ui->hallVoltageBar->setValue((int)(*hallVoltage/3.3f*100.0f));
}
void MainWindow::setMotorTorque()
{
// Get the UI control value, and affect it to the SyncVar.
*motorTorque = (float)ui->torqueSpin->value();
motorTorque.writeValue();
}
Event Timeline
Log In to Comment