Skip to content

Commit

Permalink
Fixes from testing platecrane in BIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Dozgulbas committed Mar 5, 2024
1 parent b653406 commit 6cf07ba
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 30 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN apt update && apt install -y libusb-1.0-0-dev && rm -rf /var/lib/apt/lists/*

RUN mkdir -p hudson_platecrane_module

COPY ./platecrane_driver hudson_platecrane_module/platecrane_driver
COPY ./src hudson_platecrane_module/src
COPY ./README.md hudson_platecrane_module/README.md
COPY ./pyproject.toml hudson_platecrane_module/pyproject.toml
Expand All @@ -21,5 +20,7 @@ COPY ./tests hudson_platecrane_module/tests
RUN --mount=type=cache,target=/root/.cache \
pip install -e ./hudson_platecrane_module

CMD ["python", "hudson_platecrane_module/src/sciclops_rest_node.py"]
RUN usermod -aG dialout app

CMD ["python", "-,", "sciclops_rest_node"]
#########################################
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ PROJECT_VERSION := $(shell grep -oP '(?<=version = ")[^"]+' $(PYPROJECT_TOML) |
.PHONY += init paths checks test clean
init: # Do the initial configuration of the project
@test -e .env || cp example.env .env
@sed -i 's/^USER_ID=.*/USER_ID=$(shell id -u)/' .env
@sed -i 's/^GROUP_ID=.*/GROUP_ID=$(shell id -g)/' .env
@sed -i 's/^PROJECT_VERSION=.*/PROJECT_VERSION=$(PROJECT_VERSION)/' .env
@sed -i 's/^PROJECT_PATH=.*/PROJECT_PATH=$(shell pwd | sed 's/\//\\\//g')/' .env

Expand Down
4 changes: 2 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ services:
- ${IMAGE}:latest
- ${IMAGE}:${PROJECT_VERSION}
- ${IMAGE}:dev
command: python hudson_platecrane_module/src/sciclops_rest_node.py --port 2000
command: python -m platecrane_rest_node --port 2000 --device ${DEVICE}
privileged: true
env_file: .env
volumes:
- ${DEVICE}:/dev/ttyUSB0
- /dev:/dev
- ./src:/home/app/hudson_platecrane_module/src
- ./tests:/home/app/hudson_platecrane_module/tests
ports:
Expand Down
2 changes: 0 additions & 2 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Note: all paths are relative to the docker compose file
USER_ID=
GROUP_ID=
DEVICE=/dev/ttyUSB2
PROJECT_PATH=
PROJECT_VERSION=1.2.0
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ homepage = "https://github.com/AD-SDL/hudson_platecrane_module"
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"


[tool.setuptools.packages.find]
where = ["."]
include = ["src*", "platecrane_driver*"]
exclude = ["*tests*"]

#####################
# Development Tools #
#####################
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import json
import re

from serial_port import SerialPort
from pathlib import Path

from platecrane_driver.serial_port import SerialPort


class PlateCrane:
Expand Down Expand Up @@ -46,12 +48,12 @@ def __init__(self, host_path="/dev/ttyUSB2", baud_rate=9600):

