Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw Virtual Obstacles #3406

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6f3e635
added feature to draw virtual obstacles
Mr-Anyone Nov 12, 2024
7e33f08
fixed a refactor
Mr-Anyone Nov 12, 2024
079670b
removed debugging comments
Mr-Anyone Nov 12, 2024
ec869bc
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 12, 2024
c4e365d
following conventions after reading on a few pr
Mr-Anyone Nov 12, 2024
042098d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 12, 2024
193e45d
fixed tests?
Mr-Anyone Nov 12, 2024
5e92b24
Merge branch 'obstacles_drawing_pr' of github.com:Mr-Anyone/Thunderbo…
Mr-Anyone Nov 12, 2024
bb75af2
fixed minor bugs
Mr-Anyone Nov 22, 2024
9d82de2
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 23, 2024
fd9452b
made some changes
Mr-Anyone Nov 23, 2024
e3306d0
Merge branch 'obstacles_drawing_pr' of github.com:Mr-Anyone/Thunderbo…
Mr-Anyone Nov 23, 2024
4f3a0c2
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 23, 2024
c189561
should work
Mr-Anyone Nov 23, 2024
a0ed76f
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 23, 2024
5ee0a07
fixed typo
Mr-Anyone Dec 21, 2024
91ee676
made some simple changes
Mr-Anyone Dec 21, 2024
7b70bca
made some changes to the logic
Mr-Anyone Dec 25, 2024
7115cf0
remove unnecessary import
Mr-Anyone Dec 28, 2024
9002178
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 28, 2024
8b60160
kind of implemented double click
Mr-Anyone Dec 28, 2024
9e8e6fa
better double click and now handles single click
Mr-Anyone Dec 28, 2024
ce99d4c
added more docs
Mr-Anyone Dec 28, 2024
49a8cf5
removed commentsq
Mr-Anyone Dec 28, 2024
40721cb
Merge branch 'obstacles_drawing_pr' of github.com:Mr-Anyone/Thunderbo…
Mr-Anyone Dec 28, 2024
faae266
added menu
Mr-Anyone Dec 29, 2024
13b52fc
fixed sizing
Mr-Anyone Dec 29, 2024
9c50790
basically done, need to do cleanup
Mr-Anyone Dec 29, 2024
b4c941c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 29, 2024
91c9f48
updated documentation
Mr-Anyone Dec 29, 2024
6ce5090
moved stuff into different file
Mr-Anyone Dec 29, 2024
89c6bea
made some changes
Mr-Anyone Dec 29, 2024
e44d959
final clean up I hope
Mr-Anyone Dec 29, 2024
65f88de
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 29, 2024
8561728
Update src/software/thunderscope/constants.py
Mr-Anyone Dec 30, 2024
8649714
Update src/software/thunderscope/constants.py
Mr-Anyone Dec 30, 2024
eabcb19
made some small changes
Mr-Anyone Dec 30, 2024
b8870ed
Merge branch 'obstacles_drawing_pr' of github.com:Mr-Anyone/Thunderbo…
Mr-Anyone Dec 30, 2024
491072b
removed a todo
Mr-Anyone Dec 30, 2024
c69cdbe
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Dec 30, 2024
26748e0
made some change to fix merge conflicts
Mr-Anyone Feb 13, 2025
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
5 changes: 5 additions & 0 deletions src/proto/visualization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ message ObstacleList
repeated Obstacle obstacles = 1;
}

message VirtualObstacles
{
repeated Obstacle obstacles = 1;
}

