01-16-2025, 01:24 PM
(This post was last modified: 01-16-2025, 01:49 PM by HomogeneousTransformer.
Edit Reason: Better text
)
Hello everyone,
I am trying to configure a Machining item via Python API but I struggle to
1. set multiple approach/retract values as it is possible in the GUI
2. set Program Events like in https://robodk.com/doc/en/Robot-Machinin...vents.html
The .getParam() method on the name does only return b"", even if can be set.
I already tried different naming conventions (e.g. "ProgramStart", "PathApproach").
Is there a list of all the parameters and the expected formatting
Thank you and kind regards
Transformer
My current implementation
I am trying to configure a Machining item via Python API but I struggle to
1. set multiple approach/retract values as it is possible in the GUI
2. set Program Events like in https://robodk.com/doc/en/Robot-Machinin...vents.html
The .getParam() method on the name does only return b"", even if can be set.
I already tried different naming conventions (e.g. "ProgramStart", "PathApproach").
Is there a list of all the parameters and the expected formatting
Thank you and kind regards
Transformer
My current implementation
Code:
from pydantic import BaseModel, Field
from typing import List, Tuple, Optional
from enum import Enum
class SelectAlgorithm(Enum):
MINIMUM_TOOL_ORIENTATION_CHANGE = 0
TOOL_ORIENTATION_FOLLOWS_PATH = 1
ROBOT_HOLDS_OBJECT = 3
class ProgramEvents(BaseModel):
fast_move_speed: float = Field(1000.0, description="Fast move speed in mm/s")
change_tool_id: Optional[str] = Field(None, description="Command to change tool ID")
on_start: Optional[str] = Field(None, description="Action to take at program start")
on_approach: Optional[str] = Field(None, description="Action to take during path approach")
on_path_start: Optional[str] = Field(None, description="Action to take at the start of the path")
on_point: Optional[str] = Field(None, description="Action to take on a specific point")
on_path_finish: Optional[str] = Field(None, description="Action to take at the end of the path")
on_retract: Optional[str] = Field(None, description="Action to take during path retraction")
on_finish: Optional[str] = Field(None, description="Action to take at program finish")
class MachiningConfiguration(BaseModel):
name: str = Field(..., description="Name of the machining project")
approach: List[Tuple[str, float]] = Field(
[("Tangent", 10.0)],
description="List of approach types and their corresponding values (e.g., [('Tangent', 10.0), ('Normal', 100.0)])"
)
retract: List[Tuple[str, float]] = Field(
[("Tangent", 10.0)],
description="List of retract types and their corresponding values (e.g., [('Tangent', 10.0), ('Normal', 100.0)])"
)
select_algorithm: SelectAlgorithm = Field(SelectAlgorithm.MINIMUM_TOOL_ORIENTATION_CHANGE, description="Algorithm selection")
program_events: ProgramEvents = Field(default_factory=ProgramEvents, description="Program events and commands")
def configure_curve_follow(self, curve_follow):
"""
Configure the curve_follow object using the current MachiningConfiguration parameters.
Args:
curve_follow: The curve_follow object to configure.
"""
# Combine approach types and values into a single string
approach_string = ", ".join(f"{atype} {avalue}" for atype, avalue in self.approach)
curve_follow.setParam("Approach", approach_string)
# Combine retract types and values into a single string
retract_string = ", ".join(f"{rtype} {rvalue}" for rtype, rvalue in self.retract)
curve_follow.setParam("Retract", retract_string)
# Set the algorithm selection
curve_follow.setParam("SelectAlgorithm", str(self.select_algorithm.value))
# Configure machining settings, including optional parameters
machining_settings = {"AutoUpdate": 0}
# Add program events if they are set
program_event_params = {
"on_start": self.program_events.on_start,
"on_approach": self.program_events.on_approach,
"on_path_start": self.program_events.on_path_start,
"on_point": self.program_events.on_point,
"on_path_finish": self.program_events.on_path_finish,
"on_retract": self.program_events.on_retract,
"on_finish": self.program_events.on_finish,
}
for key, value in program_event_params.items():
if value: # Only include parameters with non-None values
machining_settings[key] = value
# Set the machining settings as a JSON string
curve_follow.setParam("Machining", str(machining_settings))
# Example usage
machining_config = MachiningConfiguration(
name="CurveFollowProject",
approach=[("Tangent", 10.0), ("Normal", 100.0)],
retract=[("Tangent", 10.0), ("Normal", 50.0)],
select_algorithm=SelectAlgorithm.TOOL_ORIENTATION_FOLLOWS_PATH,
program_events=ProgramEvents(
fast_move_speed=1000.0,
change_tool_id="SetTool(%2)",
on_start="onStart",
on_approach="onApproach",
on_path_start="onPathStart",
on_point="onPoint",
on_path_finish="onPathFinish",
on_retract="onRetract",
on_finish="onFinish"
)
)