Skip to content

Commit

Permalink
Merge pull request #2 from purduerov/phoenix
Browse files Browse the repository at this point in the history
Phoenix
  • Loading branch information
XavierJCallait authored Sep 25, 2024
2 parents 7164f2c + 8766bbb commit 2c628bb
Show file tree
Hide file tree
Showing 40 changed files with 188 additions and 2,571 deletions.
Binary file removed .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Specify base image
FROM ros:humble
ARG DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get -y update
RUN apt-get -y install python3-pip

# Install python dependencies
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "X17 Dev Container",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"customizations": {
"vscode": {
"extensions": [
"ms-iot.vscode-ros", // ROS extension
"ms-python.python", // Python extension (if needed)
"ms-azuretools.vscode-docker" // Docker extension
],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
},
"mounts": [
"source=${localWorkspaceFolder}/,target=/workspace,type=bind"
],
"runArgs": [
"--network", "host" // Use host network
],
"remoteUser": "root",
"postCreateCommand": "echo 'source /opt/ros/humble/setup.bash' >> /root/.bashrc"
}
27 changes: 0 additions & 27 deletions .github/workflows/black-linter.yaml

This file was deleted.

7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
__pycache__/
ui/__pycache__
log/
.env
.env
build
install
.vscode/
.idea/
.DS_Store
29 changes: 0 additions & 29 deletions .vscode/tasks.json

This file was deleted.

46 changes: 46 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# X17-Surface PHOENIX BRANCH

This is the phoenix branch for X17-Surface. It is a rewrite of the previous X17-Surface codebase, with a focus on readability and maintainability. I will try to remove as much unnecessary complexity as possible while still maintaining the core functionality.

> [!WARNING]
> This branch is still a work in progress and is not yet fully functional. Do not merge into main until sufficient testing has been completed.
### Changes Made

#### 1. New .devcontainer setup
This will allow for easier development in a consistent environment.
Requires the following components to be installed on your machine:
- Docker Desktop
- Visual Studio Code
- Visual Studio Code Dev Containers extension

When all of the above are installed, you can open the project in Visual Studio Code and it will prompt you to reopen in a container. If you are not prompted, you can use the command palette (Ctrl+Shift+P) and select "Dev-Containers: Rebuild and Reopen in Container".

#### 2. xml -> yaml conversion
The configuration files have been converted from XML to YAML format for better readability and ease of use. I plan on doing the same for the CORE repo as well.

#### 3. New script directory
A new directory has been created for scripts, making it easier to manage and organize scripts related to the project. (Running, building, etc.)

#### 4. New launch configuration
There is a new launch configuration. It is intended to create more parity between the surface and core functionality. This can be found in the `ui` directory. Now to launch the surface, you can use the following command (Does not work yet, just a template):

```
ros2 launch ui surface_launch.yaml
```
> Note: Make sure to build and source your workspace before running the launch command.
After the launch command, the interface should be accessable at `http://127.0.0.1:5000`. I have run into some issues when trying to access the interface via `localhost` (which is where vscode will try to send you if you click on the link), so it is currently recommended to use the IP address directly. I have only had this issue on MacOS so far.

### Known working platforms
> Format: Device (Architecture) - OS Version (Date tested)
- M3 MacBook Pro (ARM) - MacOS Sequoia 15.0 (9/19/2024)
- Adam's Desktop (x86) - WSL2 on Windows 11 (9/20/2024)

### Known issues
- You cannot access any hardware yet (gamepad, etc.)

### Updates

9/19/2024: Initial commit. Implemented new .devcontainer setup, converted XML to YAML, created new script directory, and added new launch configuration.
The only nodes that are launched with the above launch command are the 'ui' node (Flask application) and the gamepad. I have not tested with the actual hardware yet so who knows if it will work.
23 changes: 0 additions & 23 deletions Dockerfile

This file was deleted.

4 changes: 0 additions & 4 deletions build.sh

This file was deleted.

