Skip to content

Commit

Permalink
Cleanup: fixed compiler warnings, C++11 is on
Browse files Browse the repository at this point in the history
  • Loading branch information
Iakov Kirilenko authored and Iakov Kirilenko committed Dec 19, 2016
1 parent 2095bca commit 4177915
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions global.pri
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ isEmpty(IS_QSLOG) {
LIBS += -lqslog$$CONFIGURATION_SUFFIX
}

QMAKE_CXXFLAGS += -std=c++1y
QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual

QMAKE_CXXFLAGS += -fno-elide-constructors -pedantic-errors -ansi -std=c++11
#I whant -Werror to be turned on, but Qt has problems
QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual -Wuninitialized -Winit-self
#-Wold-style-cast -Wmissing-declarations
GLOBAL_PWD = $$PWD

# Useful function to copy additional files to destination,
Expand Down
19 changes: 10 additions & 9 deletions trikControl/src/gyroSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

using namespace trikControl;

static const int GYRO_250DPS = 8.75;
static const float RAD_TO_MDEG = 1000 * 180 / M_PI;
static constexpr float GYRO_250DPS = 8.75;
static constexpr double pi() { return std::acos(-1); }
static constexpr float RAD_TO_MDEG = 1000 * 180 / pi();

GyroSensor::GyroSensor(const QString &deviceName, const trikKernel::Configurer &configurer
, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
Expand Down Expand Up @@ -116,19 +117,19 @@ void GyroSensor::countTilt(QVector<int> gyroData, trikKernel::TimeVal t)
mResult[2] = (gyroData[2] - mBias[2]) * GYRO_250DPS;
mResult[3] = t.packedUInt32();

const auto deltaConst = M_PI / 180 / 1000 / 1000000;
constexpr auto deltaConst = pi() / 180 / 1000 / 1000000;
const auto dt = (t - mLastUpdate) * deltaConst;

const auto x = mResult[0] * dt;
const auto y = mResult[1] * dt;
const auto z = mResult[2] * dt;

const auto c1 = cos(x / 2);
const auto s1 = sin(x / 2);
const auto c2 = cos(y / 2);
const auto s2 = sin(y / 2);
const auto c3 = cos(z / 2);
const auto s3 = sin(z / 2);
const auto c1 = std::cos(x / 2);
const auto s1 = std::sin(x / 2);
const auto c2 = std::cos(y / 2);
const auto s2 = std::sin(y / 2);
const auto c3 = std::cos(z / 2);
const auto s3 = std::sin(z / 2);

QQuaternion deltaQ;
deltaQ.setScalar(c1 * c2 * c3 + s1 * s2 * s3);
Expand Down
9 changes: 4 additions & 5 deletions trikControl/src/gyroSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
#include <QtCore/QThread>
#include <QQuaternion>
#include <QTimer>

#include <cmath>
#include <trikKernel/timeVal.h>

#include "gyroSensorInterface.h"
#include "deviceState.h"

namespace trikKernel {
class Configurer;
class TimeVal;
}

namespace trikHal {
Expand Down Expand Up @@ -77,20 +76,20 @@ private slots:
template <typename T>
static T getPitch(const QQuaternion &q)
{
return atan2(2 * q.y()*q.z() + 2 * q.scalar() * q.x()
return std::atan2(2 * q.y()*q.z() + 2 * q.scalar() * q.x()
, 1 - 2 * q.x() * q.x() - 2 * q.y() * q.y());
}

template <typename T>
static T getRoll(const QQuaternion &q)
{
return asin(2 * q.scalar() * q.y() - 2 * q.x() * q.y());
return std::asin(2 * q.scalar() * q.y() - 2 * q.x() * q.y());
}

template <typename T>
static T getYaw(const QQuaternion &q)
{
return atan2(2 * q.x() * q.y() + 2 * q.scalar() * q.z()
return std::atan2(2 * q.x() * q.y() + 2 * q.scalar() * q.z()
, 1 - 2 * q.y() * q.y() - 2 * q.z() * q.z());
}

Expand Down
3 changes: 1 addition & 2 deletions trikControl/trikControl.pro
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ TEMPLATE = lib

DEFINES += TRIKCONTROL_LIBRARY

QT += xml gui
QT += multimedia
QT += xml gui multimedia

if (equals(QT_MAJOR_VERSION, 5)) {
QT += widgets
Expand Down
2 changes: 1 addition & 1 deletion trikKernel/include/trikKernel/timeVal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License. */

#pragma once

#include <QtCore/qmetatype.h>
namespace trikKernel {

/// Structure of a time value in a convenient format.
Expand Down
3 changes: 2 additions & 1 deletion trikScriptRunner/src/scriptExecutionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void ScriptExecutionControl::system(const QString &command, bool synchronously)
QProcess::startDetached("sh", args);
} else {
QLOG_INFO() << "Running synchronously: " << command;
::system(command.toStdString().c_str());
auto rc = ::system(command.toStdString().c_str());
QLOG_INFO() << "System result code: " << rc;
}
}

Expand Down

0 comments on commit 4177915

Please sign in to comment.