Skip to content

Commit

Permalink
Adding dynamixel python driver to api
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanDuPont committed Mar 31, 2024
1 parent 28a63b2 commit 1e404c6
Show file tree
Hide file tree
Showing 53 changed files with 442 additions and 2,348 deletions.
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.

22 changes: 21 additions & 1 deletion src/api/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
from websockets.exceptions import ConnectionClosed
from fastapi.templating import Jinja2Templates
from fastapi.middleware.cors import CORSMiddleware
from .robot import (
Position2D,
RobotCommand,
RobotControl,
DynamixelMotor,
Vector2d,
Rotation2D,
DYNAMIXEL_MX_12_ADDR_CONFIG,
)
import asyncio
import cv2

Expand All @@ -22,6 +31,12 @@
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/ttyUSB1", 1, motors)


# https://stackoverflow.com/a/70626324
@app.websocket("/ws")
Expand All @@ -43,5 +58,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.send_command(RobotCommand(Vector2d(x_val, y_val), Rotation2D(0.0)))

return {"status": "success"}
Loading

0 comments on commit 1e404c6

Please sign in to comment.