dcs.infrastructure.config_manager
Configuration manager for project and machine settings.
This module provides centralized configuration management for the digital casting system, handling robot configurations, PLC settings, and other system parameters loaded from JSON configuration files with structured data objects.
ConfigManager
Manages configuration for project and machine settings.
The ConfigManager provides a centralized interface for loading and accessing configuration data for various components of the digital casting system, including robot controllers, PLC settings, and machine parameters.
Configuration files are loaded and converted to structured data objects, with all machine parameters kept in memory for efficient access by HAL classes.
Attributes:
Name | Type | Description |
---|---|---|
_HERE |
str
|
Directory path of this module file. |
_HOME |
str
|
Root directory path of the project. |
_config_dir |
str
|
Directory path where configuration files are stored. |
machines |
Dict[str, DataParam]
|
In-memory storage of machine configurations. |
Example
config = ConfigManager() config.load_plc_config() inline_mixer = config.get_machine("inline_mixer") print(f"Machine ID: {inline_mixer.machine_id}")
__init__()
Initialize configuration manager with default paths.
Sets up the directory paths used for locating configuration files relative to the current module location and initializes machine storage.
get_all_machines()
Get all loaded machine configurations.
Returns a dictionary of all machine configurations that were loaded using load_plc_config().
Returns:
Type | Description |
---|---|
dict[str, DataParam]
|
Dict[str, DataParam]: Dictionary mapping machine names to their configurations. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If load_plc_config() has not been called first. |
Example
config = ConfigManager() config.load_plc_config() all_machines = config.get_all_machines() for name, machine in all_machines.items(): ... print(f"Machine: {name}, ID: {machine.machine_id}")
get_machine(machine_name)
Get a specific machine configuration as structured data.
Retrieves a machine configuration that was previously loaded using load_plc_config(). The machine data includes structured input and output variable definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machine_name
|
str
|
Name of the machine to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataParam |
DataParam
|
Structured machine configuration with input/output variables. |
Raises:
Type | Description |
---|---|
KeyError
|
If the machine name is not found in loaded configurations. |
RuntimeError
|
If load_plc_config() has not been called first. |
Example
config = ConfigManager() config.load_plc_config() inline_mixer = config.get_machine("inline_mixer") print(f"Machine ID: {inline_mixer.machine_id}") for output_var in inline_mixer.machine_output: ... print(f"Output: {output_var.var_name}")
get_plc_config(filepath=None)
Get PLC configuration from JSON file as raw dictionary.
Loads and returns the Beckhoff TwinCAT PLC configuration as a dictionary. For structured data access, use load_plc_config() followed by get_machine().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
Custom path to PLC config file. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dict[str, Any]: Dictionary containing PLC configuration data including ADS settings, network parameters, variable lists, and machine definitions. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the PLC configuration file is not found. |
ValueError
|
If the configuration file contains invalid JSON. |
Example
config = ConfigManager() plc_config = config.get_plc_config() netid = plc_config.get("network", {}).get("netid") machines = plc_config.get("machines", [])
get_robot_config(filepath=None)
Get robot configuration from JSON file.
Loads and returns the ABB IRB4600 robot configuration including communication settings, coordinate systems, tool definitions, and operational parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
Custom path to robot config file. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dict[str, Any]: Dictionary containing robot configuration data including network settings, coordinate frames, joint limits, and other robot-specific parameters. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the robot configuration file is not found. |
ValueError
|
If the configuration file contains invalid JSON. |
Example
config = ConfigManager() robot_config = config.get_robot_config() ip_address = robot_config.get("network", {}).get("ip") joint_limits = robot_config.get("joint_limits", [])
load_plc_config(filepath=None)
Load PLC configuration and convert to structured data objects.
Loads the PLC configuration file and converts all machine definitions to DataParam objects, storing them in memory for efficient access. This method should be called before using get_machine().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
Custom path to PLC config file. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the PLC configuration file is not found. |
ValueError
|
If the configuration file contains invalid JSON. |
Example
config = ConfigManager() config.load_plc_config() inline_mixer = config.get_machine("inline_mixer")