functions/public/Get-KlippyToolhead.ps1

function Get-KlippyToolhead {
    <#
    .SYNOPSIS
        Gets toolhead status from a Klipper printer.

    .DESCRIPTION
        Retrieves the toolhead status including position, homed axes,
        velocity limits, and extruder information.

    .PARAMETER Id
        The unique identifier of the printer.

    .PARAMETER PrinterName
        The friendly name of the printer.

    .PARAMETER InputObject
        A printer object from pipeline input.

    .EXAMPLE
        Get-KlippyToolhead
        Gets toolhead status from the default printer.

    .EXAMPLE
        Get-KlippyToolhead -PrinterName "voronv2"
        Gets toolhead status from the specified printer.

    .OUTPUTS
        KlippyCLI.Toolhead object.
    #>

    [CmdletBinding(DefaultParameterSetName = 'Default')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(ParameterSetName = 'ById')]
        [ValidateNotNullOrEmpty()]
        [string]$Id,

        [Parameter(ParameterSetName = 'ByName', Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$PrinterName,

        [Parameter(ParameterSetName = 'ByObject', ValueFromPipeline = $true)]
        [PSCustomObject]$InputObject
    )

    process {
        # Resolve printer
        $resolveParams = @{}
        switch ($PSCmdlet.ParameterSetName) {
            'ById' { $resolveParams['Id'] = $Id }
            'ByName' { $resolveParams['PrinterName'] = $PrinterName }
            'ByObject' { $resolveParams['InputObject'] = $InputObject }
        }

        $printer = Resolve-KlippyPrinterTarget @resolveParams

        try {
            $endpoint = "printer/objects/query?toolhead"
            $response = Invoke-KlippyJsonRpc -Printer $printer -Method $endpoint -NoNormalize

            $data = $response.status.toolhead
            if (-not $data) {
                Write-Warning "Toolhead data not available."
                return
            }

            $position = $data.position
            [PSCustomObject]@{
                PSTypeName        = 'KlippyCLI.Toolhead'
                PrinterId         = $printer.Id
                PrinterName       = $printer.PrinterName
                HomedAxes         = $data.homed_axes
                PrintTime         = $data.print_time
                EstimatedPrintTime = $data.estimated_print_time
                Extruder          = $data.extruder
                PositionX         = if ($position) { [math]::Round($position[0], 3) } else { $null }
                PositionY         = if ($position) { [math]::Round($position[1], 3) } else { $null }
                PositionZ         = if ($position) { [math]::Round($position[2], 3) } else { $null }
                PositionE         = if ($position) { [math]::Round($position[3], 3) } else { $null }
                MaxVelocity       = $data.max_velocity
                MaxAccel          = $data.max_accel
                MaxAccelToDecel   = $data.max_accel_to_decel
                SquareCornerVelocity = $data.square_corner_velocity
            }
        }
        catch {
            Write-Error "Failed to get toolhead from '$($printer.PrinterName)': $_"
        }
    }
}