message Shape
{
oneof shape
Expand Down
20 changes: 19 additions & 1 deletion src/software/ai/hl/stp/tactic/move_primitive.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "software/ai/hl/stp/tactic/move_primitive.h"

#include "proto/message_translation/tbots_geometry.h"
#include "proto/message_translation/tbots_protobuf.h"
#include "proto/primitive/primitive_msg_factory.h"
#include "software/ai/navigator/trajectory/bang_bang_trajectory_1d_angular.h"
Expand Down Expand Up @@ -184,9 +185,26 @@ void MovePrimitive::updateObstacles(
// Separately store the non-robot + non-ball obstacles
field_obstacles =
obstacle_factory.createObstaclesFromMotionConstraints(motion_constraints, world);

obstacles = field_obstacles;

// adding virtual obstalces
auto virtual_obstacles = world.getVirtualObstacles().obstacles();
for (TbotsProto::Obstacle &obstacle : virtual_obstacles)
{
if (!obstacle.has_polygon())
{
LOG(WARNING)
<< "Virtual Obstacles contain obstacle that is not a polygon. Shape ignored";

continue;
}

Polygon obstacle_polygon = createPolygon(obstacle.polygon());
ObstaclePtr current_obstacle = obstacle_factory.createFromShape(obstacle_polygon);
obstacles.push_back(current_obstacle);
}


for (const Robot &enemy : world.enemyTeam().getAllRobots())
{
if (obstacle_avoidance_mode == TbotsProto::SAFE)
Expand Down
7 changes: 7 additions & 0 deletions src/software/backend/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "proto/message_translation/tbots_protobuf.h"
#include "proto/sensor_msg.pb.h"
#include "software/multithreading/subject.hpp"


void Backend::receiveRobotStatus(TbotsProto::RobotStatus msg)
{
Expand Down Expand Up @@ -31,3 +33,8 @@ void Backend::receiveSensorProto(SensorProto sensor_msg)
{
Subject<SensorProto>::sendValueToObservers(sensor_msg);
}

void Backend::receiveObstacleList(TbotsProto::VirtualObstacles new_obstacle_list)
{
Subject<TbotsProto::VirtualObstacles>::sendValueToObservers(new_obstacle_list);
}
9 changes: 9 additions & 0 deletions src/software/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* "Subject". Please see the implementation of those classes for details.
*/
class Backend : public Subject<SensorProto>,
public Subject<TbotsProto::VirtualObstacles>,
public FirstInFirstOutThreadedObserver<World>,
public FirstInFirstOutThreadedObserver<TbotsProto::PrimitiveSet>
{
Expand All @@ -33,4 +34,12 @@ class Backend : public Subject<SensorProto>,
void receiveSSLWrapperPacket(SSLProto::SSL_WrapperPacket msg);
void receiveSSLReferee(SSLProto::Referee msg);
void receiveSensorProto(SensorProto sensor_msg);

/**
* Callback function that receive a list of new virtual obstacles from
* Subject<VirtualObstacles>
*
* @param new_obstacles_list a new obstacles list we are having
*/
void receiveObstacleList(TbotsProto::VirtualObstacles new_obstacle_list);
itsarune marked this conversation as resolved.
Show resolved Hide resolved
};
9 changes: 9 additions & 0 deletions src/software/backend/unix_simulator_backend.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "software/backend/unix_simulator_backend.h"

#include "proto/message_translation/ssl_wrapper.h"
#include "proto/message_translation/tbots_geometry.h"
#include "proto/message_translation/tbots_protobuf.h"
#include "proto/parameters.pb.h"
#include "proto/robot_log_msg.pb.h"
#include "proto/sensor_msg.pb.h"
#include "shared/constants.h"
#include "software/constants.h"
#include "software/logger/logger.h"
#include "software/multithreading/subject.hpp"
#include "software/util/generic_factory/generic_factory.h"

UnixSimulatorBackend::UnixSimulatorBackend(
Expand Down Expand Up @@ -38,6 +40,13 @@ UnixSimulatorBackend::UnixSimulatorBackend(
[&](TbotsProto::ThunderbotsConfig& msg) { receiveThunderbotsConfig(msg); },
proto_logger));

// external obstacles for bang bang trajectory planner
external_obstacles_list_.reset(
new ThreadedProtoUnixListener<TbotsProto::VirtualObstacles>(
runtime_dir + VIRTUAL_OBSTACLES_UNIX_PATH,
[&](TbotsProto::VirtualObstacles& msg) { receiveObstacleList(msg); },
proto_logger));

// The following listeners have an empty callback since their values are
// only used by proto_logger for replay purposes.
validation_proto_set_listener.reset(
Expand Down
2 changes: 2 additions & 0 deletions src/software/backend/unix_simulator_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class UnixSimulatorBackend : public Backend, public Subject<TbotsProto::Thunderb

// ThreadedProtoUnix** to communicate with Thunderscope
// Inputs
std::unique_ptr<ThreadedProtoUnixListener<TbotsProto::VirtualObstacles>>
external_obstacles_list_;
std::unique_ptr<ThreadedProtoUnixListener<TbotsProto::RobotStatus>>
robot_status_input;
std::unique_ptr<ThreadedProtoUnixListener<SSLProto::SSL_WrapperPacket>>
Expand Down
1 change: 1 addition & 0 deletions src/software/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const std::string ROBOT_CRASH_PATH = "/robot_crash";
const std::string DYNAMIC_PARAMETER_UPDATE_REQUEST_PATH = "/dynamic_parameter_request";
const std::string DYNAMIC_PARAMETER_UPDATE_RESPONSE_PATH = "/dynamic_parameter_response";
const std::string WORLD_STATE_RECEIVED_TRIGGER_PATH = "/world_state_received_trigger";
const std::string VIRTUAL_OBSTACLES_UNIX_PATH = "/virtual_obstacles";

const unsigned UNIX_BUFFER_SIZE = 20000;

Expand Down
1 change: 1 addition & 0 deletions src/software/py_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PYBIND11_MODULE(py_constants, m)
{
m.attr("BALL_MAX_SPEED_METERS_PER_SECOND") = BALL_MAX_SPEED_METERS_PER_SECOND;
m.attr("ROBOT_MAX_HEIGHT_METERS") = ROBOT_MAX_HEIGHT_METERS;
m.attr("VIRTUAL_OBSTACLES_UNIX_PATH") = VIRTUAL_OBSTACLES_UNIX_PATH;
m.attr("ROBOT_MAX_RADIUS_METERS") = ROBOT_MAX_RADIUS_METERS;
m.attr("ROBOT_MAX_HEIGHT_MILLIMETERS") =
ROBOT_MAX_HEIGHT_METERS * MILLIMETERS_PER_METER;
Expand Down
6 changes: 6 additions & 0 deletions src/software/sensor_fusion/sensor_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ std::optional<World> SensorFusion::getWorld() const
new_world.updateRefereeStage(*referee_stage);
}

new_world.setVirtualObstacles(virtual_obstacles_);
return new_world;
}
else
Expand Down Expand Up @@ -437,3 +438,8 @@ void SensorFusion::resetWorldComponents()
enemy_team_filter = RobotTeamFilter();
possession = TeamPossession::FRIENDLY_TEAM;
}

void SensorFusion::setVirtualObstacles(TbotsProto::VirtualObstacles virtual_obstacles)
{
virtual_obstacles_ = virtual_obstacles;
}
9 changes: 9 additions & 0 deletions src/software/sensor_fusion/sensor_fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class SensorFusion
*/
std::optional<World> getWorld() const;

/**
* Set the virtual obstacles in the world
*
itsarune marked this conversation as resolved.
Show resolved Hide resolved
* @param virtual_obstacles a list of virtual obstacles
*/
void setVirtualObstacles(TbotsProto::VirtualObstacles virtual_obstacles);

// Number of vision packets to indicate that the vision client most likely reset,
// determined experimentally with the simulator
static constexpr unsigned int VISION_PACKET_RESET_COUNT_THRESHOLD = 5;
Expand Down Expand Up @@ -182,4 +189,6 @@ class SensorFusion

// The timestamp, in seconds, of the most recently received vision packet
double last_t_capture;

TbotsProto::VirtualObstacles virtual_obstacles_;
};
5 changes: 5 additions & 0 deletions src/software/sensor_fusion/threaded_sensor_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ void ThreadedSensorFusion::onValueReceived(SensorProto sensor_msg)
}
}
}

