Skip to content

Commit 9975f65

Browse files
Mr-Anyonepre-commit-ci-lite[bot]itsarunewilliamckha
authored
Draw Virtual Obstacles (UBC-Thunderbots#3406)
* added feature to draw virtual obstacles * fixed a refactor * removed debugging comments * [pre-commit.ci lite] apply automatic fixes * following conventions after reading on a few pr * [pre-commit.ci lite] apply automatic fixes * fixed tests? * fixed minor bugs * [pre-commit.ci lite] apply automatic fixes * made some changes * [pre-commit.ci lite] apply automatic fixes * should work * [pre-commit.ci lite] apply automatic fixes * fixed typo * made some simple changes * made some changes to the logic * remove unnecessary import * [pre-commit.ci lite] apply automatic fixes * kind of implemented double click * better double click and now handles single click * added more docs * removed commentsq * added menu * fixed sizing * basically done, need to do cleanup * [pre-commit.ci lite] apply automatic fixes * updated documentation * moved stuff into different file * made some changes * final clean up I hope * [pre-commit.ci lite] apply automatic fixes * Update src/software/thunderscope/constants.py Co-authored-by: itsarune <42703774+itsarune@users.noreply.github.com> * Update src/software/thunderscope/constants.py Co-authored-by: itsarune <42703774+itsarune@users.noreply.github.com> * made some small changes * removed a todo * [pre-commit.ci lite] apply automatic fixes * fixed build? * remove all toolbar related code * update docs * Formatting * [pre-commit.ci lite] apply automatic fixes * Update src/software/world/world.h Co-authored-by: William Ha <60044853+williamckha@users.noreply.github.com> * hopefully this fixed it? * Refactored GLDrawPolygonObstacleLayer and fixed GLPolygon not rendering outline correctly * [pre-commit.ci lite] apply automatic fixes * Fix small nitpicks * [pre-commit.ci lite] apply automatic fixes * address comments --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: itsarune <42703774+itsarune@users.noreply.github.com> Co-authored-by: williamckha <williamha@outlook.com> Co-authored-by: William Ha <60044853+williamckha@users.noreply.github.com>
1 parent d9b2017 commit 9975f65

23 files changed

Lines changed: 291 additions & 5 deletions

src/proto/visualization.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ message ObstacleList
6868
repeated Obstacle obstacles = 1;
6969
}
7070

