Skip to content

Commit

Permalink
Load graph UI (#193)
Browse files Browse the repository at this point in the history
* Added setup menu (graph select at startup) functionality

* Changed all online launch files to use setup menu

* Changed waypoint input text field to check validity while typing
  • Loading branch information
nthiyag committed Aug 31, 2023
1 parent 3bef4ed commit 22d40d7
Show file tree
Hide file tree
Showing 21 changed files with 484 additions and 56 deletions.
3 changes: 2 additions & 1 deletion launch/offline_honeycomb_grizzly.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ windows:
layout: main-vertical
shell_command_before:
- source ${VTRSRC}/main/install/setup.bash
# - ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
base_params:=honeycomb_grizzly_default.yaml
data_dir:=${VTRTEMP}/lidar
start_new_graph:=false
start_new_graph:=true
use_sim_time:=true
path_planning.type:=stationary
Expand Down
1 change: 1 addition & 0 deletions launch/offline_velodyne_grizzly.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ windows:
layout: main-horizontal
shell_command_before:
- source ${VTRSRC}/main/install/setup.bash
# - ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
Expand Down
3 changes: 2 additions & 1 deletion launch/offline_velodyne_jackal.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ windows:
layout: main-vertical
shell_command_before:
- source ${VTRSRC}/main/install/setup.bash
# - ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
base_params:=velodyne_jackal_default.yaml
data_dir:=${VTRTEMP}/lidar
start_new_graph:=false
start_new_graph:=true
use_sim_time:=true
path_planning.type:=stationary
Expand Down
3 changes: 2 additions & 1 deletion launch/online_honeycomb_grizzly.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ windows:
layout: main-horizontal
shell_command_before:
- source ${VTRSRC}/main/install/setup.bash
- ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
base_params:=honeycomb_grizzly_default.yaml
data_dir:=${VTRTEMP}/lidar/$(date '+%F')/$(date '+%F')
# data_dir:=${VTRTEMP}/lidar/$(date '+%F')/$(date '+%F')
start_new_graph:=false
use_sim_time:=false

Expand Down
3 changes: 2 additions & 1 deletion launch/online_velodyne_grizzly.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ windows:
layout: main-horizontal
shell_command_before:
- source ${VTRSRC}/main/install/setup.bash
- ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
base_params:=hdl64_grizzly_default.yaml
data_dir:=${VTRTEMP}/lidar/$(date '+%F')/$(date '+%F')
# data_dir:=${VTRTEMP}/lidar/$(date '+%F')/$(date '+%F')
start_new_graph:=false
use_sim_time:=false

Expand Down
3 changes: 2 additions & 1 deletion launch/online_velodyne_jackal.launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ windows:
shell_command_before:
- source /opt/ros/humble/setup.bash
&& source ${VTRSRC}/main/install/setup.bash
- ros2 run vtr_gui setup_server --ros-args -r __ns:=/vtr
panes:
- >
ros2 launch vtr_navigation vtr.launch.py
base_params:=velodyne_jackal_default.yaml
data_dir:=${VTRTEMP}/lidar
# data_dir:=${VTRTEMP}/lidar/$(date '+%F')/$(date '+%F')
start_new_graph:=false
use_sim_time:=false

Expand Down
1 change: 1 addition & 0 deletions main/src/vtr_gui/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
tests_require=['pytest'],
entry_points={
'console_scripts': [
'setup_server = vtr_gui.setup_server:main',
'web_server = vtr_gui.web_server:main',
'socket_server = vtr_gui.socket_server:main',
'socket_client = vtr_gui.socket_client:main',
Expand Down
106 changes: 106 additions & 0 deletions main/src/vtr_gui/vtr_gui/setup_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3

# Copyright 2021, Autonomous Space Robotics Lab (ASRL)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import time
import os
import flask
import flask_socketio

import vtr_navigation.vtr_setup as vtr_setup


# socket io server address and port
SOCKET_ADDRESS = '0.0.0.0'
SOCKET_PORT = 5202

logger = logging.getLogger('SetupServer')
logger.setLevel(logging.INFO)
hd = logging.StreamHandler()
fm = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
hd.setFormatter(fm)
logger.addHandler(hd)

app = flask.Flask(__name__)
app.config['DEBUG'] = False
app.secret_key = 'asecretekey'

app.logger.setLevel(logging.ERROR)
logging.getLogger('werkzeug').setLevel(logging.ERROR)

socketio = flask_socketio.SocketIO(app,
logger=False,
engineio_logger=False,
ping_interval=1,
ping_timeout=2,
cors_allowed_origins="*")


@app.route('/')
def main():
return "This is a socket-only API server."


@socketio.on('connect')
def on_connect():
logger.info('Client connected!')


@socketio.on('disconnect')
def on_disconnect():
logger.info('Client disconnected!')


##### Setup specific calls #####


@socketio.on('command/confirm_setup')
def handle_confirm_setup(data):
logger.info('Received setup parameters', data)
if vtr_setup.confirm_setup(data):
logger.info('Broadcasting setup complete')
socketio.emit(u"notification/setup_complete")
else:
logger.info('Broadcasting setup invalid')
socketio.emit(u"notification/setup_invalid")


@socketio.on('command/request_default_dir')
def handle_default_dir():
data = vtr_setup.get_default_dir()
logger.info('Broadcasting default dir')
socketio.emit(u"notification/default_dir", data)


@socketio.on('command/request_available_subdirs')
def handle_available_subdirs():
data = vtr_setup.get_available_subdirs()
logger.info('Broadcasting available subdirs')
socketio.emit(u"notification/available_subdirs", data)


@socketio.on('command/kill_setup_server')
def handle_kill_setup_server():
os._exit(0)


def main():
logger.info("Launching the setup server.")
socketio.run(app, host=SOCKET_ADDRESS, port=SOCKET_PORT, use_reloader=False)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion main/src/vtr_gui/vtr_gui/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
SOCKET_ADDRESS = 'localhost'
SOCKET_PORT = 5201

vtr_ui_logger = logging.getLogger('vtr_ui') # setted up in vtr_ui.py
vtr_ui_logger = logging.getLogger('vtr_ui') # set up in vtr_ui.py


def graph_state_from_ros(ros_graph_state):
Expand Down
1 change: 1 addition & 0 deletions main/src/vtr_gui/vtr_gui/socket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from vtr_navigation.vtr_ui_builder import build_remote


# socket io server address and port
SOCKET_ADDRESS = '0.0.0.0'
SOCKET_PORT = 5201
Expand Down
1 change: 1 addition & 0 deletions main/src/vtr_gui/vtr_gui/vtr-gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions main/src/vtr_gui/vtr_gui/vtr-gui/src/components/goal/GoalForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class GoalForm extends React.Component {
error={goal_waypoints_invalid}
onChange={(e) => {
this.setState({ goal_waypoints_str: e.target.value });
this.parseGoalWaypoints(e);
this.parseGoalWaypoints(e.target.value);
}}
value={goal_waypoints_str}
/>
Expand Down Expand Up @@ -222,18 +222,10 @@ class GoalForm extends React.Component {
}

/** @brief Selects repeat waypoints. */
parseGoalWaypoints(e) {
let input = e.target.value;
let names_lst = input.split(", ");
parseGoalWaypoints(input) {
let names_str = input.replace(/ /g, "").split(",");
let ids = [];

if (input == "") {
this.props.setNewGoalWaypoints([]);
this.setState({ goal_waypoints_invalid: false });
return;
}

for (let name of names_lst) {
for (let name of names_str) {
if (Array.from(this.props.waypointsMap.values()).includes(name)){
ids.push(
Array.from(this.props.waypointsMap.keys()).find(
Expand All @@ -246,7 +238,6 @@ class GoalForm extends React.Component {
return;
}
}

this.props.setNewGoalWaypoints(ids);
this.setState({ goal_waypoints_invalid: false });
}
Expand All @@ -260,6 +251,7 @@ class GoalForm extends React.Component {
s = s.slice(0, s.length - 2);
this.setState({
goal_waypoints_str: s,
goal_waypoints_invalid: false,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,22 @@ class GoalManager extends React.Component {
}

setPause(pause) {
console.info("Sending pause signal with pause:", pause);
console.debug("Sending pause signal with pause:", pause);
this.props.socket.emit("command/set_pause", { pause: pause });
}

cancelGoal(goal) {
console.info("Sending cancel goal signal with goal:", goal);
console.debug("Sending cancel goal signal with goal:", goal);
this.props.socket.emit("command/cancel_goal", goal);
}

beginGoals() {
console.info("Sending begin goals signal");
console.debug("Sending begin goals signal");
this.props.socket.emit("command/begin_goals");
}

handleAnnotateSliderChangeCommitted(type) {
console.info("Sending annotate slider change signal with type:", type);
console.debug("Sending annotate slider change signal with type:", type);
this.props.socket.emit("command/change_env_info", { terrain_type: type });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class GraphMap extends React.Component {
label="Name"
variant="standard"
size="small"
on
onChange={(e) => {
disp_wps_map.set(key, e.target.value);
this.setState({display_waypoints_map: disp_wps_map});
Expand Down
Loading

0 comments on commit 22d40d7

Please sign in to comment.