Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,16 @@ headlessly in a scratch directory, forcing two machine facts the stock presets
get wrong: the nozzle type the printer reports and the build plate declared in
its profile. The resulting `.3mf` is then validated and queued like any other
upload, and the job carries `provenance` (source mesh hash, presets, slicer
version). Slicing runs inline in the request.
version, placement). Slicing runs inline in the request.

By default the slicer centres the part. The optional form field
`placement=front_left` instead puts its footprint `slicer.placement_margin_mm`
(default 10 mm, room for a brim) in from the front-left corner of the printable
area, resting on the plate and keeping its orientation. The gateway wraps the
mesh in a one-object 3MF whose build transform carries the offset and slices
with `--arrange 0`, since the CLI drops a bare STL off the plate when arrange
is off. On the A1 this keeps the part clear of the purge line, which runs along
the front edge at X 108-158.

For A1 server-side PLA slicing, add the following alongside existing printer
entries under `slicer.machine_profiles` in the local configuration:
Expand All @@ -458,10 +467,20 @@ bambu_a1_01:
process: 0.20mm Standard @BBL A1
filaments:
PLA: Generic PLA @BBL A1
end_bed_y_mm: 250 # optional: park the bed forward for pickup
```

`end_bed_y_mm` rewrites the Y of the stock end gcode's final park move (the
A1's `G1 X-48 Y180 F3600`, just before the motors are released) so a finished
plate is presented further forward; on the A1 a larger Y moves the bed toward
the front. It must lie within the printable area, and a preset whose end gcode
has no such move is refused rather than guessed at. The value is recorded as
`provenance.end_bed_y_mm` and returned by `pickup-targets` as `bed_park_y_mm`,
because object positions move with the bed.

Agents upload multipart fields `file=design.stl`,
`target_machine=bambu_a1_01`, and `material=PLA` to `POST /submissions`
`target_machine=bambu_a1_01`, `material=PLA` and optionally
`placement=front_left` to `POST /submissions`
through the authenticated edge with their own API key and `X-Agent-Id`.
A1 agent mode must be on. There is no separate `/slice` endpoint. HTTP 201
returns a stored submission; inspect its validation and state before approval.
Expand Down
13 changes: 12 additions & 1 deletion docs/API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ does not affect validation or establish physical spool identity after a swap.
`POST /submissions` accepts an artifact (`.3mf`, `.gcode`, or `.stl` where
slicing is enabled for the target; `.stl` requires `material`) and metadata,
validates it, and queues passing jobs. A sliced job carries `provenance`.
For an `.stl`, optional `placement` is `auto` (default: the slicer centres the
part) or `front_left` (the part's footprint `slicer.placement_margin_mm`,
default 10 mm, in from the front-left corner of the printable area, resting on
the plate, orientation unchanged). A part that does not fit there is refused
with 422; `placement` on a `.3mf` or `.gcode` is refused with 422.
Approval and cancellation update gateway records only, and approval alone does
not establish a filament-to-slot mapping or sufficient remaining quantity.

Expand Down Expand Up @@ -178,7 +183,13 @@ the file does not say. There is no robot frame; the arm agent owns calibration.
`GET /submissions/{id}/pickup-targets` returns those objects with
`bed_size_mm`, `pickup: {bed_temperature_c, safe_bed_temperature_c, cooled,
observed_at}` from the monitor's cache, and `ready` (finished, cooled, and at
least one object). It never contacts a printer or a robot.
least one object). It never contacts a printer or a robot. `bed_park_y_mm` is
the Y axis position the job's end gcode left the bed at, when the gateway set
it while slicing (`slicer.machine_profiles.<id>.end_bed_y_mm`); `null` means
unknown (the stock end move, or a file sliced elsewhere). Object positions are
in the bed's own frame and move with the bed: on a bed-slinger such as the A1,
parking at Y 250 instead of the stock Y 180 puts every object 70 mm further
toward the front of the printer.

`GET /events?after=<event_id>` is a pollable lifecycle feed: `job.started`,
`job.finished`, `job.failed`, `job.rejected`, `job.cancelled`, `job.cooled`
Expand Down
2 changes: 2 additions & 0 deletions printers.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ slicer:
profiles_dir: /home/you/.local/opt/bambu-studio/squashfs-root/resources/profiles/BBL
work_dir: var/slicer
timeout_s: 600
placement_margin_mm: 10 # gap to the bed edges for placement=front_left
# Defaults for a printer that does not name its own process or filaments.
process_profile: "0.20mm Standard @BBL X1C"
filament_profiles: # material a submitter names -> filament preset
Expand All @@ -82,6 +83,7 @@ slicer:
# process: "0.20mm Standard @BBL A1"
# filaments:
# PLA: "Bambu PLA Basic @BBL A1"
# end_bed_y_mm: 250 # park the bed forward when done (stock Y180)

printers:
- id: bambu_x1c_01
Expand Down
5 changes: 5 additions & 0 deletions src/bambu_server/agent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,10 @@ class PickupInfo(BaseModel):
ready: bool
reason: str
bed_size_mm: tuple[float, float] | None = None
#: The Y axis position the job's end gcode parked the bed at, when the
#: gateway set it while slicing. Object positions are in the bed's own
#: frame and move with it, so the arm needs this to find them; None means
#: unknown (the stock end move, or a file sliced elsewhere).
bed_park_y_mm: float | None = None
pickup: PickupReadiness
objects: list[ObjectPosition] = Field(default_factory=list)
8 changes: 8 additions & 0 deletions src/bambu_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ class SlicerPrinterPresets(BaseModel):
machine: str = Field(min_length=1)
process: str | None = Field(default=None, min_length=1)
filaments: dict[str, str] | None = None
#: Where the stock end gcode's final park move leaves the bed, as the Y
#: axis position in bed millimetres. Unset keeps the stock move (the A1's
#: ``G1 X-48 Y180``). On a bed-slinger a larger Y brings the plate further
#: toward the front for pickup; stay short of the printable area's edge.
end_bed_y_mm: float | None = Field(default=None, ge=0, le=1000)

@field_validator("filaments", mode="before")
@classmethod
Expand Down Expand Up @@ -296,6 +301,9 @@ class SlicerSettings(BaseModel):
machine_profiles: dict[str, SlicerPrinterPresets] = Field(default_factory=dict)
#: Ceiling on an uploaded mesh.
max_stl_bytes: int = Field(default=100 * 1024 * 1024, ge=1024)
#: Gap, in millimetres, between a ``front_left`` part's footprint and the
#: front and left edges of the printable area: room for a brim or skirt.
placement_margin_mm: float = Field(default=10.0, ge=0, le=100)

@field_validator("filament_profiles", mode="before")
@classmethod
Expand Down
15 changes: 15 additions & 0 deletions src/bambu_server/docs/AGENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ preset provenance. Allow time for slicing; it is synchronous with the upload
request. It does not send any printer command. The server selects the target's
presets, so callers cannot silently use P1S process settings for an A1.

To put the part near the front-left corner of the plate instead of the centre,
add `placement=front_left`. The part keeps its orientation and is moved so its
footprint starts `slicer.placement_margin_mm` (default 10 mm) from the front
and left edges of the printable area, in the bed frame (origin front-left, +X
right, +Y toward the back). A part too large to fit there is refused with 422.
`provenance.placement` records the choice and `GET /submissions/{id}/objects`
reports where the slicer actually put it. `placement` is accepted only with an
`.stl`; a sliced `.3mf` prints where its own slicer placed it.

An agent may instead slice locally with Bambu Studio and submit the result.
Use A1 machine, process and filament presets for an A1; P1S/X1C process settings
are not substitutes. Check the validation verdict returned by submission.
Expand Down Expand Up @@ -151,6 +160,12 @@ Temperature alone does not establish safe robot clearance, part release or
graspability. Objects are in bed millimetres, origin front-left, +X right,
+Y back, Z up. The arm agent owns its calibration and transform; the gateway
never commands the arm. Unknown positions are an empty list, never a guess.
On the A1 the bed itself moves in Y, so bed coordinates do not fix a world
position on their own: `bed_park_y_mm` says where the job's end gcode parked
the bed (`null` when unknown, e.g. the stock Y 180 end move). A larger value
puts the plate, and every object on it, that much further toward the front.
After the print the bed motors are released, so the bed can be pushed; check
it has not moved before relying on it.

`/submissions/{id}/artifact` returns the exact stored bytes and SHA-256 ETag.
`/result` returns the durable versioned bundle; `final: false` means the job is
Expand Down
30 changes: 29 additions & 1 deletion src/bambu_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@
Transport,
urllib_transport,
)
from .slicer import BambuStudioSlicer, SliceRequest, SlicerError, SlicerUnavailable
from .slicer import (
BambuStudioSlicer,
Placement,
SliceRequest,
SlicerError,
SlicerUnavailable,
)
from .submissions import (
TERMINAL_STATES as TERMINAL_JOB_STATES,
)
Expand Down Expand Up @@ -707,6 +713,14 @@ async def create_submission(
requested_by: Annotated[str | None, Form(max_length=120)] = None,
material: Annotated[str | None, Form(max_length=60)] = None,
eln_project: Annotated[str | None, Form(max_length=120)] = None,
placement: Annotated[
Placement | None,
Form(
description="Where the gateway puts an uploaded .stl on the plate: "
"`auto` (default; the slicer centres it) or `front_left` (a margin in "
"from the front-left corner of the bed). Only for an .stl."
),
] = None,
) -> SubmissionJob:
"""Accept a print artifact, validate it, and queue it if it passes.

Expand All @@ -716,6 +730,8 @@ async def create_submission(
``eln_project`` optionally names the ELN project the finished record
is filed under, through the central server. An agent (``X-Agent-Id`` or
an agent edge role) may submit only to a printer in agent mode.
``placement`` positions an ``.stl`` the gateway slices; a sliced file
is printed where its slicer put it, so it is refused there.
"""

# A verified identity wins over the form field: a signed-in person must
Expand Down Expand Up @@ -743,6 +759,13 @@ async def create_submission(
material=material,
eln_project=eln_project,
agent_id=agent_id,
placement=placement or "auto",
)
if placement is not None:
raise HTTPException(
status_code=422,
detail="placement applies only to an .stl the gateway slices; "
"a sliced file prints where its slicer placed it",
)
kind = ARTIFACT_EXTENSIONS.get(extension)
if kind is None:
Expand Down Expand Up @@ -800,6 +823,7 @@ async def _slice_and_accept(
material: str | None,
eln_project: str | None = None,
agent_id: str | None = None,
placement: Placement = "auto",
) -> SubmissionJob:
"""Slice an uploaded mesh for the target machine, then intake the 3mf.

Expand Down Expand Up @@ -846,6 +870,7 @@ async def _slice_and_accept(
material=material,
nozzle_type=monitor.profile().nozzle_type,
plate=monitor.definition.profile.plate,
placement=placement,
)
try:
machine, process, filament = slicer.resolve_presets(request)
Expand All @@ -864,6 +889,8 @@ async def _slice_and_accept(
machine_preset=machine.stem,
process_preset=process.stem,
filament_preset=filament.stem,
placement=placement,
end_bed_y_mm=result.end_bed_y_mm,
warnings=list(result.warnings),
)

Expand Down Expand Up @@ -1103,6 +1130,7 @@ async def pickup_targets(
ready=ready,
reason=reason,
bed_size_mm=keeper.bed_size(job.target_machine),
bed_park_y_mm=job.provenance.end_bed_y_mm if job.provenance else None,
pickup=pickup,
objects=objects,
)
Expand Down
Loading
Loading