Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions src/Modules/Processing/CustomPlayer/CustomPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,58 @@ void CustomPlayer::update() {
}

void CustomPlayer::exec() {
if (!field || !frame || !robot) {

if (!field || !frame || !robot)
return;
if (!frame->has_ball())
return;
auto&& pos_ball = frame->ball();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usar um mesmo padrão pra nomes de variáveis. Nesse caso, a variável passaria a ser posBall


QPointF targetPosition(1000, 4000);
QPointF initialPosition(2000, 0);
int tolerance = 150;
Comment on lines +44 to +46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como essas variáveis são constantes, podem ir pro arquivo CustomPlayer.h.

maxdis = 9000000;
if ((pos_ball.distTo(targetPosition)) > tolerance) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colocar nomes descritivos para as condicionais facilita entender o que tá acontecendo:

Suggested change
if ((pos_ball.distTo(targetPosition)) > tolerance) {
bool isBallOnTargetPosition = (pos_ball.distTo(targetPosition)) <= tolerance;
if (!isBallOnTargetPosition) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse comentário também se aplica às outras condicionais


for (const auto& ally : frame->allies()) {
double distance = ally.distTo(pos_ball);
if (maxdis > distance) {
maxdis = distance;
idrobot = ally.id();
}
}
}

// TODO: here...
// emit sendCommand(...);
if (robot->id() != idrobot)
return;

if ((pos_ball - targetPosition).manhattanLength() > tolerance) {
if (robot->distTo(pos_ball) > 150) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Substituir o 150 por uma constante

SSLMotion::GoToPoint goToPoint(pos_ball, (pos_ball - robot->position()).angle(), true);
auto command = sslNavigation.run(robot.value(), SSLRobotCommand(goToPoint));
command.set_dribbler(true);
command.set_dribblerVelocity(4);
emit sendCommand(command);
} else {
SSLMotion::GoToPoint goToPoint(targetPosition,
(targetPosition - robot->position()).angle(),
true);
goToPoint.set_maxVelocity(1);
auto command = sslNavigation.run(robot.value(), SSLRobotCommand(goToPoint));
command.set_dribbler(true);
command.set_dribblerVelocity(4);
emit sendCommand(command);
}
} else if (robot->id() == idrobot && robot->distTo(initialPosition) > tolerance) {
SSLMotion::GoToPoint goToInitial(initialPosition,
(initialPosition - robot->position()).angle(),
true);
auto command = sslNavigation.run(robot.value(), SSLRobotCommand(goToInitial));
emit sendCommand(command);
} else {
idrobot = -1;
maxdis = 9000000;
}
}

void CustomPlayer::receiveField(const Field& field) {
Expand Down
3 changes: 3 additions & 0 deletions src/Modules/Processing/CustomPlayer/CustomPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "Modules/Processing/ProcessingUtils/ProcessingUtils.h"

class CustomPlayer : public Processing {
int maxdis = 9000000;
int idrobot = -1;
Comment on lines +8 to +9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int maxdis = 9000000;
int idrobot = -1;
int maxDis = 9000000;
int idRobot = -1;

bool ball_placement = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa variável não é usada, então pode ser removida

public:
CustomPlayer(int index, QThreadPool* threadPool);

Expand Down