11 changes: 0 additions & 11 deletions compose.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ numpy==1.21.5
opencv_python==4.7.0.68
paramiko==3.4.0
pygame==2.5.2
PyQt5==5.15.10
python-dotenv==1.0.1
setuptools==59.6.0
flask==3.0.3
22 changes: 12 additions & 10 deletions ros/gamepad/src/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def process_event(event):
# If the gamepad is disconnected, try to reconnect it
elif event.type == pygame.JOYDEVICEREMOVED:
if not reconnect_gamepad():
print("\nNo gamepad found, exiting")
node.get_logger().info("\nNo gamepad found, exiting")
pygame.quit()
rclpy.shutdown()
sys.exit(0)
Expand Down Expand Up @@ -203,7 +203,7 @@ def reconnect_gamepad():
i = GAMEPAD_TIMEOUT
while i >= 0 and not reconnected:
try:
print('Gamepad disconnected, reconnect within {:2} seconds'.format(i), end='\r')
node.get_logger().info('Gamepad disconnected, reconnect within {:2} seconds'.format(i))
pygame.init()
pygame.joystick.init()
# make sure there is only one joystick
Expand All @@ -220,30 +220,32 @@ def reconnect_gamepad():
i -= 1

if reconnected:
print('\nGamepad reconnected')
node.get_logger().info('\nGamepad reconnected')
joystick = pygame.joystick.Joystick(0)

return reconnected


if __name__ == '__main__':
global pub, pub_tools, data_thread, gamepad_thread
global pub, pub_tools, data_thread, gamepad_thread, node

# Initialize the ros node
rclpy.init()
node = rclpy.create_node('gp_pub')

try:
init_pygame()
except:
print('No gamepad found, please connect a gamepad')
node.get_logger().info('No gamepad found, please connect a gamepad')
if not reconnect_gamepad():
print("\nNo gamepad found, exiting")
node.get_logger().info("\nNo gamepad found, exiting")
pygame.quit()
sys.exit(0)

# Initialize the ros node
rclpy.init()
node = rclpy.create_node('gp_pub')


# Create the publishers
pub = node.create_publisher(RovVelocityCommand, 'rov_velocity', 10)
pub = node.create_publisher(RovVelocityCommand, '/rov_velocity', 10)
pub_tools = node.create_publisher(ToolsCommandMsg, 'tools', 10)

# Create the timers
Expand Down
5 changes: 0 additions & 5 deletions run.sh

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/bash

source /opt/ros/humble/setup.bash
colcon build
. install/setup.bash
export ROS_DOMAIN_ID=69
18 changes: 18 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Define directories to be removed
directories=("log" "install" "build")

# Loop through each directory and remove it if it exists
for dir in "${directories[@]}"; do
if [ -d "$dir" ]; then
echo "Removing directory: $dir"
rm -rf "$dir"
else
echo "Directory $dir does not exist."
fi
done

source /opt/ros/humble/setup.bash

echo "Cleanup complete."
5 changes: 5 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

. install/setup.bash
export ROS_DOMAIN_ID=69
ros2 launch ui surface_launch.yaml
Binary file removed ui/.DS_Store
Binary file not shown.
24 changes: 11 additions & 13 deletions ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ find_package(rclpy REQUIRED)

ament_python_install_package(${PROJECT_NAME})

install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)

install(PROGRAMS
src/runner.py
src/streams.py
src/ssh.py
src/main.py
src/interface.py
src/gamepad.py
src/subscribers/ThrustersSurface.py
src/subscribers/DepthSurface.py
src/subscribers/GamepadListener.py
src/subscribers/GamepadSender.py
src/subscribers/config.py
src/subscribers/TempListener.py
src/subscribers/LeakListener.py
src/app.py
DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY
src/templates
DESTINATION lib/${PROJECT_NAME}
)

Expand Down
Binary file removed ui/__pycache__/camera_stream.cpython-311.pyc
Binary file not shown.
Binary file removed ui/__pycache__/controls.cpython-311.pyc
Binary file not shown.
Binary file removed ui/__pycache__/readouts.cpython-311.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions ui/launch/surface_launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
launch:

- node:
pkg: ui
exec: app.py
namespace: rov

- node:
pkg: gamepad
exec: sender.py
namespace: rov
Binary file removed ui/src/.DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions ui/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import os
from flask import Flask, render_template, request, redirect, url_for
# Import rlcpy for logging
import rclpy

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

if __name__ == "__main__":
# Initialize the ros node
rclpy.init()
node = rclpy.create_node('flask_server')
node.get_logger().info("Flask server started")

# Run the flask app
app.run(host='0.0.0.0', port=5000)
Loading

0 comments on commit 2c628bb

Please sign in to comment.