void ThreadedSensorFusion::onValueReceived(TbotsProto::VirtualObstacles virtual_obstacles)
{
sensor_fusion.setVirtualObstacles(virtual_obstacles);
}
5 changes: 4 additions & 1 deletion src/software/sensor_fusion/threaded_sensor_fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class ThreadedSensorFusion
: public Subject<World>,
public FirstInFirstOutThreadedObserver<SensorProto>,
public FirstInFirstOutThreadedObserver<TbotsProto::ThunderbotsConfig>
public FirstInFirstOutThreadedObserver<TbotsProto::ThunderbotsConfig>,
public FirstInFirstOutThreadedObserver<TbotsProto::VirtualObstacles>

{
public:
explicit ThreadedSensorFusion(TbotsProto::SensorFusionConfig config);
Expand All @@ -19,6 +21,7 @@ class ThreadedSensorFusion
private:
void onValueReceived(SensorProto sensor_msg) override;
void onValueReceived(TbotsProto::ThunderbotsConfig config) override;
void onValueReceived(TbotsProto::VirtualObstacles virtual_obstacles) override;

SensorFusion sensor_fusion;
TbotsProto::SensorFusionConfig sensor_fusion_config;
Expand Down
1 change: 1 addition & 0 deletions src/software/thunderscope/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ py_library(
"//software/thunderscope/gl/layers:gl_attacker_layer",
"//software/thunderscope/gl/layers:gl_cost_vis_layer",
"//software/thunderscope/gl/layers:gl_debug_shapes_layer",
"//software/thunderscope/gl/layers:gl_draw_polygon_obstacle",
"//software/thunderscope/gl/layers:gl_obstacle_layer",
"//software/thunderscope/gl/layers:gl_passing_layer",
"//software/thunderscope/gl/layers:gl_path_layer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading

from subprocess import Popen, TimeoutExpired
from software.thunderscope.gl.layers.gl_obstacle_layer import ObstacleList
from software.thunderscope.proto_unix_io import ProtoUnixIO
from software.python_bindings import *
from proto.import_all_protos import *
Expand Down Expand Up @@ -215,5 +216,6 @@ def setup_proto_unix_io(self, proto_unix_io: ProtoUnixIO) -> None:
(VALIDATION_PROTO_SET_PATH, ValidationProtoSet),
(ROBOT_LOG_PATH, RobotLog),
(ROBOT_CRASH_PATH, RobotCrash),
(VIRTUAL_OBSTACLES_UNIX_PATH, VirtualObstacles),
]:
proto_unix_io.attach_unix_sender(self.full_system_runtime_dir, *arg)
4 changes: 4 additions & 0 deletions src/software/thunderscope/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class EstopMode(IntEnum):
<b><code>Ctrl + R:</code></b> Remove the current layout file and reset the layout<br><br>
Layout file (on save) is located at {SAVED_LAYOUT_PATH}<br>

<b><code>Shift+Double Click</code></b> Push the current obstacle to the obstacle stack. FriendlyObstacleLayer must be enabled.<br><br>
<b><code>c</code></b> Clear the virtual obstacle stack FriendlyObstacleLayer must be enabled. <br><br>


"""
)

Expand Down
2 changes: 2 additions & 0 deletions src/software/thunderscope/gl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ py_library(
"//software/thunderscope/gl/layers:gl_measure_layer",
"//software/thunderscope/gl/widgets:gl_field_toolbar",
"//software/thunderscope/gl/widgets:gl_gamecontroller_toolbar",
"//software/thunderscope/gl/widgets:gl_multilayer_toolbar",
"//software/thunderscope/gl/widgets:gl_shift_toolbar",
"//software/thunderscope/replay:replay_controls",
requirement("pyqtgraph"),
],
Expand Down
24 changes: 22 additions & 2 deletions src/software/thunderscope/gl/gl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

from software.thunderscope.constants import *

from software.thunderscope.gl.widgets.gl_multilayer_toolbar import MultilayerToolbar
from software.thunderscope.gl.widgets.gl_shift_toolbar import ShiftButtonToolbar
from software.thunderscope.proto_unix_io import ProtoUnixIO
from software.thunderscope.gl.layers.gl_layer import GLLayer
from software.thunderscope.gl.layers.gl_measure_layer import GLMeasureLayer
from software.thunderscope.gl.widgets.gl_field_toolbar import GLFieldToolbar
from software.thunderscope.gl.widgets.gl_field_toolbar import GLFieldToolbar, MultiLayerToolbar
from software.thunderscope.replay.proto_player import ProtoPlayer
from software.thunderscope.replay.replay_controls import ReplayControls
from software.thunderscope.gl.helpers.extended_gl_view_widget import *
Expand Down Expand Up @@ -83,21 +85,35 @@ def __init__(
self.setLayout(self.layout)
self.layout.addWidget(self.gl_view_widget)

# setup multi layer toolbar
self.multi_layer_toolbar = MultilayerToolbar(
parent=self.gl_view_widget, toolbars=[]
)

self.shift_button_toolbar = ShiftButtonToolbar(parent=self.multi_layer_toolbar)

# Setup toolbar
self.measure_mode_enabled = False
self.measure_layer = None
self.layers_menu = QMenu()
self.toolbars_menu = QMenu()
self.layers_menu_actions = {}


self.simulation_control_toolbar = GLFieldToolbar(
parent=self.gl_view_widget,
parent=self.multi_layer_toolbar,
on_camera_view_change=self.set_camera_view,
on_measure_mode=self.toggle_measure_mode,
layers_menu=self.layers_menu,
toolbars_menu=self.toolbars_menu,
sandbox_mode=sandbox_mode,
)


layers = [self.simulation_control_toolbar]
self.multilayer_toolbar = MultiLayerToolbar(self.gl_view_widget, layers)
self.multi_layer_toolbar.add_toolbar(self.simulation_control_toolbar)

# Setup gamecontroller toolbar
self.gamecontroller_toolbar = GLGamecontrollerToolbar(
parent=self.gl_view_widget,
Expand All @@ -123,6 +139,10 @@ def __init__(

self.set_camera_view(CameraView.LANDSCAPE_HIGH_ANGLE)

def get_shift_button_toolbar(self):
itsarune marked this conversation as resolved.
Show resolved Hide resolved
"""Get the ShiftButtonToolbar"""
return self.shift_button_toolbar

def get_sim_control_toolbar(self):
"""Returns the simulation control toolbar"""
return self.simulation_control_toolbar
Expand Down
10 changes: 10 additions & 0 deletions src/software/thunderscope/gl/layers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,13 @@ py_library(
requirement("pyqtgraph"),
],
)

py_library(
name = "gl_draw_polygon_obstacle",
srcs = ["gl_draw_polygon_obstacle.py"],
deps = [
":gl_layer",
"//software/thunderscope/gl/graphics:gl_polygon",
requirement("pyqtgraph"),
],
)
Loading