self.plate_resources = json.load(
open(
"/home/rpl/wei_ws/src/platecrane_module/platecrane_driver/platecrane_driver/plate_resources.json"
Path(__file__).parent / "plate_resources.json"
)
)
self.stack_resources = json.load(
open(
"/home/rpl/wei_ws/src/platecrane_module/platecrane_driver/platecrane_driver/stack_resources.json"
Path(__file__).parent / "stack_resources.json"
)
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
152 changes: 152 additions & 0 deletions src/platecrane_driver/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@





if __name__ == "__main__":
import platecrane_driver
"""
Runs given function.
"""
s = platecrane_driver.PlateCrane("/dev/ttyUSB2")
# s.initialize()
# s.home()
stack4 = "Stack4"
stack5 = "Stack5"
solo6 = "Solo.Position6"
solo4 = "Solo.Position4"
solo3 = "Solo.Position3"
target_loc = "HidexNest2"
lidnest3 = "LidNest3"
sealer = "SealerNest"
# s.move_location("Safe")

# s.move_location("Stack4")
#s.move_single_axis("Z", "Safe", delay_time=1) # move all the way up in z height

# print(s.get_location_list())

# s.transfer("Stack4","Solo.Position1",source_type="stack",target_type="stack",height_offset=800) # test from stack to solo pos 1
#s.transfer("Stack4","Solo.Position1",source_type="stack",target_type="stack") # Stack 4 to SOLO 1

# s.transfer("Solo.Position1","Stack5",source_type="stack",target_type="stack") # SOLO 1 --> Stack 5

# s.transfer("Stack5","Solo.Position1",source_type="stack",target_type="stack") # Stack 4 to SOLO 1

###
#s.transfer("Solo.Position1","Stack3",source_type="stack",target_type="stack")

# s.transfer("Stack2","PeelerNest",source_type="stack",target_type="stack")

# s.transfer("PeelerNest","Stack2",source_type="stack",target_type="stack")

#s.transfer("Stack2","LidNest1",source_type="stack",target_type="stack")
# s.transfer("Stack1","LidNest1",source_type="stack",target_type="stack")
# s.transfer("LidNest1","Solo.Position1",source_type="stack",target_type="stack")
# s.transfer("Solo.Position1","PeelerNest", source_type="stack", target_type="stack")
# s.transfer("PeelerNest","Stack1",source_type="stack",target_type="stack")

#s.transfer("Solo.Position1","Hidex.Nest",source_type="stack",target_type="module")



# s.transfer("LidNest2","LidNest3",source_type="stack",target_type="stack")

# s.transfer("LidNest3". "Solo.Position2", source_type="stack", target_type="stack")
# s.transfer("PeelerNest","Stack2",source_type="stack",target_type="stack")

# s.transfer("PeelerNest","Stack2",source_type="stack",target_type="stack")



###
# s.transfer("Solo.Position1","Hidex.Nest",source_type="stack",target_type="module", height_offset=700) # SOLO 1 to Hidex

# s.transfer("Hidex.Nest","Solo.Position1",source_type="module",target_type="module") # Stack 4 to SOLO 1




### Hidex Recalibration

#print(s.get_position())

#s.set_location("Safe", 195399, 2646, 0, 0)


s.transfer("Hidex.Nest","Sealer.Nest",source_type="module",target_type="stack", height_offset = 650)


print(s.get_location_list())


# old sealer nest 28:SealerNest, 210256, -1050, 491, 5730



# ----------------------------------------------------------------------------------------------------------------------------------------


















# s.pick_stack_plate("Stack1")
# a = s.get_position()
# s.set_location("LidNest3",R=231449,Z=-31500,P=484,Y=-306)

# s.set_location("Hidex.Nest",R=a[0],Z=a[1],P=a[2],Y=a[3])
# s.place_module_plate("Hidex.Nest")
# s.move_single_axis("Z","Hidex.Nest")
# s.transfer("Hidex.Nest","Solo.Position1",source_type="module",target_type="stack",height_offset=800)
# s.transfer("Stack1", "PeelerNest",source_type="stack",target_type="stack")

# s.place_module_plate()
# s.get_location_list()

# s.move_joints_neutral()
# s.move_single_axis("R", "Safe", delay_time=1)
# s.set_location("Safe",R=195399,Z=0,P=0,Y=0)
# s.set_location("LidNest2",R=131719,Z=-31001,P=-5890,Y=-315)
# s.transfer(source="LidNest1",target="LidNest2",source_type="stack",target_type="stack", plate_type="96_well")

# s.transfer(source="LidNest2",target="LidNest3",source_type="stack",target_type="stack", plate_type="96_well")
# s.transfer("Stack1","Stack1")
# s.free_joints()
# s.lock_joints()

# s.set_location("LidNest3",R=99817,Z=-31001,P=-5890,Y=-315)

# s.get_location_joint_values("HidexNest2")
# s.set_location("HidexNest2", R=210015,Z=-30400,P=490,Y=2323)

# s.transfer(stack5, solo4, source_type = "stack", target_type = "module", plate_type = "96_deep_well")
# s.transfer(solo4, stack5, source_type = "module", target_type = "stack", plate_type = "96_deep_well")

# s.remove_lid(source = "LidNest1", target="LidNest2", plate_type="96_well")
# s.transfer("Stack4", solo3, source_type = "stack", target_type = "stack", plate_type = "tip_box_lid_off")
# s.remove_lid(source = solo6, target="LidNest3", plate_type="tip_box_lid_on")
# s.replace_lid(source = "LidNest3", target = solo6, plate_type = "tip_box_lid_on")
# s.replace_lid(source = "LidNest2", target = solo4, plate_type = "96_well")
# s.transfer(solo4, stack5, source_type = "module", target_type = "stack", plate_type = "96_well")
# s.transfer(solo6, "Stack2", source_type = "module", target_type = "stack", plate_type = "tip_box_lid_on")


# Crash error outputs 21(R axis),14(z axis), 02 Wrong location name. 1400 (Z axis hits the plate), 00 success
# TODO: Need a response handler function. Unkown error messages T1, ATS, TU these are about connection issues (multiple access?)
# TODO: Slow the arm before hitting the plate in pick_stack_plate
# TODO: Create a plate detect function within pick stack plate function
# TODO: Maybe write another pick stack funtion to remove the plate detect movement

34 changes: 21 additions & 13 deletions src/platecrane_rest_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"""The server for the Hudson Platecrane/Sciclops that takes incoming WEI flow requests from the experiment application"""

import json
from argparse import ArgumentParser
from argparse import ArgumentParser, Namespace
from contextlib import asynccontextmanager
import traceback
from pathlib import Path

from fastapi import FastAPI
Expand All @@ -22,6 +23,17 @@

global platecrane, state

def parse_args() -> Namespace:
parser = ArgumentParser()
parser.add_argument(
"--host",
type=str,
default="0.0.0.0",
help="Hostname that the REST API will be accessible on",
)
parser.add_argument("--port", type=int, default=2002)
parser.add_argument("--device", type=str, default="/dev/ttyUSB0")
return parser.parse_args()

@asynccontextmanager
async def lifespan(app: FastAPI):
Expand All @@ -36,10 +48,13 @@ async def lifespan(app: FastAPI):
None"""
global platecrane, state

args = parse_args()

try:
platecrane = PlateCrane()
platecrane = PlateCrane(host_path=args.device)

except Exception as error_msg:
traceback.print_exc()
state = "PLATECRANE CONNECTION ERROR"
print("------- PlateCrane Error message: " + str(error_msg) + (" -------"))

Expand Down Expand Up @@ -67,8 +82,8 @@ async def about():
"""Returns a description of the actions and resources the module supports"""
global state
about = ModuleAbout(
name="Sciclops Robotic Arm",
description="Sciclops is a robotic arm module that grabs a plate from a specific tower location.",
name="Hudson Platecrane",
description="Platecrane is a robotic arm module that can pick up and move plates between locations.",
interface="wei_rest_node",
version=extract_version(Path(__file__).parent.parent / "pyproject.toml"),
actions=[
Expand Down Expand Up @@ -274,15 +289,8 @@ def do_action(action_handle: str, action_vars):
if __name__ == "__main__":
import uvicorn

parser = ArgumentParser()
parser.add_argument(
"--host",
type=str,
default="0.0.0.0",
help="Hostname that the REST API will be accessible on",
)
parser.add_argument("--port", type=int, default=2002)
args = parser.parse_args()
args = parse_args()

uvicorn.run(
"platecrane_rest_node:app",
host=args.host,
Expand Down

0 comments on commit 6cf07ba

Please sign in to comment.