-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ajr/node-composition' into JRA/tag-detector
- Loading branch information
Showing
41 changed files
with
12,622 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = "backend.apps.backendConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
teleoperation/basestation_gui/backend/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
], | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
teleoperation/basestation_gui/backend/migrations/0002_joystick_delete_note.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from django.urls import path, include | ||
from backend import views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
133
teleoperation/basestation_gui/basestation_gui/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())] |
Oops, something went wrong.