Skip to content

festo-edcon / Modbus Examples

Copy-paste oriented examples for direct-drive setups using EdconAxis and Gantry.


1. Connect via configuration file

connect_from_config.py
1
2
3
4
5
6
from pathlib import Path

from applied_motion import Gantry

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))
print(repr(gantry))

Config example:

modbus-gantry-config.json
{
    "spec_version": "3.0",
    "component_config": {
        "metadata": {},
        "components": {
            "gantry_1": {
                "backend": "modbus",
                "axes": {
                    "X": {"name": "X", "ip": "192.168.0.100"},
                    "Y": {"name": "Y", "ip": "192.168.0.101"},
                    "Z": {"name": "Z", "ip": "192.168.0.102"}
                },
                "axis_order": ["X", "Y", "Z"],
                "concurrent_axes": ["X", "Y"]
            }
        }
    }
}

2. Construct manually (without config)

connect_manual.py
1
2
3
4
5
6
7
8
from applied_motion.backends.edcon_axis import EdconAxis
from applied_motion.applied_motion import Gantry

x = EdconAxis(name="X", ip="192.168.0.100")
y = EdconAxis(name="Y", ip="192.168.0.101")
z = EdconAxis(name="Z", ip="192.168.0.102")

gantry = Gantry(axes={"X": x, "Y": y, "Z": z})

3. Home then move sequentially

sequential_move.py
from collections import deque
from pathlib import Path

from applied_motion import Gantry

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))
gantry.home()

movements = deque([
    {"X": {"position": 120.0, "velocity": 60.0}},
    {"Y": {"position":  80.0, "velocity": 50.0}},
    {"Z": {"position":  15.0, "velocity": 25.0}},
])

gantry.move_to(movements)

4. Relative move

relative_move.py
from collections import deque
from pathlib import Path

from applied_motion import Gantry

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))
gantry.home()

gantry.move_to(deque([
    {"X": {"position": 10.0, "velocity": 30.0, "position_type": "relative"}},
]))

5. Run one full batch concurrently

concurrent_batch.py
from collections import deque
from pathlib import Path

from applied_motion import Gantry

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))
gantry.home()

movements = deque([
    {"X": {"position": 180.0, "velocity": 80.0}},
    {"Y": {"position":  40.0, "velocity": 80.0}},
])

gantry.move_to(movements, concurrent=True)

6. Read status and position

status_and_location.py
1
2
3
4
5
6
7
8
9
from pathlib import Path
from pprint import pprint

from applied_motion import Gantry

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))

print(gantry.get_location())
pprint(gantry.get_status())

7. Error handling

error_handling.py
from collections import deque
from pathlib import Path

from applied_motion import Gantry
from applied_motion.applied_motion import MovementError

gantry = Gantry.from_config(Path("modbus-gantry-config.json"))

try:
    gantry.move_to(deque([
        {"X": {"position": 999999.0, "velocity": 5.0}},
    ]))
except MovementError as exc:
    print(f"Movement failed: {exc}")