Skip to content

Commit

Permalink
Merge branch 'ajr/node-composition' into JRA/tag-detector
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrhm committed Oct 17, 2024
2 parents c2ec9cb + 567625b commit 5caf093
Show file tree
Hide file tree
Showing 41 changed files with 12,622 additions and 9 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(mrover VERSION 2025.0.0 LANGUAGES C CXX)
cmake_policy(SET CMP0148 OLD)

set(CMAKE_CXX_STANDARD 23)
set(CXX_STANDARD_REQUIRED ON)

# Generate compile_commands.json for clangd language server.
# Can be used by VSCode, CLion, VIM, etc.
Expand Down Expand Up @@ -248,10 +249,16 @@ if(ZED_FOUND AND CUDA_FOUND)
)

# ZED Wrapper
mrover_add_node(zed perception/zed_wrapper/*.c* perception/zed_wrapper/pch.hpp)
target_compile_options(zed PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++20>)
# add_library(zed SHARED perception/zed_wrapper/zed_wrapper.cpp perception/zed_wrapper/ perception/zed_wrapper/pch.hpp)
# target_compile_definitions(zed PRIVATE "COMPOSITION_BUILDING_DLL")
# ament_target_dependencies(zed rclcpp rclcpp_components sensor_msgs ZED CUDA tf2 tf2_ros)
# rclcpp_components_register_nodes(zed "mrover::ZedWrapper")
# set(node_plugins "${node_plugins}mrover::ZedWrapper;$<TARGET_FILE:zed_wrapper>\n")

mrover_add_component(zed perception/zed_wrapper/*.c* perception/zed_wrapper/pch.hpp)
# target_compile_options(zed PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++20>)
target_link_libraries(zed parameter_utils lie MANIF::manif ${CUDA_LIBRARIES} loop_profiler cuda_compiler_flags)
ament_target_dependencies(zed rclcpp sensor_msgs ZED CUDA tf2 tf2_ros)
ament_target_dependencies(zed rclcpp rclcpp_components sensor_msgs ZED CUDA tf2 tf2_ros)

# Learning Library
# TODO(john): Update to use the new API
Expand Down
1 change: 1 addition & 0 deletions cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ endmacro()
macro(mrover_add_component name sources includes)
file(GLOB_RECURSE LIBRARY_SOURCES CONFIGURE_DEPENDS ${sources})
add_library(${name} SHARED ${ARGV3} ${LIBRARY_SOURCES})
rclcpp_components_register_nodes(${name} "mrover::${name}")
mrover_target(${name})
target_compile_definitions(${name} PRIVATE "COMPOSITION_BUILDING_DLL")
endmacro()
Expand Down
8 changes: 2 additions & 6 deletions perception/zed_wrapper/zed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,5 @@ namespace mrover {
}
}; // namespace mrover

auto main(int argc, char* argv[]) -> int {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<mrover::ZedWrapper>());
rclcpp::shutdown();
return 0;
}
#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(mrover::ZedWrapper)
1 change: 1 addition & 0 deletions teleoperation/basestation_gui/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = "backend.apps.backendConfig"
3 changes: 3 additions & 0 deletions teleoperation/basestation_gui/backend/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
11 changes: 11 additions & 0 deletions teleoperation/basestation_gui/backend/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.apps import AppConfig

import rospy


class BackendConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "backend"

def ready(self):
rospy.init_node("teleop_starter")
58 changes: 58 additions & 0 deletions teleoperation/basestation_gui/backend/consumers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json
from channels.generic.websocket import JsonWebsocketConsumer
import rospy
from mrover.msg import Joystick, WheelCmd


class GUIConsumer(JsonWebsocketConsumer):

def connect(self):
self.sub = rospy.Subscriber("/joystick", Joystick, self.joystick_callback)
self.accept()

def disconnect(self, close_code):
self.sub.unregister()

def receive(self, text_data):
"""
Receive message from WebSocket.
"""

message = json.loads(text_data)
if message["type"] == "joystick":
self.handle_joystick_message(message)

def handle_joystick_message(self, msg):
fb = msg["foward_back"]
lr = msg["left_right"]

pub = rospy.Publisher("/joystick", Joystick, queue_size=100)
message = Joystick()
message.forward_back = float(fb)
message.left_right = float(lr)
pub.publish(message)

def joystick_callback(self, msg):
forward_back = msg.forward_back
left_right = msg.left_right

# scaling multiplier to adjust values if needed
K = 1
left = K * (forward_back + left_right)
right = K * (forward_back - left_right)

# Ensure values are [-1,1] for each motor
if abs(left) > 1:
left = left / abs(left)
if abs(right) > 1:
right = right / abs(right)

# Send output to WebSocket
self.send(text_data=json.dumps({"type": "wheel_cmd", "left": left, "right": right}))

# publish motor output to ros topic
pub = rospy.Publisher("/wheel_cmd", WheelCmd, queue_size=100)
message = WheelCmd()
message.left = left
message.right = right
pub.publish(message)
20 changes: 20 additions & 0 deletions teleoperation/basestation_gui/backend/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.4 on 2023-09-03 19:35

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Note",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("note", models.CharField(max_length=180)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.4 on 2023-09-07 01:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("backend", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Joystick",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("forward_back", models.FloatField()),
("left_right", models.FloatField()),
],
),
migrations.DeleteModel(
name="Note",
),
]
Empty file.
8 changes: 8 additions & 0 deletions teleoperation/basestation_gui/backend/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

# Create your models here.


class Joystick(models.Model):
forward_back = models.FloatField()
left_right = models.FloatField()
10 changes: 10 additions & 0 deletions teleoperation/basestation_gui/backend/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.test import TestCase

# Create your tests here.
from django.test import TestCase

# Create your tests here.
from django.test import TestCase

# Create your tests here.
h
2 changes: 2 additions & 0 deletions teleoperation/basestation_gui/backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from django.urls import path, include
from backend import views
3 changes: 3 additions & 0 deletions teleoperation/basestation_gui/backend/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file.
24 changes: 24 additions & 0 deletions teleoperation/basestation_gui/basestation_gui/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
++++"""
ASGI config for basestation_gui project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
import basestation_gui.urls

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "basestation_gui.settings")

application = ProtocolTypeRouter(
{
# handle http/https requests
"http": get_asgi_application(),
# handle ws/wss requests
"websocket": AuthMiddlewareStack(URLRouter(basestation_gui.urls.websocket_urlpatterns)),
}
)
133 changes: 133 additions & 0 deletions teleoperation/basestation_gui/basestation_gui/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
Django settings for basestation_gui project.
Generated by 'django-admin startproject' using Django 4.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-5^^0$(-3g%8+ge1(xjhwxenw3&*m*u4xhx7i0nu4xt+80yl)v)"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"daphne",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"channels",
"backend",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "basestation_gui.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "frontend/build/templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = "basestation_gui.wsgi.application"

ASGI_APPLICATION = "basestation_gui.asgi.application"

CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}}


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "/static/"
STATIC_ROOT = "static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "frontend/build/static")]

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
35 changes: 35 additions & 0 deletions teleoperation/basestation_gui/basestation_gui/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
URL configuration for basestation_gui project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include
from django.http import HttpResponse
from django.shortcuts import render

from backend.consumers import GUIConsumer

vue_urls = [
path("", lambda request: HttpResponse(render(request, "vue_index.html"))),
path("motor_sim/", lambda request: HttpResponse(render(request, "vue_index.html"))),
]

urlpatterns = [
path("admin/", admin.site.urls),
path("", include(vue_urls)),
]

websocket_urlpatterns = [path("ws/drive-controls", GUIConsumer.as_asgi())]
Loading

0 comments on commit 5caf093

Please sign in to comment.