generated from MaracatronicsRobotics/Armorial-PSEL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coach.cpp
68 lines (59 loc) · 2.51 KB
/
coach.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/***
* Maracatronics Robotics
* Federal University of Pernambuco (UFPE) at Recife
* http://www.maracatronics.com/
*
* This file is part of Armorial project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "coach.h"
Coach::Coach(const QMap<bool, QList<Player*>>& players, WorldMap* worldMap)
: _players(players), _worldMap(worldMap)
{
// Create QTimer and connects to the runCoach() slot
_actuatorTimer = new QTimer(this);
QObject::connect(_actuatorTimer, &QTimer::timeout, this, &Coach::runCoach);
_actuatorTimer->start(COACH_ITERATION_INTERVAL_MS);
}
std::optional<Player*> Coach::getPlayer(const bool& isTeamBlue, const quint8& playerId) {
// Get list of players
QList<Player*> playersForColor = _players.value(isTeamBlue);
// Iterate searching for playerId
for(const auto& player : playersForColor) {
if(player->getPlayerId() == playerId) {
return player;
}
}
// If could not found, just return std::nullopt (should trait later)
return std::nullopt;
}
WorldMap* Coach::getWorldMap() {
return _worldMap;
}
void Coach::runCoach() {
// Here you can control the robots freely.
// Remember that the getPlayer(color, id) function can return a std::nullopt object, so
// be careful when you use it (remember to only use ids from 0-2 and the BLUE and YELLOW
// defines).
// Example 1: here we get the ball position and set the BLUE and YELLOW player 0 to follow it
QVector2D ballPosition = getWorldMap()->ballPosition();
getPlayer(BLUE, 0).value()->goTo(ballPosition);
getPlayer(YELLOW, 0).value()->goTo(ballPosition);
// Example 2: here we set the BLUE and YELLOW players 1 and 2 to rotate to the ball
getPlayer(BLUE, 1).value()->rotateTo(ballPosition);
getPlayer(BLUE, 2).value()->rotateTo(ballPosition);
getPlayer(YELLOW, 1).value()->rotateTo(ballPosition);
getPlayer(YELLOW, 2).value()->rotateTo(ballPosition);
}