Skip to content

Commit

Permalink
Addressed test comments. One left to resolve.
Browse files Browse the repository at this point in the history
Signed-off-by: LolaSegura <lsegura@ekumenlabs.com>
  • Loading branch information
LolaSegura committed Jul 16, 2021
1 parent fbeceff commit b8bccc0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
44 changes: 22 additions & 22 deletions src/plugins/teleop/Teleop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ namespace gui
{
namespace plugins
{
enum class keyLinear{
kforward,
kbackward,
kstop,
enum class KeyLinear{
kForward,
kBackward,
kStop,
};

enum class keyAngular{
kleft,
kright,
kstop,
enum class KeyAngular{
kLeft,
kRight,
kStop,
};

class TeleopPrivate
Expand All @@ -73,9 +73,9 @@ namespace plugins
public: int angularDir = 0;

/// \brief Linear state setted by keyboard input.
public: keyLinear linearState = keyLinear::kstop;
public: KeyLinear linearState = KeyLinear::kStop;
/// \brief Angular state setted by keyboard input.
public: keyAngular angularState = keyAngular::kstop;
public: KeyAngular angularState = KeyAngular::kStop;

/// \brief Indicates if the keyboard is enabled or
/// disabled.
Expand Down Expand Up @@ -192,16 +192,16 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event)
switch(keyEvent->key())
{
case Qt::Key_W:
this->dataPtr->linearState = keyLinear::kforward;
this->dataPtr->linearState = KeyLinear::kForward;
break;
case Qt::Key_A:
this->dataPtr->angularState = keyAngular::kleft;
this->dataPtr->angularState = KeyAngular::kLeft;
break;
case Qt::Key_D:
this->dataPtr->angularState = keyAngular::kright;
this->dataPtr->angularState = KeyAngular::kRight;
break;
case Qt::Key_S:
this->dataPtr->linearState = keyLinear::kbackward;
this->dataPtr->linearState = KeyLinear::kBackward;
break;
default:
break;
Expand All @@ -216,16 +216,16 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event)
switch(keyEvent->key())
{
case Qt::Key_W:
this->dataPtr->linearState = keyLinear::kstop;
this->dataPtr->linearState = KeyLinear::kStop;
break;
case Qt::Key_A:
this->dataPtr->angularState = keyAngular::kstop;
this->dataPtr->angularState = KeyAngular::kStop;
break;
case Qt::Key_D:
this->dataPtr->angularState = keyAngular::kstop;
this->dataPtr->angularState = KeyAngular::kStop;
break;
case Qt::Key_S:
this->dataPtr->linearState = keyLinear::kstop;
this->dataPtr->linearState = KeyLinear::kStop;
break;
default:
break;
Expand All @@ -241,12 +241,12 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event)
void Teleop::SetKeyDirection()
{
this->dataPtr->linearDir = this->dataPtr->linearState ==
keyLinear::kforward ? 1 : this->dataPtr->linearState ==
keyLinear::kbackward ? -1 : 0;
KeyLinear::kForward ? 1 : this->dataPtr->linearState ==
KeyLinear::kBackward ? -1 : 0;

this->dataPtr->angularDir = this->dataPtr->angularState ==
keyAngular::kleft ? 1 : this->dataPtr->angularState ==
keyAngular::kright ? -1 : 0;
KeyAngular::kLeft ? 1 : this->dataPtr->angularState ==
KeyAngular::kRight ? -1 : 0;
}

/////////////////////////////////////////////////
Expand Down
31 changes: 15 additions & 16 deletions src/plugins/teleop/Teleop_TEST.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* 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.
Expand Down Expand Up @@ -30,7 +30,7 @@
#include "ignition/gui/Application.hh"
#include "ignition/gui/Plugin.hh"
#include "ignition/gui/MainWindow.hh"
#include <ignition/gui/qt.h>
#include "ignition/gui/qt.h"

#include "Teleop.hh"

Expand All @@ -40,10 +40,11 @@ char **g_argv = new char *[g_argc];
using namespace ignition;
using namespace gui;

class TeleopTest : public ::testing::Test {

protected:
void SetUp() override {
class TeleopTest : public ::testing::Test
{
protected:
void SetUp() override
{
common::Console::SetVerbosity(4);
}

Expand Down Expand Up @@ -77,7 +78,7 @@ class TeleopTest : public ::testing::Test {
auto plugins = win->findChildren<plugins::Teleop *>();
EXPECT_EQ(plugins.size(), 1);

auto plugin = plugins[0];
const auto plugin = plugins[0];
EXPECT_EQ(plugin->Title(), "Teleop!");

plugin->OnTopicSelection(QString::fromStdString(_topic));
Expand All @@ -88,8 +89,8 @@ class TeleopTest : public ::testing::Test {
EXPECT_EQ(plugin->AngularDirection(), 0);

// Define velocity values.
double linearVel = 1.0;
double angularVel = 0.5;
const double linearVel = 1.0;
const double angularVel = 0.5;

// Set velocity value and movement direction.
// Forward and left movement.
Expand All @@ -115,7 +116,7 @@ class TeleopTest : public ::testing::Test {
plugin->OnTeleopTwist();

int sleep = 0;
int maxSleep = 30;
const int maxSleep = 30;
while (!received && sleep < maxSleep)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down Expand Up @@ -228,7 +229,7 @@ class TeleopTest : public ::testing::Test {
auto plugins = win->findChildren<plugins::Teleop *>();
EXPECT_EQ(plugins.size(), 1);

auto plugin = plugins[0];
const auto plugin = plugins[0];
EXPECT_EQ(plugin->Title(), "Teleop!");

// Set desire topic.
Expand All @@ -239,8 +240,8 @@ class TeleopTest : public ::testing::Test {
EXPECT_EQ(plugin->AngularDirection(), 0);

// Define velocity values.
double linearVel = 1.0;
double angularVel = 0.5;
const double linearVel = 1.0;
const double angularVel = 0.5;

// Set velocity value and movement direction.
plugin->OnLinearVelSelection(QString::number(linearVel));
Expand Down Expand Up @@ -274,7 +275,7 @@ class TeleopTest : public ::testing::Test {
app.sendEvent(win->QuickWindow(), keypress_W);

int sleep = 0;
int maxSleep = 30;
const int maxSleep = 30;
while (!received && sleep < maxSleep)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down Expand Up @@ -430,13 +431,11 @@ TEST_F(TeleopTest, Load)
/////////////////////////////////////////////////
TEST_F(TeleopTest, ButtonCommand)
{
TestButtons("/cmd_vel");
TestButtons("/model/vehicle_blue/cmd_vel");
}

/////////////////////////////////////////////////
TEST_F(TeleopTest, KeyboardCommand)
{
TestKeys("/cmd_vel");
TestKeys("/model/vehicle_blue/cmd_vel");
}

0 comments on commit b8bccc0

Please sign in to comment.