Skip to content

Commit

Permalink
Adding Dynamixel hardware abstraction layer and binding to API
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanDuPont committed Mar 31, 2024
1 parent 889e961 commit 54a4397
Show file tree
Hide file tree
Showing 10 changed files with 732 additions and 4 deletions.
55 changes: 54 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,57 @@ cython_debug/
!crates/ruff_python_resolver/resources/test/airflow/venv/
!crates/ruff_python_resolver/resources/test/airflow/venv/lib
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/_watchdog_fsevents.cpython-311-darwin.so
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/orjson/orjson.cpython-311-darwin.so
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/orjson/orjson.cpython-311-darwin.so

# ROS gitignore
devel/
logs/
build/
bin/
lib/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
build_isolated/
devel_isolated/

# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py

# Ignore generated docs
*.dox
*.wikidoc

# eclipse stuff
.project
.cproject

# qcreator stuff
CMakeLists.txt.user

srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user

/planning/cfg
/planning/docs
/planning/src

*~

# Emacs
.#*

# Catkin custom files
CATKIN_IGNORE
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

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

21 changes: 19 additions & 2 deletions src/api/v1/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Union
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
from websockets.exceptions import ConnectionClosed
from fastapi.templating import Jinja2Templates
from fastapi.middleware.cors import CORSMiddleware
from robot import (
Position2D,
RobotControl,
DynamixelMotor,
DYNAMIXEL_MX_12_ADDR_CONFIG,
)
import asyncio
import cv2

Expand All @@ -22,6 +27,13 @@
allow_headers=["*"], # Allow all headers
)

motors = [
DynamixelMotor(10, DYNAMIXEL_MX_12_ADDR_CONFIG, Position2D(0, 0, 0)),
DynamixelMotor(11, DYNAMIXEL_MX_12_ADDR_CONFIG, Position2D(0, 0, 0), True),
]
ctrl = RobotControl("/dev/ttyUSB0", 1, motors)
ctrl.init(1000000)


# https://stackoverflow.com/a/70626324
@app.websocket("/ws")
Expand All @@ -43,5 +55,10 @@ async def get_stream(websocket: WebSocket):
@app.post("/command")
async def command(request: Request):
data = await request.json()
print(data)

x_val = -data.get("left", 0) + data.get("right", 0)
y_val = -data.get("down", 0) + data.get("up", 0)

ctrl.set_velocity(Position2D(x_val, y_val, 0))

return {"status": "success"}
Loading

0 comments on commit 54a4397

Please sign in to comment.