Skip to content

Commit

Permalink
feat: deg suppport for backedn
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-abarzua committed Nov 10, 2023
1 parent 3eb5a86 commit da3a173
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import asynccontextmanager

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager

from routers.move import router as move_router
from routers.settings import router as settings_router
Expand All @@ -15,6 +16,7 @@ async def controller_lifespan(_: FastAPI):

stop_controller()


app = FastAPI(lifespan=controller_lifespan)

app.add_middleware(
Expand Down
6 changes: 4 additions & 2 deletions backend/src/routers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def get_items(


@router.get("/status/")
def status(controller: ArmController = controller_dependency,
degrees: bool = Query(True, description="Return angles in degrees")) -> Dict[Any, Any]:
def status(
controller: ArmController = controller_dependency,
degrees: bool = Query(True, description="Return angles in degrees"),
) -> Dict[Any, Any]:
pose = controller.current_pose
status_dict: Dict[str, Any] = deepcopy(pose.get_dict(degrees=degrees))

Expand Down
15 changes: 7 additions & 8 deletions controller/src/robot_arm_controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ def stop(self) -> None:
def current_pose(self) -> ArmPose:
return self.kinematics.angles_to_pose(self.current_angles)

@ property
@property
def current_angles(self) -> List[float]:
with self.current_angles_lock:
return self._current_angles

@ current_angles.setter
@current_angles.setter
def current_angles(self, angles: List[float]) -> None:
if len(angles) != self.num_joints:
raise ValueError(f"Angles must be a list of length {self.num_joints}")
with self.current_angles_lock:
self._current_angles = angles

@ property
@property
def is_ready(self) -> bool:
if self.websocket_server is None:
websocket_server_up = True
Expand Down Expand Up @@ -550,7 +550,7 @@ class SingletonArmController:
print_status: bool = False
config_file: Optional[Path] = None

@ classmethod
@classmethod
def create_instance(
cls,
arm_parameters: ArmParameters,
Expand All @@ -565,13 +565,12 @@ def create_instance(
cls.print_status = print_status
cls.config_file = config_file

cls._instance = ArmController(arm_parameters=arm_parameters,
websocket_port=websocket_port, server_port=server_port)
cls._instance = ArmController(arm_parameters=arm_parameters, websocket_port=websocket_port, server_port=server_port)
cls._instance.print_status = print_status
if config_file is not None:
cls._instance.set_config_file(config_file)

@ classmethod
@classmethod
def get_instance(cls) -> ArmController:
if cls._instance is not None:
if cls._instance.status == ControllerStatus.STOPPED:
Expand All @@ -594,6 +593,6 @@ def get_instance(cls) -> ArmController:
return cls._instance
raise ValueError("Arm Controller not initialized")

@ classmethod
@classmethod
def was_initialized(cls) -> bool:
return cls._instance is not None
15 changes: 15 additions & 0 deletions utils/serial_com.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import serial
from serial.rfc2217 import Serial


class SerialCom:
'''
TODO:
- Scan available ports and search for a esp32
- Use argparse to specify a port
- use the default espidf baudrate of 115200
- Start a rfc2217 server on the port
'''

0 comments on commit da3a173

Please sign in to comment.