71+
message VirtualObstacles
72+
{
73+
repeated Obstacle obstacles = 1;
74+
}
75+
7176
message Shape
7277
{
7378
oneof shape

src/software/ai/hl/stp/tactic/move_primitive.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "software/ai/hl/stp/tactic/move_primitive.h"
22

3+
#include "proto/message_translation/tbots_geometry.h"
34
#include "proto/message_translation/tbots_protobuf.h"
45
#include "proto/primitive/primitive_msg_factory.h"
56
#include "software/ai/navigator/trajectory/bang_bang_trajectory_1d_angular.h"
@@ -184,9 +185,26 @@ void MovePrimitive::updateObstacles(
184185
// Separately store the non-robot + non-ball obstacles
185186
field_obstacles =
186187
obstacle_factory.createObstaclesFromMotionConstraints(motion_constraints, world);
187-
188188
obstacles = field_obstacles;
189189

190+
// Adding virtual obstacles
191+
auto virtual_obstacles = world.getVirtualObstacles().obstacles();
192+
for (TbotsProto::Obstacle &obstacle : virtual_obstacles)
193+
{
194+
if (!obstacle.has_polygon())
195+
{
196+
LOG(WARNING)
197+
<< "Virtual Obstacles contain obstacle that is not a polygon. Shape ignored";
198+
199+
continue;
200+
}
201+
202+
Polygon obstacle_polygon = createPolygon(obstacle.polygon());
203+
ObstaclePtr current_obstacle = obstacle_factory.createFromShape(obstacle_polygon);
204+
obstacles.push_back(current_obstacle);
205+
}
206+
207+
190208
for (const Robot &enemy : world.enemyTeam().getAllRobots())
191209
{
192210
if (obstacle_avoidance_mode == TbotsProto::SAFE)

src/software/backend/backend.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "proto/message_translation/tbots_protobuf.h"
44
#include "proto/sensor_msg.pb.h"
5+
#include "software/multithreading/subject.hpp"
6+
57

68
void Backend::receiveRobotStatus(TbotsProto::RobotStatus msg)
79
{
@@ -31,3 +33,8 @@ void Backend::receiveSensorProto(SensorProto sensor_msg)
3133
{
3234
Subject<SensorProto>::sendValueToObservers(sensor_msg);
3335
}
36+
37+
void Backend::receiveObstacleList(TbotsProto::VirtualObstacles new_obstacle_list)
38+
{
39+
Subject<TbotsProto::VirtualObstacles>::sendValueToObservers(new_obstacle_list);
40+
}

src/software/backend/backend.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* "Subject". Please see the implementation of those classes for details.
1616
*/
1717
class Backend : public Subject<SensorProto>,
18+
public Subject<TbotsProto::VirtualObstacles>,
1819
public FirstInFirstOutThreadedObserver<World>,
1920
public FirstInFirstOutThreadedObserver<TbotsProto::PrimitiveSet>
2021
{
@@ -33,4 +34,12 @@ class Backend : public Subject<SensorProto>,
3334
void receiveSSLWrapperPacket(SSLProto::SSL_WrapperPacket msg);
3435
void receiveSSLReferee(SSLProto::Referee msg);
3536
void receiveSensorProto(SensorProto sensor_msg);
37+
38+
/**
39+
* Callback function that receives a list of new virtual obstacles to send
40+
* to Observers
41+
*
42+
* @param new_obstacles_list the received virtual obstacles list
43+
*/
44+
void receiveObstacleList(TbotsProto::VirtualObstacles new_obstacle_list);
3645
};

src/software/backend/unix_simulator_backend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "software/backend/unix_simulator_backend.h"
22

33
#include "proto/message_translation/ssl_wrapper.h"
4+
#include "proto/message_translation/tbots_geometry.h"
45
#include "proto/message_translation/tbots_protobuf.h"
56
#include "proto/parameters.pb.h"
67
#include "proto/robot_log_msg.pb.h"
78
#include "proto/sensor_msg.pb.h"
89
#include "shared/constants.h"
910
#include "software/constants.h"
1011
#include "software/logger/logger.h"
12+
#include "software/multithreading/subject.hpp"
1113
#include "software/util/generic_factory/generic_factory.h"
1214

1315
UnixSimulatorBackend::UnixSimulatorBackend(
@@ -37,6 +39,13 @@ UnixSimulatorBackend::UnixSimulatorBackend(
3739
[&](TbotsProto::ThunderbotsConfig& msg) { receiveThunderbotsConfig(msg); },
3840
proto_logger));
3941

42+
// external obstacles for bang bang trajectory planner
43+
external_obstacles_list_.reset(
44+
new ThreadedProtoUnixListener<TbotsProto::VirtualObstacles>(
45+
runtime_dir + VIRTUAL_OBSTACLES_UNIX_PATH,
46+
[&](TbotsProto::VirtualObstacles& msg) { receiveObstacleList(msg); },
47+
proto_logger));
48+
4049
// The following listeners have an empty callback since their values are
4150
// only used by proto_logger for replay purposes.
4251
validation_proto_set_listener.reset(

src/software/backend/unix_simulator_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class UnixSimulatorBackend : public Backend, public Subject<TbotsProto::Thunderb
3939

4040
// ThreadedProtoUnix** to communicate with Thunderscope
4141
// Inputs
42+
std::unique_ptr<ThreadedProtoUnixListener<TbotsProto::VirtualObstacles>>
43+
external_obstacles_list_;
4244
std::unique_ptr<ThreadedProtoUnixListener<TbotsProto::RobotStatus>>
4345
robot_status_input;
4446
std::unique_ptr<ThreadedProtoUnixListener<SSLProto::SSL_WrapperPacket>>

src/software/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const std::string REPLAY_BOOKMARK_PATH = "/replay_bookmark";
3636
const std::string DYNAMIC_PARAMETER_UPDATE_REQUEST_PATH = "/dynamic_parameter_request";
3737
const std::string DYNAMIC_PARAMETER_UPDATE_RESPONSE_PATH = "/dynamic_parameter_response";
3838
const std::string WORLD_STATE_RECEIVED_TRIGGER_PATH = "/world_state_received_trigger";
39+
const std::string VIRTUAL_OBSTACLES_UNIX_PATH = "/virtual_obstacles";
3940

4041
const unsigned UNIX_BUFFER_SIZE = 20000;
4142

src/software/py_constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PYBIND11_MODULE(py_constants, m)
88
{
99
m.attr("BALL_MAX_SPEED_METERS_PER_SECOND") = BALL_MAX_SPEED_METERS_PER_SECOND;
1010
m.attr("ROBOT_MAX_HEIGHT_METERS") = ROBOT_MAX_HEIGHT_METERS;
11+
m.attr("VIRTUAL_OBSTACLES_UNIX_PATH") = VIRTUAL_OBSTACLES_UNIX_PATH;
1112
m.attr("ROBOT_MAX_RADIUS_METERS") = ROBOT_MAX_RADIUS_METERS;
1213
m.attr("ROBOT_MAX_HEIGHT_MILLIMETERS") =
1314
ROBOT_MAX_HEIGHT_METERS * MILLIMETERS_PER_METER;

src/software/sensor_fusion/sensor_fusion.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ std::optional<World> SensorFusion::getWorld() const
4040
new_world.updateRefereeStage(*referee_stage);
4141
}
4242

43+
new_world.setVirtualObstacles(virtual_obstacles_);
4344
return new_world;
4445
}
4546
else
@@ -512,3 +513,8 @@ void SensorFusion::resetWorldComponents()
512513
possession = TeamPossession::FRIENDLY_TEAM;
513514
dribble_displacement = std::nullopt;
514515
}
516+
517+
void SensorFusion::setVirtualObstacles(TbotsProto::VirtualObstacles virtual_obstacles)
518+
{
519+
virtual_obstacles_ = virtual_obstacles;
520+
}

src/software/sensor_fusion/sensor_fusion.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class SensorFusion
4848
*/
4949
std::optional<World> getWorld() const;
5050

51+
/**
52+
* Set the virtual obstacles in the world
53+
*
54+
* @param virtual_obstacles a list of virtual obstacles
55+
*/
56+
void setVirtualObstacles(TbotsProto::VirtualObstacles virtual_obstacles);
57+
5158
// Number of vision packets to indicate that the vision client most likely reset,
5259
// determined experimentally with the simulator
5360
static constexpr unsigned int VISION_PACKET_RESET_COUNT_THRESHOLD = 5;
@@ -205,4 +212,6 @@ class SensorFusion
205212

206213
// The timestamp, in seconds, of the most recently received vision packet
207214
double last_t_capture;
215+
216+
TbotsProto::VirtualObstacles virtual_obstacles_;
208217
};

0 commit comments

Comments
 (0)